树莓派 摄像头mjpg-streamer视频推流+开机自启动

1.Enable树莓派摄像头

sudo raspi-config

enable摄像头(执行一次即可,无需每次开机都执行),进入后,将camera一项enable,然后重启:

sudo reboot

2.更新安装库

sudo apt-get update
sudo apt-get install subversion
sudo apt-get install libjpeg8-dev
sudo apt-get install imagemagick
sudo apt-get install libv4l-dev
sudo apt-get install cmake
sudo apt-get install git

3.下载git开源的项目

sudo git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
sudo make all
sudo make install

普通USB摄像头开启:

./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"

Raspberry Pi Camera开启:

./mjpg_streamer -i "./input_raspicam.so" -o "./output_http.so -w ./www"

查看摄像机画面:

摄像头:获取摄像头的动态画面:
http://192.168.1.6:8080/?action=stream
获取摄像头的静态页面:
http://192.168.1.6:8080/?action=snapshot

4.设置为开机自启动

在/lib下的systemd创建mjpg_streamer服务 :

sudo nano /lib/systemd/system/mjpg_streamer.service

copy以下代码:

[Unit]
Description=A server for streaming Motion-JPEG from a video capture device
After=network.target
 
[Service]
ExecStart=/usr/local/bin/mjpg_streamer -i "/usr/local/lib/mjpg-streamer/input_raspicam.so -d /dev/video0" -o "/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www"
 
[Install]
WantedBy=multi-user.target

最后:

sudo systemctl enable mjpg_streamer
sudo reboot

你可能感兴趣的:(树莓派,运维)