22

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:admin@10.1.1.1: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).

blahdiblah
  • 30,909
  • 18
  • 92
  • 149
Ruslan Sharipov
  • 653
  • 2
  • 6
  • 10

3 Answers3

25

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"

Community
  • 1
  • 1
Alexander Garden
  • 3,831
  • 3
  • 28
  • 23
  • 4
    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. – Aron Nov 23 '15 at 14:54
  • 7
    Ffmpeg did not become avconv and avconv is not the new ffmpeg. They are different projects. https://stackoverflow.com/questions/9477115/what-are-the-differences-and-similarities-between-ffmpeg-libav-and-avconv – Cristian Toma Sep 13 '17 at 05:13
17

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

DIF
  • 2,440
  • 6
  • 36
  • 49
Ron Hinchley
  • 249
  • 3
  • 4
  • 1
    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. – AJ Hsu Oct 04 '17 at 07:08
-1

Team work: Split the video source and have two processes alternate recording the time frame. You'll want to test how variable the startup time is, and how variable it is. You might want to set the processes priority to realtime to reduce start time variance. There will be some overlap but that sound like it might be ok for your application from what I infer. Example:

p1: sRRRRRRRRRwwwwwwwwsRRRRRRRRRwwwwwwwwsRRRRRRRRR...
p2: wwwwwwwwwsRRRRRRRRRwwwwwwwwsRRRRRRRRRwwwwwwwww...

                    time -->

s: startup
R: running
w: wait
Stu Thompson
  • 36,763
  • 19
  • 104
  • 155