问题
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