The Club’s SlipCam setup is done with a few “moving” parts – an IP camera that supports RTSP, a relay server in the office that transcodes the video, some PHP, HTML, and Javascript on our website, and YouTube’s live video hosting.

Camera

We use a Hikvision DS-2CD2035FWD-I 3MP IP camera with a 2.8mm lens for a 98 degree field of view; we got ours from use-ip.co.uk, but you can probably find a similar camera elsewhere. On a technical aspect, you’re looking for at least a 3 megapixel camera that will do a minimum of 1280×720 (referred to as HD), and preferably 1920×1080 (referred to as Full HD or FHD). More megapixels at the same resolution will result in a crisper/clearer image. A smaller mm on the lens (ie, 2.8 vs 4) will give a wider field of view (98 degrees vs 78 degrees), and more of a fish-eye effect when the horizon is not at the vertical half-way point of the frame. This is sometimes visible on our stream when the camera is not perfectly aligned with the horizon.

The camera is mounted on the side of the clubhouse; a length of outside-rated Cat5e Ethernet cable is run down to where our internet router sits, and a PoE injector is used as a bridge between the router and the camera to provide power to the camera over the data connection. The Hikvision, as shipped, came with a waterproof metal mounting box, with full seals and o-rings. After a year in the Irish weather, the white seal between the camera mount and the mounting box lid is degrading; the black seal for the mounting box lid is fine.

“Static” SlipCam

The static version of our SlipCam uses FTP to push a snapshot every few seconds from the camera to our web hosting; this is a feature of the camera firmware. Some simple PHP, HTML and Javascript is used to create a page that sends a new image to the browser when one is available. Due to the nature of the FTP connection, this camera has a refresh rate of approximately 1 frame every 5 seconds. Each image is a few hundred kilobytes.

In our case, the PHP and HTML files are respectively www.dmyc.ie/webcam.php and www.dmyc.ie/webcam.html. The former is used by the latter, so the latter is the URL we put in our navigation menu, share on Facebook etc.

Streaming SlipCam

The streaming version of our SlipCam is done with the same camera, but the camera doesn’t support pushing video to YouTube natively, so some extra work has to be done. Right now this is done with a server in the office that pulls the video from the camera, converts it from h264 to FLV format, adds a silent audio track to keep YouTube happy, and then re-broadcasts it to YouTube with a roughly 30 second delay. A dedicated account is configured with just RTSP streaming rights (on the camera), so that credential compromise doesn’t lead to admin rights on the camera.

The h264 to FLV conversion is done using a shell script that runs ffmpeg. The camera is treated as a RTSP input, a nullsrc is used for the audio, and the sink is a local instance of nginx that has the RTMP module enabled. The nginx instance is configured to broadcast the stream over to YouTube. Nginx isn’t required, but we’ve found that it makes the stream more stable. You can, of course, set YouTube’s publishing URL as the output sink for ffmpeg, with exit detection in the script to ensure that ffmpeg is restarted automatically if there’s a problem.

The ffmpeg incantation looks like

ffmpeg \
-f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \
-i rtsp://[email protected]$SRC_HOST/ \
-c:v copy -c:a aac \
-map 0:a -map 1:v \
-f flv rtmp://localhost:1935/splitter/

An experiment, right now, is to use ffmpeg to do some overlays of data feeds on the video; one from Twitter, and one from marine.ie.


TXTFILE="world"
LOGO="overlay=25:25[LOGO]"
TXT="[BOX]drawtext=fontsize=20:textfile=$TXTFILE:x=5:y=(h-text_h):fontcolor=white:reload=1"
BOX="[LOGO]drawbox=h=45:x=0:y=(ih-h):w=iw:[email protected]:t=max[BOX]"

ffmpeg -thread_queue_size 256 -reorder_queue_size 100 -probesize 32 \
-i rtsp://[email protected]$SRC_HOST/ \
-f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \
-map 1:a -map 0:v \
-c:a copy \
-c:v copy \
-bufsize 700k \
-f flv - 2>/dev/null | ffmpeg -thread_queue_size 512 -i pipe:0 -i logo.png -filter_complex "$LOGO;$BOX;$TXT" -c:a aac -qmin 2 -qmax 4 -vb 1500k -f flv rtmp://youtube/...

Internet connection

You’ll need an internet connection that can sustain several megabits per second of upload traffic, and that won’t throttle you for uploading a lot. Some ISPs operate plans where your download and upload quota are tied together, and streaming a full HD video 24 hours a day can use a lot of this quota very quickly. The camera streams approximately 500 MB per hour, but it really depends on whether it’s daytime or nighttime, and during the day, if it’s bright and sunny, or overcast and grey.