简体   繁体   English

保存H.264 RTP流而无需重新编码?

[英]Saving H.264 RTP stream without re-encoding?

My C++ application receives a H.264 RTP video stream. 我的C ++应用程序接收H.264 RTP视频流。

Right now it decodes the stream, saves it into a YUV file and later I use ffmpeg to re-ecode the file into something suitable to watch on a Windows PC (eg. Mpeg4 AVI). 现在它解码流,将其保存到YUV文件中,然后我使用ffmpeg将文件重新编码为适合在Windows PC上观看的内容(例如Mpeg4 AVI)。

Shouldn't it be possible to save the H.264 stream into a AVI (or similar) container without having to decode and re-encode it ? 是否不可能将H.264流保存到AVI(或类似)容器中而无需对其进行解码和重新编码? That would require some H.264 decoder on the PC to watch, but it should be much more efficient. 这需要在PC上观看一些H.264解码器,但它应该更高效。

How could that be done ? 怎么可能这样呢? Are there any libraries supporting that ? 有没有图书馆支持这个?

Your program could pipe the rtp itself through ffmpeg - even invoking it using popen3() . 你的程序可以通过ffmpeg管道rtp本身 - 甚至使用popen3()调用它。

It seems that you need to use an intermediate SDP file - I speculate that you can specify a file you created as a named pipe or with tmpfile() which your application writes to - using the file as an intermediary. 您似乎需要使用中间SDP文件 - 我推测您可以使用该文件作为中介,将您创建的文件指定为命名管道或使用应用程序写入的tmpfile()

The command-line would be something like: 命令行会是这样的

int p[3];
const char* const out_fmt = "avi";
const char* cmd[] = {"ffmpeg","-f",,"-i",temp_sdp_filename,"-vcodec","copy","-f",out_fmt,"-",NULL};
if(-1 == popen3(p,cmd)) ...
// write the rtp that you receive to p[STDIN_FILENO]
// read the avi from p[STDOUT_FILENO]
// read any messages and error text from p[STDERR_FILENO] 

I believe that in this circumstance ffmpeg is clever enough to repackage the container (rtp stream vs AVI) without transcoding the video and audio (this is the -vcodec copy switch); 我相信在这种情况下,ffmpeg足够聪明,可以重新打包容器(rtp stream vs AVI)而无需转码视频和音频(这是-vcodec copy开关); therefore, you'd have no loss of quality and it'd be blazingly fast. 因此,你没有质量损失,而且速度非常快。

using ffmpeg is correct but the answers posted so far dont look right to me. 使用ffmpeg是正确的,但到目前为止发布的答案看起来不对我。

the correct switch should be: 正确的开关应该是:

-vcodec copy

You can take a look at x264 source code. 您可以查看x264源代码。 I've been looking for a container that can hold already compressed H264 packets (coming from an IP camera, so write-to-a-file-then-convert approach was not appropriate for me too). 我一直在寻找一个容器,可以容纳已压缩的H264数据包(来自IP摄像头,所以写入文件然后转换方法也不适合我)。 There you can find raw, MP4, Matroska and FLV container implementations. 在那里你可以找到raw,MP4,Matroska和FLV容器实现。 Here is the link: http://www.videolan.org/developers/x264.html 这是链接: http//www.videolan.org/developers/x264.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM