NOTE IM STILL WRITING THIS PAGE

VLC Batch Video Recorder

Building a server to automate capturing hour long timestamped video clips for compliance/security/quality assurance using shell scripts with VLC

Background

I work in a TV studio for a company that does live gambling, (specificity roulette) on television and online. While some of the wheels have a real live spinner, others are automated and run 24 hours.

supercasino flash client

While the computers that control the roulette wheels produce a ton of raw data that is analysed to check for valid spins, statistics, randomness etc. It is would also be useful to have a recording of the raw wheel as a backup to confirm this data. Eg if the data indicates that a particular wheel is mis-spinning at a higher rate from a certain section of the wheel when the wheels spins in one direction, we can confirm this by looking up the footage of the spin, and deal with the problem.

Also as the gambling industry is heavily regulated, having 30 days worth of recordings of the wheels is also good in a CCTV kinda way, as insurance that products have not been tampered with and are fair.

In TV broadcasting you can buy a “compliance recorder” which is basically nice a box that you feed your video into, it records everything and gives you a nice interface to access your recordings for you or regulator (eg OFCOM or the FCC) if they require recordings from you. This is what we use for recording the shows that go out on air, but for just making recordings of wheels that won't be checked frequently, it would be overkill. So I have hacked a simple server to record a load of time stamped hour long clips to serve the same purpose.

Of course you could adapt the general this for other purposes where you need a lot of video recorded, compressed and timestamped, like for instance security or monitoring. Though there are better home CCTV solutions available, such as Zoneminder

Hardware

  • A modern PC with enough power to handle capturing, encoding and streaming multiple video streams, I built this out of an ex-workstation PC, with dual quad xenon procsessors, that we had lying around.
  • RAID 5 array of disks depending on your space/recording requirements.
  • USB/PCI Video/SDI/Firewire capture cards/decvices, I used 2x PCI-X video and 3x USB capture cards.
video i/o

As these where not going to be archiving quality recordings, analouge video capture was deemed "good enough". SDI would be nice, and convenient for feeding it off a video matrix without converting down to analouge video with some DAC's.

supermico case for server

Note: research driver support, before you go dropping £100's on nice SDI cards and discover you can't get VLC talking to them, thanksfully the all the hardware (bar the RAID controller) worked out the box, thank you devlopers that write device drivers.

When installing Debian, the installer couldn't find any disks, I needed to grab the non-free drivers for the Adaptec RAID 4000, they only had packages for Red Hat, but you can extract them and stick them on your install media and the installer finds them ok.

Software

  • Debian Stable (aka Squeeze)
  • VLC (I apt-pinned the newest version in testing, currently 2.0.2, as it has support for x264)
  • Samba
  • NTP and other basic admin stuff you might need like SSH, SMART monitoring etc.

Minimal install of Debian (no X11), install samba, NTP, other stuff you may find useful. NTP is quite key so that the timestamps on the video clip filenames and BITC, so set that up to your local or national time source.

BITC in the top left of EBU bars

Next we need VLC, as the current version in the stable repos is quite out of date, add the testing or sid repos to APT and install the newer version of VLC from there. As I'm building this without X, grab the "vlc-nox" package to avoid a ton of dependencies.

Scripts

Edit the scripts to your needs, eg video codec, bit rate, where to store recordings, etc.

(Dont forget to set permissions for the user you are going to run them as and to make them excutable..)

Capturing sctipt

