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

Wednesday, April 27, 2016

Node Red: Forcing numeric comparisons in a Switch node

I've been learning and using node-red to control a relay that turns on my car charger (technically an EVSE, the charger being in the car itself) and one thing I discovered as that the Switch node doesn't enforce any specific type for the comparisons. A bug was reported and a change made in a previous version, for details see, but this was then removed when new features were added to the Switch node.

How this causes problems is if your numbers have different lengths and the default msg.payload type is a string; then 850 is greater than 2000.

The solution I found was a very simple intermediate function that just changes the type of the msg.payload to a number. Put this in front of your Switch node and all works as expected:

save image

Long delayed update

It's been sometime since I posted anything here. Social media and forums means that much of the stuff I'm do get mentioned there in the first instance. I am going to try to make the effort to post here too and in more detail if for no other reason than to have a long lived and locatable instance of all this stuff that I think may be interesting.