asticode / go-astits

Demux and mux MPEG Transport Streams (.ts) natively in GO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

End of PES payload is truncated for certain streams

Hakkin opened this issue · comments

I'm trying to extract timed ID3 data, which contains a JSON payload, but the end of every PES payload seems to be truncated by a few bytes. This also happens when attempting to extract the AAC audio (results in a corrupted file), the H264 stream seems to extract fine though.

I've compared this to extracting the data using ffmpeg (ffmpeg -i test.ts -map 0:2 -c copy -f data ID3.bin), ffmpeg actually has it's own issues in that it doesn't output the magic number at the start of the stream for whatever reason, but it seems to correctly extract the payload otherwise.

Here is an example ts file to use,
and here is the extracted ID3 stream using astits vs ffmpeg. You can see the first payload astits extracted ends in "transc_s":15694516, while ffmpeg is "transc_s":1569451686155}

You can see the code I'm using to extract the PES payload here: https://gist.github.com/Hakkin/6cab34dcf004494d436025a1846633c0
It's possible I'm doing something wrong in my code, but it seems fairly straightforward, so I'm not sure.

Thanks for providing the data to reproduce the problem, I'll check it out!

@Hakkin I've pushed a fix, it should be all good now (even for AAC). Can you confirm?

Edit: See comment below, this was an error in my code.

That seems to have fixed the payloads being truncated, but now I've noticed that astits isn't outputting as much stream data as ffmpeg does. In the example file above, astits outputs 4096 bytes, ffmpeg outputs 5005 bytes. Inspecting the data, I can see astits seems to be skipping some packets at the end of the stream.

This seems to affect the AAC stream as well, but not H264.

It seems like maybe some problem with astits only outputting non-H264 streams in 4096 byte chunks? The ID3 stream astits outputs is 4096, the AAC output is 413,696 (4096*101). In both cases, the size of the data ffmpeg outputs is within 4096 bytes of what astits puts out.

Oops, sorry! That was an issue with my code, not yours. I wasn't flushing my buffer properly. This seems to be fixed. Thank you!

Cheers