Support #728
Updated by Daniel Curtis over 8 years ago
This is a guide on how I created a video stream using a webcam attached to a Raspberry Pi Model B running Arch Linux.
h2. Prepare the Environment
* Make sure the system is up to date:
<pre>
sudo pacman -Syu
</pre>
h2. Get Webcam Information
* Install the v4l2 utilities:
<pre>
sudo pacman -S v4l-utils
</pre>
* Get the current resolutions and pixel format of the webcam:
<pre>
v4l2-ctl -V
</pre>
#* *NOTE*: For more details use the following command:
<pre>
v4l2-ctl --all
</pre>
* Get a list of supported resolutions and pixel formats:
<pre>
v4l2-ctl --list-formats-ext
</pre>
* Set the resolution of the webcam to 352x288 (to make streaming a little faster):
<pre>
v4l2-ctl --set-fmt-video=width=352,height=288,pixelformat=0
</pre>
h2. Install Motion
* Install motion:
<pre>
sudo pacman -S motion
</pre>
* Edit the motion config file:
<pre>
nano /etc/motion/motion.conf
</pre>
#* And modify the following parameters:
<pre>
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
</pre>
* Test start the motion server to check that everything is running properly:
<pre>
sudo motion -n -c /etc/motion/motion.conf
</pre>
#* @Ctrl+C@ to quit the server when done testing.
* Make the /run/motion directory:
<pre>
mkdir /run/motion
</pre>
* Start and enable the server at boot:
<pre>
sudo systemctl enable motion
sudo systemctl start motion
</pre>
* 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.
h2. Install Nginx
* Install Nginx
<pre>
sudo pacman -S nginx
</pre>
* Start and enable nginx at boot:
<pre>
sudo systemctl enable nginx
sudo systemctl start nginx
</pre>
* Create a configuration directory to make managing individual server blocks easier
<pre>
sudo mkdir /etc/nginx/conf.d
</pre>
* Edit the main nginx config file:
<pre>
sudo vi /etc/nginx/nginx.conf
</pre>
#* And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
<pre>
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 208.67.222.222 208.67.220.220;
include /etc/nginx/conf.d/*.conf;
}
</pre>
* Add a *camera site server block*:
<pre>
sudo vi /etc/nginx/conf.d/camera.example.com.conf
</pre>
#* Add the following:
<pre>
server {
listen 80 default_server;
server_name camera.example.com;
access_log /var/log/camera.example.com.log;
location / {
proxy_pass http://localhost:8081/;
}
}
</pre>
h2. Resources
* http://www.lavrsen.dk/foswiki/bin/view/Motion/ConfigFileOptions
* http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideBasicFeatures
* http://pimylifeup.com/raspberry-pi-webcam-server/
* https://www.linux.com/learn/tutorials/780055-how-to-operate-linux-spycams-with-motion