So you have a dog in your office, work on a residential television service and it’s almost April Fools’. What do you do? Put a camera on it and broadcast it of course. That’s the immediate idea I had anyways, so I spent some time in March figuring out how I could do just that.
I bounced some ideas around with the guys at work about how we could accomplish it, the simplest being just using a cellphone as it already has a battery, camera and radios, but it didn’t seem all that neat and we’d be limited by what was available as an app. Some of them had already been trying out the Raspberry Pi for their own projects and it seemed like it could be the perfect platform. Low power, runs Linux and has lots of available drivers and binary packages.
The end goal was a live 720p HD multicast MPEG-TS stream with a soundtrack and a channel logo. It was assumed that a relay server would be needed to do any heavy lifting when it came to transcoding or muxing. A couple things were settled on for the project:
- Raspberry Pi Model B
- Mobile battery pack (Trent iCarrier 12000mAh)
- Powered USB hub (Belkin)
- WiFi adapter (TP Link)
- 720p HD camera (Raspberry Pi camera board)
- Dog backpack (Kurgo Wander Pack)
- Mounting system (Hodge podge of string, GoPro and RAM mounts)
The initial purchase of hardware included a Logitech C510 webcam. The research I’d done suggested it was up to the task but on the Pi, try as I might, I could not get a decent framerate out of it. VLC seems like it never properly implemented setting the FPS through v4l2 (though a recent commit on github suggests a fix), so it always reset the driver to 30 fps which I believe contributed to problems. I tried ffmpeg and mjpg-streamer, but it didn’t matter in the end because the wild variances in framerate caused serious problems with adding an audio track. Video on its own would have been acceptable, though it suffered from intermittent speed ups and slow downs. The next attempt was with the Raspberry Pi camera board, claiming to be capable of 1080p30 and 720p60, which did the trick, though the best I’ve gotten from it with consistent quality so far is 20fps.
The Pi runs Raspbian with raspivid and vlc doing the dirty work, and the relay server runs Debian Jessie with a binary build of the real ffmpeg (not the libav fork known as avconv now) with audio and logo files.
The magic sauce for the Pi:
raspivid -ih -w 1280 -h 720 -fps 20 -t 0 -b 15000000 -o - | cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264
For the relay server:
/root/ffmpeg -r 20 -i http://192.168.1.5:8090 -re -i /root/elevator.mp2 -i /root/logo.png -filter_complex "overlay=main_w-overlay_w-30:main_h-overlay_h-30" -map 0:v -map 1:a -acodec copy -vcodec mpeg2video -analyzeduration 15 -q:v 2 -f mpegts udp://232.16.5.55:1234?pkt_size=1316,buffer_size=65535
These were all wrapped in monitoring scripts to ensure they stay up in case of any problems, along with some init.d scripts so that pieces could be restarted if need be. In the end it all worked better than I expected, though the mount for the dog’s pack was not as stable as I’d hoped, and he eventually got very moody carrying it around and we had to take off the pack. I haven’t run the setup on battery power from full charge to empty yet, but when I turned it off at the end of the day it had been running for 8.5hrs with the battery showing 2/3 bars. That could mean anything from 34% to 65% charge left, so I’m very impressed as I expected to have it run out of power some time after lunch.
Happy to answer any questions about specifics should someone be interested.
Can you add a few pictures or a description on how you mounted the Pi/Camera to the Kurgo? Thank you!