Friday, May 6, 2016

Updated Streaming Geovision IP-CAM to YouTube

I recently got a Raspberry Pi 3 to play with and wondered if it could take over the Cat Cam streaming duties from a more traditional x86 Linux server. Moving the script over and updating it for the much newer version of avconv (the libav-tools version of ffmpeg) I found it worked but consumed a whole core of CPU and ran hot at 100% - but it worked.

Well, this was the same problem that forced me to hold back updates to libav-tools on the original server. I thought harder. Realised that the CPU was nowhere near enough to be transcoding the video and so maybe the audio was the problem. Remember that the original avconv command line added a silent audio track and then encoded it as aac? Well, perhaps the aac codec was inefficient? I tried mp3 as the Raspbian version of libav-tools has mp3 encoding as standard, unlike the older version I had. Not much change.

Next brainwave, see if the camera can add silence and just copy the stream, same as the video. Well, I remember there was a setting and eventually I found it:

I ticked this, saved, changed the command line to simply copy the stream and voila! Down to 3% and streaming perfectly.

As the Pi isn't quite ready for production use at home I went back to my original server, updated libav-tools and the dependencies and made the same changes and I was greatly relieved to see the same behaviour. All is good, finally.

The underlying command line is now like this:
avconv -v warning -rtsp_transport tcp -i rtsp://camera1:8554/CH001.sdp -codec:v copy -codec:a copy -f flv rtmp:// -c copy -map 0:v -f segment -segment_time 300 camera1-%03d.mp4
Note that the last part of the command line is to do with the saving off or 5 minute chunks as a CCTV backup and everything after the -c copy ... can be left out