[Tutorial] [Record] Raspberry Pi Raspberry+mjpg-streamer+camera realizes photo, video and real-time video functions

I am new to Raspberry Pi, so please give me your advice.


1. Preparation

1. Raspberry Pi 4B
2. Raspberry Pi camera 500W pixels (Taobao more than ten dollars) (csi interface)
3.mjpg-streamer
insert image description here

2. Operation steps

1. Enter the settings to open the camera module

In the Raspberry Pi terminal window type:

sudo raspi-config 

Select interface option–>I1 Camera in turn, then enter, confirm, and restart, as shown in the figure
insert image description hereinsert image description here

2. Install mjpg-streamer

(1) Update and install related packages

#更新软件
sudo apt-get update			
sudo apt-get upgrade	
#安装相关的包	
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				

(2) Download the source code and compile and install
Download

sudo apt-get install wget
sudo wget https://github.com/Five-great/mjpg-streamer/archive/master.zip
sudo unzip  master.zip

Enter the directory and compile

cd mjpg-streamer-master/mjpg-streamer-experimental
sudo make
sudo make install

(3) View the Raspberry Pi camera node and configure it

cd
ls /dev/video*

If there are many video0, video10, etc. as shown in the figure below, it is case A.
If there is no video, it is case B.

insert image description here
Continue to switch back to mjpg-streamer/mjpg-streamer-experimentalthe directory and
configure the startup file

sudo  nano start.sh

First comment out the original one at the arrow
insert image description here
and then add the following code yourself
Case A:

./mjpg_streamer -i "/usr/local/lib/mjpg-streamer/input_uvc.so -n -f 80 -r 800x600" -o "/usr/local/lib/mjpg-streamer/output_http.so -p 8081 -w /usr/local/share/mjpg-streamer/www"

Case B:

./mjpg_streamer -i "/usr/local/lib/mjpg-streamer/input_raspicam.so -n -f 80 -r 800x600" -o "/usr/local/lib/mjpg-streamer/output_http.so -p 8081 -w /usr/local/share/mjpg-streamer/www"

For mjpg-streamer, you can check this article yourself .

3. start

Still mjpg-streamer-master/mjpg-streamer-experimentaloperate in the directory

sudo ./start.sh

If such a problem occurs, please execute:
insert image description here

sudo chmod  777 /dev/video0

Then re-execute the startup command and run it successfully to
insert image description here
see the effect
(1) View in the LAN (192.168.137.xx is your own Raspberry Pi ip address)
Enter in the browser: http://192.168.137.xx:8081/
very smooth
insert image description here
(2) Remote view on the public network (192.168.137 .xx is your own public network ip address)
Enter in the browser: http://192.168.137.xx:7001/
the effect is good, it does not affect the live broadcast, yeah! ( You can refer to this article to use intranet penetration to view real-time video through the public network )
insert image description here
4. Set quick start and stop
(1) Start

cd
sudo  nano start-mjpg.sh

fill in

#!/bin/bash

sudo chmod  777 /dev/video0
# 下面路径为自己的安装目录路径
cd /home/lumuzi/mjpg-streamer/mjpg-streamer-experimental/
./start.sh

Ctrl+s, Ctrl+x, save and exit
(2) stop

cd
sudo  nano stop-mjpg.sh

fill in

#!/bin/sh

sudo kill -15 $(pgrep mjpg)
sudo kill -15 $(pgrep mjpg)

Ctrl+s, Ctrl+x, save and exit
Grant permission:

sudo chmod 777 start-mjpg.sh
sudo chmod 777 stop-mjpg.sh
# 启动
sudo ./start-mjpg.sh
# 停止
sudo ./start-mjpg.sh

3. Summary

I am also new to Xiaobai. As the saying goes, a good memory is not as good as a bad pen. I use this article to record my exploration process. If there is any discomfort in the article, please criticize it.

Guess you like

Origin blog.csdn.net/qq_44696500/article/details/124695075