Support #728
Using Motion To Stream a Webcam with a Raspberry Pi on Arch
Description
This is a guide on how I created a video stream using a webcam attached to a Raspberry Pi Model B running Arch Linux.
Prepare the Environment¶
- Make sure the system is up to date:
sudo pacman -Syu
Get Webcam Information¶
- Install the v4l2 utilities:
sudo pacman -S v4l-utils
- Get the current resolutions and pixel format of the webcam:
v4l2-ctl -V
- NOTE: For more details use the following command:
v4l2-ctl --all
- NOTE: For more details use the following command:
- Get a list of supported resolutions and pixel formats:
v4l2-ctl --list-formats-ext
- Set the resolution of the webcam to 352x288 (to make streaming a little faster):
v4l2-ctl --set-fmt-video=width=352,height=288,pixelformat=0
Install Motion¶
- Install motion:
sudo pacman -S motion
- Edit the motion config file:
nano /etc/motion/motion.conf
- And modify the following parameters:
daemon on v4l2_palette 2 width 352 height 288 framerate 100 webcam_localhost off control_localhost off output_normal off ffmpeg_cap_new off ffmpeg_cap_motion off webcam_motion off webcam_maxrate 100
- And modify the following parameters:
- Test start the motion server to check that everything is running properly:
sudo motion -n -c /etc/motion/motion.conf
Ctrl+C
to quit the server when done testing.
- Make the /run/motion directory:
mkdir /run/motion
- Start and enable the server at boot:
sudo systemctl enable motion sudo systemctl start motion
- Open a web browser and go to http://motion.example.com:8081 to view the video stream.
- Open a web browser and go to http://motion.example.com:8080 to view configuration information.
Install Nginx¶
- Install Nginx
sudo pacman -S nginx
- Start and enable nginx at boot:
sudo systemctl enable nginx sudo systemctl start nginx
- Create a configuration directory to make managing individual server blocks easier
sudo mkdir /etc/nginx/conf.d
- Edit the main nginx config file:
sudo vi /etc/nginx/nginx.conf
- And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
worker_processes 1; error_log /var/log/nginx-error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; # nginx may need to resolve domain names at run time resolver 192.168.1.1 ipv6=off; include /etc/nginx/conf.d/*.conf; }
- And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
- Add a camera site server block:
sudo vi /etc/nginx/conf.d/camera.example.com.conf
- Add the following:
server { listen 80 default_server; server_name camera.example.com; access_log /var/log/camera.example.com.log; location / { proxy_pass http://localhost:8081/; } }
- Add the following: