I've got a few IP Cameras which output an RTSP (h264 mpeg4) stream.

Hitting the URL locally via VLC: rtsp://

I can stream the camera and dump to disk (on my desktop). I'd like to however store these files on my NAS (FreeNAS). I was looking at ways to capture the RTSP stream and dump them to disk but I'm unable to find anything.

Is it possible to capture the stream on FreeBSD or Linux (RaspberryPi) and dump the streamed content to a disk local to Linux or FreeBSD - preferably every 30minutes?

EDIT: The NAS is headless (HP N55L or something) and the RaspberryPi's are headless too.

I've already looked into ZoneMinder but need something small. I was hoping maybe using Motion to detect motion on the stream but that will come later.

  • Why not use VLC for linux?
    – LatinSuD
    Jun 9, 2014 at 8:58
  • 2
    oops, I forgot to mention that both the FreeNAS server and RaspberryPi's are headless!
    – Keerthi
    Jun 9, 2014 at 8:59
  • 1
    You can use VLC from command line. Not trivial, but possible.
    – LatinSuD
    Jun 9, 2014 at 9:00
  • As RTSP is just a protocol, will it just dump the h264 content or do I have to get VLC to transcode it?
    – Keerthi
    Jun 9, 2014 at 9:06
  • 1
    Well that's part of the VLC command line voodoo, and sorry that's why i'm not giving you a full answer here. I think a fully transcoding is not necessary but maybe change the container. I hope that some VLC expert pops up here.
    – LatinSuD
    Jun 9, 2014 at 9:08

5 Answers 5


IP cameras are of varying quality, some behaving erratically in my experience. Dealing with their RTSP streams requires a dose of fault-tolerance.

The Live555 project provides a relatively fault-tolerant RTSP client implementation, openRTSP, for pulling RTSP audio/video streams via CLI: http://www.live555.com/openRTSP/

For example, to save a camera's RTSP audio/video to files in QuickTime format (AVI and MP4 also available), one file every 15 minutes:

$ openRTSP -D 1 -c -B 10000000 -b 10000000 -q -Q -F cam_eight -d 28800 -P 900 -t -u admin 123456 rtsp://

These options mean:

-D 1 # Quit if no packets for 1 second or more
-c   # Continuously record, after completion of -d timeframe
-B 10000000 # Input buffer of 10 MB
-b 10000000 # Output buffer 10MB (to file)
-q   # Produce files in QuickTime format
-Q   # Display QOS statistics 
-F cam_eight  # Prefix output filenames with this text
-d 28800      # Run openRTSP this many seconds
-P 900        # Start a new output file every -P seconds
-t            # Request camera end stream over TCP, not UDP
-u admin 123456  # Username and password expected by camera
rtsp://  # Camera's RTSP URL

Removing the -t option causes openRTSP to default to UDP instead, which can reduce network traffic a bit. You will need to play with the options in order to find the combination which suits you.

Frankly, the cameras themselves are sometimes unreliable, or just implemented differently -like closing the socket unexpectedly is not all that unusual.

Sometimes the openRTSP client does not catch these glitches. So I've opted to code a controller in Python using the 'subprocesses' module to invoke and monitor the stdout of each openRTSP client instance, and also check that the files are continuing to grow in size.

This appears to be a byproduct of the low-end of the CCTV industry playing fast and loose with standards, RTSP and ONVIF being the two most frequently abused.

Fortunately, you can usually work around these problems. Unless your IP cameras and controller are all designed to play nicely together, only use ONVIF for once-only discovery and settings management.

I use openRTSP on a few Raspberry Pi B+ running Raspbian. Each 1280x1024 stream occupies around 8-10% of the CPU's time, and I've successfully run up to eight cameras per RPi, writing the files to NAS storage. Another RPi processes completed files with ffmpeg, searching for motion and produce index PNGs of those frames, to assist with spotting break-ins.

There is an open-source effort called ZoneMinder which does this latter part, but I was unable to get it working with my cameras. ONVIF support is new and nascent in ZM, and it doesn't seem to contend well with the spotty RTSP streams produced by my menagerie of under-$100 IP cameras.

  • Great solution Kevin, could you please share more with motion search/png indexing solution - at least where to dig on further?
    – Igor
    Sep 13, 2015 at 4:02
  • @Kevin-Prichard I wanted to understand, 1. If I could convert say Analog SD CVSB to IP stream would your solution work? ( I want to capture mp4 videos in 1 hour chunks from each source) And would I be able to record 300 such streams over a single network 24/7 or would this overload the network? 2. Is it possible to conver Analog SD/ CVSB to IP stream?
    – CP3O
    Sep 19, 2017 at 10:49
  • @Kevin-Prichard, I am interested in your python scripts. It sounds like we have similar use cases: save the video streams from multiple security cameras to disk 24/7.
    – Eddified
    May 21, 2020 at 0:48
  • 1
    @Eddified Honestly, a lot has happened since 2015, both w/ Python and potential RTSP clients. Looks like live555's openRTSP has been getting updates (mirrored from their repo I guess). Jun 15, 2020 at 23:48
  • 1
    It seems that openRTSP does not support h265 video format yet, as I tested today (Jan 17, 2021).
    – bruin
    Jan 17, 2021 at 9:38

If I follow your question correctly, why don't you try the following command on a Linux system (RPi):

ffmpeg -i rtsp:// -vcodec copy -acodec copy -map 0 -f segment -segment_time 300 -segment_format mp4 "ffmpeg_capture-%03d.mp4"

This should save the video in chunks of 300 seconds. (Note that the clip length will depend on your input and output frame rates)

  • 2
    This should be marked as the correct answer as VLC is just full of horrible bugs
    – MitchellK
    Sep 23, 2021 at 8:59
  • In my case segments after the first were not working, I had to add -reset_timestamps 1 Oct 8, 2022 at 18:01

I just thought I'd add my two cents and complement BjornR's answer.

Instead of running a cron job to periodically kill the VLC process, one could tell VLC to run for a specified amount of time and close afterwards.

This is the command that I run on my box:

/usr/bin/vlc -vvv rtsp:// --sout=file/ts:/media/path/to/save/location/recording-$(date +"%Y%m%d%H%M%S").ts -I dummy --stop-time=480 vlc://quit

This runs VLC for the specified amount of time and later exits. The vlc://quit parameter is required since VLC would stop recording and stay open. This command needs to be placed inside a loop.

The only problem I've found so far is that it might miss a few seconds every time a new recording starts.


VLC looks like an ideal candidate to process your stream. Basic methods to capture a stream are described on the Videolan website. I sucessfully recorded the output of my D-Link DCS-5222 network camera using the following command:

vlc rtsp://user:password@ip/play1.sdp --sout=file/ogg:mystream.ogv

In your case, this might work to save the output locally:

vlc rtsp:// --sout=file/ts:mystream.mpg

I'd suggest to run a script that ends this vlc process and launch a new instance every 30 minutes as i'm not sure VLC is able to do this.

As for storing on a NAS, just mount it to your local file system.

  • 1
    You could also use FFMPEG to do exactly the same job. You will still need to mount your NAS as per the answer suggests.
    – Kinnectus
    Jun 9, 2014 at 12:39

A "all in one" solution (capture, display, event based recording...) is Shinobi. It hasa nice web based gui and good performance. I use it with different ip cameras. (h264 RTSP streams)


  • Shinobi looks really good, I'll definitely try it out: shinobi.video
    – markshep
    Nov 25, 2022 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .