Search code examples
ffmpegrecordrtsp

How to save (record) rtsp stream to the disk storage without artifacts and missing seconds?


I need to save (record) rtsp stream to the disk storage. I am using nginx-module and ffmpeg for it. Here the config for enable recording:

rtmp {
    live on;
    hls on;
    hls_fragment 5s;
    server {
        listen 1935;
        application cam1 {
            hls_path /tmp/cam1;
        }
        exec_static ffmpeg -rtsp_transport tcp -i rtsp://... -c copy -f flv rtmp://.../cam1/stream;
    }
}

Config is creating the flv files, each duration of 5 second. Then we need to merge all got files in one file by command:

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.flv

After concated files we are got a problem. When previous 5 seconds end and start next 5 seconds we have artifacts and missing 0.5-1 second.

Please, get me help with saving rtsp stream without artifacts and missing seconds.


Solution

  • We are decided to exclude Nginx and build ffmpeg without format decoding. That’s helped us to fix our problem :

    ffmpeg -rtsp_transport tcp -i "rtsp://..." -reconnect 1 \ 
           -f segment -segment_format flv -segment_time 10 -segment_atclocktime 1 \ 
           -reset_timestamps 1 -strftime 1 -avoid_negative_ts 1 \ 
           -c copy -map 0 %Y%m%d-%H%M%S.flv