Mpeg TS muxing

Feb 7, 2013 at 2:10 PM
I'm hoping to use this library to write elementary h264 byte streams to an mpeg TS file. Is this possible with this library?

Thanks,

Adam
Coordinator
Feb 7, 2013 at 4:56 PM
Edited Feb 7, 2013 at 4:57 PM
Demuxing is mostly complete aside from optional stream information stuff but I've not started on the muxing yet.

The code in the constructors of all the packets has to be inverted for a start. Then you have to know enough about the ins and outs of the specific TS format you want in order to construct all the right packets. A basic TS stream isn't too terribly hard but once you get into the differences between straight MPEG-2 TS, ATSC, DVB, etc... things get a bit complicated.

Note it's a 2-stage mux. First you have to convert NAL to PES then PES to TS. And you have to decide how often you want to send the various tables. If it's for a static file, you can potentially get away with doing the tables once at the top of the file. For any streaming use, you'd have to resend them periodically and the interval you settle on determines how quickly a player can start decoding at any arbitrary point in the stream.

Timing and padding is pretty critical in most of the common use-cases for TS, too. ATSC has to be almost exactly 20megabit with very good interleaving of audio and video and minimal overall jitter since tuners don't have a lot of buffer space.
Feb 7, 2013 at 5:32 PM
I thought as much after I glanced through some of the code, spotting the 'TODO' comments everywhere regarding serialisation. As far as the completeness of the TS muxing I can get away with the bare minimum as it's for a very static and specific use case where I know exactly what kind of TS structure is expected. I will have a stab at it tomorrow if I have some free time and let you know how it goes. I hope you continue to work on this great little library. Once complete it will become extremely popular I'm sure!

Kind Regards,

Adam
Coordinator
Feb 7, 2013 at 5:51 PM
Serialization in the TS library should be a lot simpler than it was for BMFF. I decided to do the bit fiddling in the property getters/setters rather than up front when creating the class. That decision was for performance trade-off reasons since TS is nearly always streamed and much of the time you won't bother looking at most of the values. It means you don't want to use those properties over and over again if you can put them in a temp variable, though.

However, that made it easier to not do them at the same time -- so I ended up with a one-way demux instead of mux/demux like the bmff library where I did both at the same time for each box.

I've got a bunch of edits for the TS library in the works right now. Some refactoring, minor bug fixes and expanded support for descriptors. I should be able to put in the serialization this weekend.