将实时视频流保存到本地存储

时间:2011-06-03 09:39:25

标签: ffmpeg directshow rtsp

问题:

I have to save live video streams data which come as an RTP packets from RTSP Server.
The data come in two formats : MPEG4 and h264. 
I do not want to encode/decode input stream.
Just write to a file which is playable with proper codecs. 

有什么建议吗?

祝福

历史:

我的解决方案及其问题:

第一次尝试: FFmpeg

I use FFmpeg libary to get audio and video rtp packets. 
But in order to write packets i have to use av_write_frame : 
which seems that decode /encode takes place.
Also, when i give output format as mp4 ( av_guess_format("mp4", NULL, NULL)
the output file is unplayable. 
[ any way ffmpeg has bad doc. hard to find what is wrong]

第二次尝试:DirectShow

Then i decide to use DirectShow. I found a RTSP Source Filter. 
Then a Mux and File Writer.
Cretae Single graph:

RTSP Source --> MPEG MUX ---> File Writer

It worked but the problem is that  the output file is not playable
if graph is not stoped. If something happens, graph crashed for example
the output file is not playable
Also i can able to write H264 data, but the video is completely unplayable.

1 个答案:

答案 0 :(得分:2)

MP4文件格式具有正确播放所需的索引,索引只能在完成录制后创建。所以使用MP4容器文件(和其他索引文件)的任何解决方案都会遇到同样的问题。您需要停止录制以完成文件,否则将无法播放。

一个可能有用的解决方案是将图表分成两部分,这样您就可以在停止当前文件的同时继续录制到新文件。有一个例子,请访问www.gdcl.co.uk/gmfbridge。

如果您尝试使用GDCL MP4多路复用器,并且遇到H264流问题,请参阅相关问题GDCL Mpeg-4 Multiplexor Problem