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)
And of course, if you mapped your NAS to your operating system, FFmpeg can dump the files there.
That’s it for now!