从libavformat获取TS数据包到缓冲区 [英] Get TS packets into buffer from libavformat

查看:254
本文介绍了从libavformat获取TS数据包到缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕获视频,压缩和复制它作为一个mpeg2 ts。所有这些都是非常简单的ffmpeg库,但我想做的,而不是写入一个文件,捕获ts数据包在一个缓冲区,并以其他方式使用这个流。有没有一个简单的方法呢?

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?

要将编码的帧写入文件,我使用av_interleaved_write_frame(oc,& pkt)。 OC是具有定义文件名和格式的输出上下文。 pkt是包含压缩帧的AVPacket。 av_interlaced_write_frame正在进行多路复用和写入文件。

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.

我想要最终实现的是将相同的ts流写入多个文件,并开始和停止写入不同的文件彼此独立。为每个流启动一个新的muxer似乎效率不高,因为TS流不应该需要任何标题或正确的结尾才能正确播放(如果我读到的是正确的)

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)

我很失落,试图在ffmpeg代码中找到很好的例子,这些库没有很好的记录。任何关于此主题的输入都将被欣赏。谢谢!

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!

推荐答案

终于让它工作了。一种方法是使用avio_alloc_context设置一个回调,您可以使用流来完成所需的操作。这个人有一个很好的例子:

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

这篇关于从libavformat获取TS数据包到缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