Search code examples
ffmpegstreamrtsp

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


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


Solution

  • 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.