Get TS packets into buffer from libavformat

北城以北 提交于 2020-01-06 05:49:05

问题


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!


回答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



来源:https://stackoverflow.com/questions/10579719/get-ts-packets-into-buffer-from-libavformat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!