dholroyd / mpeg2ts-reader

Rust reader for MPEG2 Transport Stream data
Apache License 2.0
51 stars 14 forks source link

remuxer example #29

Open lu-zero opened 1 year ago

lu-zero commented 1 year ago

Is it possible to have an example that takes every element of the ts muxer and then writes it down to a file element by element? I'm trying to figure out how to get the data alongside with its parsing and I fail to figure out how to do it by reading the examples.

dholroyd commented 1 year ago

Yes, the examples are bit lacking.

What level of detail would you like to see specifically?

dholroyd commented 1 year ago

Since you mention remux, there am old example of remuxing mpegts to mp4 over at dholroyd/lowly/src/mpegts/h264.rs. The code is not very good - only supports a fixed audio/video setup, but does this demonstrate some of the library functionality that you would like to see added to an example?

lu-zero commented 1 year ago

Maybe a great example would be taking in a ts and convert it to a cbr one or the leanest vbr one by adding/removing the stuffing?

dholroyd commented 1 year ago

I see - you should know that this codebase doesn't currently have any support for multipliexing / writing mpegts - there's more than just examples missing there! I've been tempted to add multiplexing in the past, but it's both harder than demux and something I've not needed as often as demux.

It would be easy enough to write an example that drops packets with pid=0x1fff, but it sounds like you are looking for more than this?

lu-zero commented 1 year ago

As example that's exactly what you want :)

In a case you read everything, if you find stuffing do not write the packet, otherwise write down what you just read, in the other you read everything and write it down and every time you see a PCR you check if you wrote enough data, otherwise you add more stuffing.

A muxer that pairs well with this crate would be great in general, but not required for the examples I had in mind.

dholroyd commented 1 year ago

There's a first pass example of stripping stuffing packets in #30.

Because this uses the existing demuxer infra rather than simply iterating packets, in addition to dropping stuffing it also has the effect of,

lu-zero commented 1 year ago

Thank you, I was away and I just read the code :)