Recording IP Camera Footages onto NAS or local storage

In my previous post, I shared about my overhaul of IP Cameras in my home. I ditched the 3 cheap D-Link DCS-930L and went for 2  D-Link DCS-5222L IP Cameras. One great feature of this camera is the ability to do RTSP streams. Cheaper IP Cameras usually stream in Motion-JPEG format which I personally find the quality crappy and may not have the audio stream available.

After a few days of research, I concluded that I need to get a camera that streams H.264 via RTSP so that I can capture them natively as mp4 files. D-Link DCS-5222L does that and the price was pretty reasonable for its RTSP support, 720p resolution, PTZ feature and good viewing angle. The hardest thing to do is to choose software that will:

  • Stream from the cameras via command line
  • Dump the video stream as H.264 Mp4 files
  • Save the audio stream in the same file container
  • Segment the footages at my chosen interval with appropriate file naming
  • Reasonably crash-resilient (I’ll explain why later)

I’ve tried many off-the-shelf products and the best one out there appears to be Webcam 7 Pro. It is reasonably stable but captures mainly MJPEG streams only without audio. It does a good job segmenting files and you can even make it auto delete footages that are X days old. Enough of this lest I sound like I’m promoting the software.

I found that VLC is a good candidate as it has robust command line features and can be used to relay a media stream as a fresh broadcast or dump a stream to file with real-time transcoding i.e. you can transcode a H.264 stream into a mpeg file for storage (but you don’t want to do that of course because mpeg files are larger). The problem with VLC that I face is that it crashes easily and that seems to be a bug which caused a stream to be decoded to some raw format causing my disk space to fill up overnight. In the end, I use VLC as a monitoring tool as I can easily launch the RTSP stream by passing the IP Camera URL, port, credentials and the fullscreen parameters via command line.

Here’s how I did it for my camera:

vlc rtsp://admin:[password]@[ip address]:[port]/live1.sdp –fullscreen

Remember to replace [password], [ip address] and [port] with your own values.

Moving on to the next candidate, FFmpeg. 

FFmpeg has been around for many years and many video conversion / broadcasting software including VLC make use of components from FFmpeg! As mentioned above, I needed something that can save both video and audio streams, segment files (so that you don’t get a huge 100GB file after a few weeks) and be able to use timestamps as the filename.

After tinkering for a day or two, I decided that this will work for me:

start “Door Cam” “ffmpeg.exe” -i rtsp://admin:[password]@[ip address]/live1.sdp -c copy -map 0 -f segment -segment_atclocktime 1 -strftime 1 -segment_time 1800 -segment_format mp4 -vcodec copy -acodec aac -strict experimental -ab 64k “.\Recordings\DoorCam-%%Y-%%m-%%d_%%H%%M.mp4”

The above command (yes I know it probably contain redundant flags because I whippped this up with much trial and error) will:

  • start reading the video and audio stream as defined in the SDP file of my D-Link DCS-5222L
  • copy the video stream “as-is” and convert the audio (from PCM mu-law) to AAC @ 64Kbps and mux them into a mp4 container
  • segment the files (chop up the files every 1800 seconds (30 minutes)
  • synchronise the next segment on the clock (i.e. 12:30pm, 1pm, 1:30pm, etc)
  • Give each segment a meaningful filename (e.g. DoorCam-2016-12-4_1030.mp4)

The results:

Don’t worry about the errors. It happens a lot with live streaming devices such as an IP Camera


And of course, if you mapped your NAS to your operating system, FFmpeg can dump the files there.

That’s it for now!


Home Surveillance overhaul with D-Link DCS-5222L

D-Link DCS-5222L

Got two D-Link DCS-5222L IP Cameras from Lazada to replace my old D-Link DCS-930L (3 of them). I was a fan of cheap IP Cameras and was always telling people how I can monitor my home for under $100. However, as time passes by, I am no longer satisfied with the poor field of view offered by cheap IP Cameras. As an interim solution, I even bought wide angle lenses meant for Smart Phones and mounted them on the D-Link DCS-930L using adhesives or magnetically.

D-Link DCS-930L with self mounted wide angle lens bought separately.
D-Link DCS-930L with self mounted wide angle lens bought separately.

Here’s how one of the 3 look like:

Even with the wide angle lens, I wasn’t satisfied.I did not mount the cameras securely so a slight knock will tip the cameras off the surface and I spent quite a bit of time looking for the fallen lenses.

I decided that enough was enough. I took the plunge and went for the D-Link DCS-5222L which is a PTZ IP Camera with wide angle lens built-in. The IR LEDs were also immensely useful. No more pitch black videos in my NAS at night!

Another feature I look to the D-Link DCS-5222L is the availability of RTSP streams. This allows me to:

  1. Use VLC to easily launch the RTSP stream on any computer for quick viewing or monitoring
  2. Use FFMPEG to record the RTSP stream onto my NAS or local disk. I know VLC can do the same but after much tries, FFMPEG appears to handle errors from the live streams without crashing so easily.

In my next post, I will talk about how I use VLC and FFMPEG to build my own command line IP Camera recording and viewing.