Save RTSP stream continuously into multi mp4 files with specific length (10 minutes) in ffmpeg

女生的网名这么多〃 提交于 2019-12-13 23:35:31

问题


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.

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

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

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


回答1:


FFmpeg has a segment muxer you can use for this.

Basic form is

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.




回答2:


I want to extend the answer from @Gyan as my solution that I'm using.

In my case, I want to segment stream into normal videos (it can be playback) and video starts at 0 minute every hour of clock. So I'm using option reset_timestamps and segment_atclocktime.

Below is my full ffmpeg command:

ffmpeg -rtsp_transport tcp -i <rtsp_url> -f segment -strftime 1 \ 
    -segment_time 00:10:00 -segment_atclocktime 1 -segment_clocktime_offset 30 \
    -segment_format mp4 -an -vcodec copy -reset_timestamps 1 \ 
    record_%Y-%m-%d-%H.%M.%S.mp4


来源:https://stackoverflow.com/questions/56423581/save-rtsp-stream-continuously-into-multi-mp4-files-with-specific-length-10-minu

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