在ffmpeg中将RTSP流连续保存为特定长度(10分钟)的多个mp4文件 [英] Save RTSP stream continuously into multi mp4 files with specific length (10 minutes) in ffmpeg
问题描述
我正在使用ffmpeg将来自摄像机的RTSP流记录到.mp4
文件中,我想将其滚动成多个文件,每个视频的时长为10分钟.
I'm recording RTSP stream from camera into .mp4
files using ffmpeg and I want to roll it into multi files with 10 minutes long every videos.
当前,我对此有一个解决方案:我将时间长度设置为"00:10:00",完成后,我将使用新进程重新启动下面的命令. 样本:
Currently I have a solution for this: I'm setting a time length '00:10:00', after it finished then I will restart below command with new process. Sample:
ffmpeg -rtsp_transport tcp -i <rtsp_url> -acodec copy -vcodec copy -t 00:10:00 D:\video_test.mp4
但是此解决方案使摄像机变得不稳定,RTSP流通常会因以下错误而损坏:
But this solution makes camera becoming unstable, RTSP stream uasually corrupted with this error:
rtsp://10.96.41.14:9024/user=xxxx_password=xxx_channel=1_stream=0.sdp?real_stream: Operation not permitted
我想找到更好的解决方案,以保持与RTSP流的持续连接(而不是使用-t
标志创建新进程).
I want to find better solution to keep connection to RTSP stream continuously (not create new process with a -t
flag).
有人有更好的主意来保持连续录制流吗? 谢谢
Does anyone have better idea to keep recording stream continuously? Thanks
推荐答案
FFmpeg具有细分多路复用器.
FFmpeg has a segment muxer you can use for this.
基本形式为
ffmpeg -rtsp_transport tcp -i <rtsp_url> -c copy -f segment -segment_time 600 stream_piece_%d.mp4
请注意,分段多路复用器会在关键帧处分割,因此所获得的分段持续时间可能会有小的偏差.
Note that the segment muxer splits at keyframes, so there are likely to be small deviations in the segment durations obtained.
这篇关于在ffmpeg中将RTSP流连续保存为特定长度(10分钟)的多个mp4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!