Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 765
TLePhan Avatar asked Oct 22 '25 14:10

TLePhan


2 Answers

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.

like image 72
Gyan Avatar answered Oct 24 '25 14:10

Gyan


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
like image 21
TLePhan Avatar answered Oct 24 '25 13:10

TLePhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!