Project

General

Profile

Support #728

Using Motion To Stream a Webcam with a Raspberry Pi on Arch

Added by Daniel Curtis about 8 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Camera Server
Target version:
Start date:
01/20/2016
Due date:
% Done:

100%

Estimated time:
1.00 h
Spent time:

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
      
  • 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
      
  • 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
    

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;
      }
      
  • 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/;
          }
      }
      

Resources

#1

Updated by Daniel Curtis about 8 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 50
#2

Updated by Daniel Curtis about 8 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 50 to 100
#3

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#4

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#5

Updated by Daniel Curtis about 8 years ago

  • Status changed from Resolved to Closed
#6

Updated by Daniel Curtis over 7 years ago

  • Description updated (diff)
#7

Updated by Daniel Curtis over 7 years ago

  • Description updated (diff)
#8

Updated by william carinio over 6 years ago

  • Updated Motion Config
    daemon on                                                                                    
    process_id_file /var/run/motion/motion.pid                                                   
    setup_mode off                                                                               
    log_level 6                                                                                  
    log_type all
    videodevice /dev/video0
    v4l2_palette 2  
    input -1
    norm 0
    frequency 0
    power_line_frequency -1
    rotate 0
    flip_axis none
    width 1280
    height 720
    framerate 100
    minimum_frame_time 0
    netcam_keepalive off
    netcam_tolerant_check off
    rtsp_uses_tcp on
    auto_brightness off
    brightness 0
    ffmpeg_bps 400000
    saturation 0                                                                                 
    hue 0                                                                                        
    roundrobin_frames 1
    roundrobin_skip 1
    switchfilter off
    threshold 1500
    threshold_tune off
    noise_level 32
    noise_tune on
    despeckle_filter EedDl
    smart_mask_speed 0
    lightswitch 0
    minimum_motion_frames 1
    pre_capture 0
    post_capture 0
    event_gap 60
    max_movie_time 0
    emulate_motion off
    output_pictures off
    output_debug_pictures off
    quality 75
    picture_type jpeg
    ffmpeg_output_movies off
    ffmpeg_output_debug_movies off
    ffmpeg_bps 400000
    ffmpeg_variable_bitrate 0
    ffmpeg_video_codec mkv
    ffmpeg_duplicate_frames true
    timelapse_interval 0
    timelapse_mode daily
    timelapse_fps 30
    timelapse_codec mpg
    use_extpipe off
    snapshot_interval 0
    locate_motion_mode off
    locate_motion_style box
    text_right %Y-%m-%d\n%T-%q
    text_changes off
    text_event %Y%m%d%H%M%S
    text_double off
    ipv6_enabled off
    stream_port 8081
    stream_quality 50
    stream_motion off
    stream_maxrate 30
    stream_localhost off
    stream_limit 0
    stream_auth_method 0
    webcontrol_port 8080
    webcontrol_localhost off 
    webcontrol_html_output on
    webcontrol_parms 0
    track_type 0
    track_auto off
    track_iomojo_id 0
    track_step_angle_x 10
    track_step_angle_y 10
    track_move_wait 10
    track_speed 255
    track_stepsize 40
    quiet on
    
#9

Updated by Daniel Curtis over 6 years ago

  • Description updated (diff)

Also available in: Atom PDF