I talked about using a ONVIF camera to stream to a Chromecast earlier because they come with an open well documented interface for pulling video from them (as well as pan/tilt/zoom control if available).
If you don’t have a camera that supports ONVIF you can build something similar with a Raspberry Pi and the Camera module.
This should work with pretty much all of the currently available Raspberry Pi models (With the exception of the basic Pi Zero that doesn’t have Wifi)
- Flash a SD card with the Raspbian Lite image
- Insert the camera ribbon cable into both the camera module and the Pi
- Once the card has booted use the
raspi-confcommand to enable the Camera interface
- Install ffmpeg
sudo apt-get install ffmpeg
- Create a script with the following content
#!/bin/sh v4l2-ctl --set-ctrl video_bitrate=300000 ffmpeg -f video4linux2 -input_format h264 -video_size 640x360 -framerate 30 -i /dev/video0 -vcodec copy -an -f flv rtmp://192.168.1.96/show/pi
- This script sets the max video bitrate to 30kps
- If you need to rotate the video you can insert
v4l2-ctl --set-ctrl=rotate=180before ffmpeg to rotate
ffmpeguses the videolinux2` driver to read from the attached camera (
h264encoded feed at
30frames per second and outputs it to the same nginx instance that I mentioned in my previous post. The feed is called
ffmpeg uses the on board hardware support for the video encoding so even a Pi Zero W runs at about 5% CPU load. This means that if you only have 1 camera you could probably run nginx on the same device, else you can have a multiple cameras all feeding to a central video streaming server.
If you want a kit that comes with the Pi Zero W, Camera and a case to mount it to a window have a look at the Pimoroni OctoCam.
The instructions should also work for pretty much any USB (or built in) camera attached to a Linux machine.