Get TS packets into buffer from libavformat
Asked Answered
N

1

0

I would like to capture video, compress it and mux it as an mpeg2 ts. All of this is quite simple with the ffmpeg libraries, but what I would like to do, instead of writing it to a file, is capture the ts packets in a buffer and using this stream in other ways. Is there a simple way to do this?

To write the encoded frames to file right now, I use av_interleaved_write_frame(oc, &pkt). OC is an output context with a filename and format defined. pkt is an AVPacket containing the compressed frame. The av_interlaced_write_frame is doing the muxing and writing the file.

What I would like to ultimately achieve is to write the same ts stream to multiple files, and to start and stop writing the different files independent of each other. Starting a new muxer for each stream seems inefficient, as a TS stream should not need any header or correct ending to be played back correctly (If what I've read is correct)

I'm kind of lost trying to find good examples in the ffmpeg code, and the libraries are not very well documented. Any input on this subject is appreciated. Thank you!

Northbound answered 14/5, 2012 at 8:20 Comment(0)
N
1

Finally got it working. One way to do it is to use avio_alloc_context to set up a callback where you do what you want with the stream. This guy has a good example of it:

https://github.com/EvilTengil/kinect-streamer/blob/master/src/kstreamer/ffv1_depth_encoder.cpp

Northbound answered 31/5, 2012 at 7:22 Comment(1)
the github repository at the link you posted is gone; if you can remember or have some code lying around, could you please post the actual code example?Give

© 2022 - 2024 — McMap. All rights reserved.