Save continuous RTSP stream to 5-10 minute long mp4 files

52,475

Solution 1

See this question and answer on Server Fault. In short, switch tools. avconv will do what you want. (ffmpeg has become avconv.)

The feature you are looking for is called segmentation. Your command line would look something like this:

avconv -i rtsp://10.2.2.19/live/ch01_0 -c copy -map 0 -f segment -segment_time 300 -segment_format mp4 "capture-%03d.mp4"

Solution 2

Alexander Garden solution works for ffmpep using the version below. Replace avconv with ffmpeg.

./ffmpeg -i rtsp://10.2.2.19/live/ch01_0 -c copy -map 0 -f segment -segment_time 300 -segment_format mp4 "capture-%03d.mp4"

I'm including this header because of the FFmpeg confusion over versions, the ubuntu schism and rapid development.

ffmpeg version N-80023-gd55568d Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1) configuration: --prefix=/home/rhinchley/q10/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/rhinchley/q10/ffmpeg_build/include --extra-ldflags=-L/home/rhinchley/q10/ffmpeg_build/lib --bindir=/home/rhinchley/q10/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree libavutil 55. 24.100 / 55. 24.100 libavcodec 57. 42.100 / 57. 42.100 libavformat 57. 36.100 / 57. 36.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 45.100 / 6. 45.100 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100

Share:
52,475

Related videos on Youtube

Ruslan Sharipov
Author by

Ruslan Sharipov

Updated on June 28, 2021

Comments

  • Ruslan Sharipov
    Ruslan Sharipov almost 3 years

    How can I keep the flow (protocol rtsp, codec h264) in file (container mp4)? That is, on inputting an endless stream (with CCTV camera), and the output files in mp4 format size of 5-10 minutes of recording time.

    OS: debian, ubuntu Software: vlc, ffmpeg (avconv)

    Currently this scheme is used:

    cvlc rtsp://admin:[email protected]:554/ch1-s1 --sout=file/ts:stream.ts
    ffmpeg -i stream.ts -vcodec copy -f mp4 stream.mp4
    

    But it can not record video continuously (between restarts vlc loses about 10 seconds of live video).

  • Aron
    Aron over 8 years
    I would advise that you want to use -segment_atclocktime 1 if the application is for "CCTV". As this will try to split based on the wall clock and not time since recording began.
  • Cristian Toma
    Cristian Toma over 6 years
    Ffmpeg did not become avconv and avconv is not the new ffmpeg. They are different projects. stackoverflow.com/questions/9477115/…
  • AJ H
    AJ H over 6 years
    Thanks for sharing this version of FFmpeg's solution, I'd prefer to use FFmpeg over avconv. And it would be better to wrap up your URL with double-quotes so that bash won't be confused with strange characters which will cause you stuck at FFmpeg's header section.