title: Use ffmpeg to segment streaming video
body: <p>Suppose I have a streaming video URL rtsp://whatever and I wish to store that video stream to my file system as a series of files off approximately the same size or duration. Ideally I would like to store the files with a start and stop timestamp as part of the filename, and each file should be such that it can stand on its own to be displayed as a video file if someone wants to view it. I understand that ffmpeg has a segment command option that allows me to segment by time and store in a series of files like outfile%3d.dat or whatever. But suppose I want to do this perpetually and cycle the files (age out old ones) when the total size of all the saved files exceeds a specific value. For example, suppose I want to save the most recent 500GB of video from this streaming URL and keep doing this day after day continuously into the distant future. What happens to the output filename after outfile999.dat is saved? Does the count start over at 0? Or does ffmpeg just stop or crash? Is there an ffmpeg command that can segment and age out old files, or is this something I would have to do running another program simultaneously or would I have to hack into ffmpeg itself to do this? I'm pretty new to ffmpeg so any suggestions you ffmpeg experts might have on how to do this would be welcome. I also welcome suggestions for other command line Linux tools that might be better for this application.</p>
  
  <p>UPDATE: So it turns out that ffmpeg has a segmenter built in, and I can segment the files such that the filenames have the video start datetime as part of the filename. I used a command like this:</p>
  
  <pre><code>ffmpeg -i rtsp://camera_feed_url_here -c copy -f segment -segment_list out.list -segment_time 900 \ -segment_atclocktime 1 -strftime 1 "%Y-%m-%d_%H-%M-%S.mkv"
  </code></pre>
  
  <p>That's the good news. The bad news is that when I run this command, after about 1 minute it just throws this error and stops:</p>
  
  <p>rtsp://camera_feed_url_here: Invalid data found when processing input</p>
  
  <p>No other error or diagnostic mesages are printed out. Even when I run with -loglevel debug, it just seems to die with this error message.</p>
  
  <p>When I built ffmpeg, used this:</p>
  
  <pre><code>./configure --enable-demux='rtsp,rtp,sdp,flac,gif,image2,image2pipe,matrosk' --enable-network --enable-protocols --enable-decoder=h264
  </code></pre>
  
  <p>Any ideas what I'm doing wrong and how I can make this error go away?</p>