Wildlife Camera

I created a simple ‘weatherproofish’ Raspberry Pi camera setup, which I detail below:

I bought the following hardware:

With the LED IR light, I placed some duct tape over the LDR on it, so that it remains always on.

I used ZyXEL PLA5205 600 Mbps Powerline Gigabit Ethernet Adapter to attach to the Pis ethernet interface. This provides a fast network which can connect far away from my Wifi AP (my Wifi AP has a powerline adapter connected to its ports).

When streaming to youtube for a while, with the 2m cable I noticed image corruption occurring after a number of hours. However I also noticed the sunny connector had become slightly loose. I have now glued the sunny connector and am using a 1m cable now, when I streamed over night it worked well, after making a script which detects problems with the stream to youtube going down.

‘sudo vcdbg log msg’ gave the following when image corruption occurred:

3480690.655: vcos_abort: Halting
3482637.188: mmal: fail_destroy: Timed out waiting to destroy ril.camera

I stream to youtube using the following command (which was found on https://www.youtube.com/watch?v=S3zNBGfPFxI – I also followed his guide for installing ffmpeg).

raspivid -o - -t 0 -fps 30 -b 6000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le \ 
-f s16le -ac 2 -i /dev/zero -f h264 -r 30 -i - -vcodec copy -acodec aac -ab 128k     \
-g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<your code>

Originally I used a bitrate of 1000000 (1Mbps) which I have been told is far too low! And could have been the cause of some of my videocore issues.

If you get message like the following in the videocore logs:

2582211.411: mmal: mmal_port_send_buffer: ril.video_encode:in:0(OPQV): send failed: EINVAL
2582211.446: mmal: mmal_port_connected_output_cb: ril.camera:out:1(OPQV) could not send buffer on port ril.video_encode:in:0(OPQV) (EINVAL)
2668226.995: mmal: mmal_port_send_buffer: ril.video_encode:in:0(OPQV): send failed: EINVAL

It could simply be due to the stream to youtube dropping due to flaky Internet, like mine!

I created a bash script, which is run as root, based on this command, which checks for the stream dropping and starts the stream again if necessary:

#!/bin/bash

function stream {
	sudo -u pi raspivid -v -o - -t 0 -fps 30 -b 1000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -r 30 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/ > outp 2>&1 & 
}

vcdbg log msg 2> vidcore
OLD="$(cat vidcore  | grep "ril.video_encode:in:0(OPQV): send failed: EINVAL" | tail -n1 | awk -F':' '{ print $1 }')"

stream;

while [[ 1 ]]
do
	sleep 20
	vcdbg log msg 2> vidcore
	grep "ril.video_encode:in:0(OPQV): send failed: EINVAL" vidcore > /dev/null
	
	RES=$?
	
	if [ $RES -eq 0 ]; then
	
		TIMEERR=$(cat vidcore  | grep "ril.video_encode:in:0(OPQV): send failed: EINVAL" | tail -n1 | awk -F':' '{ print $1 }')

		if [ "$TIMEERR" != "$OLD" ]; then
			echo "Net died, waiting 60 secs"
			pkill -9 ffmpeg	
			sleep 60
			rm outp
			echo "starting stream again" 
			stream;
		fi

		OLD=$TIMEERR
	fi
done

You can see all the hardware in the weatherproof box below:

The rapsberry pi camera fits well in the waterproof housing, I managed to thread the camera cable between the two hinges of the waterproof casing 🙂

I noticed I can get a black image from Raspistill but I believe this is due to it being dark outside and PiCamera using different default image capture settings, can capture fine. When I set the ISO to 800 in Raspivid, I get better results in the dark.

Oh dear, seems to have broken completely now....

mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
mmal: Failed to create camera component
mmal: main: Failed to create camera component
mmal: Camera is not detected. Please check carefully the camera module is installed correctly

Leave Comment

Error Please check your entries!