Demux TS file

Nov 15, 2012 at 2:15 PM


I'm wondering how I can use the TsDemuxer to extract Video and Audio samples from a TS file.

If I use the ProcessInput method from your TsDemuxer, it seems to work when I look to the output console. But how can I retrieve the samples ? From the TsDemuxer's streams property, I can see 3 streams (one video and two audios) and from TsDemuxer's programs property, I can see one program. Compared to others TS parser, it seems ok.

Do you have any piece of advice that can help me ?

Thanks in advance,




Nov 15, 2012 at 9:40 PM

That project is still pretty early in development so it's a use at your own risk sort of situation.  It does work with the streams I've tested it on but the API isn't complete.

However, to answer your question...

You have to get the TsStream implementation from either from TsDemuxer.Streams or TsDemuxer.Programs[x].Streams and then add an event handler for UnitReceived.  Depending on the stream type, that'll either be a PesPacket or byte[].

The end goal is to have TsDemuxer raise an event for added programs and TsProgram raise an event for added streams and then you'll get notified and can subscribe to the stream at that point.  Unfortunately the only even that presently exists is TsStream.UnitReceived.

Also, it really shouldn't be doing any unit processing if you haven't subscribed to a stream... that's just wasted CPU cycles but for now its a good way to find bugs.

Nov 15, 2012 at 9:51 PM

Oh, I should point out that TsStream and TsStreamEventArgs are kind of polymorphic.. you'll need to cast to the appropriate TsStreamEventArgs<T> to get at the DecodedUnit property.  That's what I meant by byte[] vs PesPacket.  Otherwise all you'll see is the assembled TS Unit.

Nov 16, 2012 at 9:06 AM

Thanks the for this nice answer ! I have a better view of the architecture... and I can now demux my ts file :)

Great job !