This script captures videos from the video source (cvlc v4l2:///dev/video0:width=720:height=576), burns in a marque showing the time (--sub-filter=marq --marq-marquee='%Y-%m-%d$_%H:%M:%S' --marq-position=5 --marq-refresh=-1 --marq-size=15), then encodes.

Note as I don't need audio, I havnt including capturing and encoding from an audio device

The following pages on the VLC wiki should give you a good idea of the options;

#captures /dev/video0, burns in time code, x264@1Mbit/s, rtsp streams. 
cvlc v4l2:///dev/video0:width=720:height=576 --v4l2-aspect-ratio 16:9 --quiet-synchro --no-osd --sub-filter=marq  --marq-marquee='%Y-%m-%d$_%H:%M:%S' --marq-position=5 --marq-refresh=-1 --marq-size=15 --sout '#transcode{vcodec=h264,vb=550,scale=0.5,acodec=none,sfilter=marq}:rtp{sdp=rtsp://:8080/vid0.sdp}' :no-sout-rtp-sap :no-sout-standard-sap :sout-keep

Note: on the PCI card, they only have one phyically video i/o for composite, however the USB ones and others may have multiple (s-video and composite on a phono), with trial and error you should be able to work out which is which with the "--v4l2-input=1" option.

Recording script

To componstate for glitching at the start of clips, we make this 61 minutes long, so there is an overlap. With a cronjob we automate this script to be started every hour

#records 61min long time stamped clip, then kills itself. 
cvlc -v --no-osd --no-embedded-video rtsp://localhost:8080/vid0.sdp --sout='#std{access=file,mux=mp4,dst=/var/recordings/recorder0/%Y-%m-%d-%H%M.mp4}}' --run-time 3660 vlc://quit

Setup as a service

Service script to run as user goes here. 

Tech user crontab

# Every hour starts the recording script, and sends the garbage to /dev/null
0 * * * * /usr/local/bin/rec_vid0.sh &> /dev/null
0 * * * * /usr/local/bin/rec_vid1.sh &> /dev/null
0 * * * * /usr/local/bin/rec_vid2.sh &> /dev/null

Root Crontab

# Every hour deletes recordings older than $minutes
0 */1 * * * find /var/recordings/recorder0/ -type f -mmin +28800 -exec rm {} \;
0 */1 * * * find /var/recordings/recorder1/ -type f -mmin +28800 -exec rm {} \;
0 */1 * * * find /var/recordings/recorder2/ -type f -mmin +28800 -exec rm {} \;

Fine tune the number of minutes to how much space you have for recordings

htop showing load

Administrating machine using PuTTY and showing load of 3 recordings in progress.

Samba share

Now that we have the server all setup recording 1 hour long clips, setup a simple samba share, so users can view recordings.

#simple samba smb.conf share for recordings

[recordings]
comment = compliance recordings
path =  /var/recordings
guest ok = yes
browseable = yes

As there is not much value of these recordings, I have just setup a open read-only guest acess to the recording, so that should a clip need to be reviewed later, recordings can be tranfered off to somewhere more permanent.

accessing recordings using samba and playing files with vlc

User accessing recordings using samba and reviewing recordings using vlc

Credits

"Duncan at QVC" for the orignal idea of using vlc for this purpose and providing a basic implatition of it using vlc on windows.

CCTV

Bonus CCTV project!

While for serious home CCTV you would be better served with something like Zoneminder, for fun I made a similar script for an old USB webcam that I connected up to my home server for use as CCTV.

home cctv

cctv.sh

cvlc v4l2:///dev/video0:width=352:height=292 --quiet-synchro --no-osd --sub-filter=marq --marq-marquee='%Y-%m-%d %H:%M:%S' --marq-position=5 --marq-refresh=-1 --marq-size=15 --sout '#transcode{venc=x264{keyint=60,profile=main},vcodec=x264,vb=100,scale=0.5,sfilter=marq}:rtp{sdp=rtsp://:8080/cctv.sdp}' :no-sout-rtp-sap :no-sout-standard-sap :sout-keep

I've currently just got this running live, though could have it automated to record hour long clips pretty easily.

Now I can be anywhere in the world, jump on my VPN and see if my package from Amazon has arrived yet.

android_vlc_rtsp_stream.png

I can also view this stream from my phone.... there's no picture there, cos its night and the light is off... obviously.

Hooking up some IR LED's or getting a camera with nightvision built in would be awesome.

server_cctv2.jpg

See, works fine with the lights on...