directory

Method 1: Motion

Method 2. Mjpg-streamer mode


Before, I needed raspberry PI and PC for video transmission. I found two methods:

Method 1: Python+OpenCv to achieve raspberry PI data collection, raspberry PI to build the server, PC as the client to achieve data transmission, the result found that the transmission quality is poor.

Address: blog.csdn.net/m0_38106923…

Method 2: Use Python+ raspberry PI original camera, use Python code to call, then set up the server, transmit video, remarkable effect.

Address: blog.csdn.net/m0_38106923…

Recently found a new way to transfer data, raspberry PI built a webcam, not only smooth speed, impressive effect, and multiple users can access at the same time, cool

To show you the effect of simultaneous access from PC and mobile:

Now I’m going to explain to you the process of building a Raspberry PI webcam. There are two main ways.

  • Method 1: Motion

Step 1: Install the Motion package

sudo apt-get install motion
Copy the code

Step 2: Start the Motion Daemon daemon and keep it running in the background

Sudo nano /etc/default/motion # no: start_motion_daemon=yesCopy the code

Step 3: Modify the Motion configuration file

Sudo vim /etc/motion/motion.conf #deamon on # set resolution width 800 height 600 webcam_localhost offCopy the code

Step 4: Run Motion

sudo motion
Copy the code

Now our webcam has turned into a webcam. Visit http://[your.domain]:8081 in Chrome and you can see the pictures taken by the webcam. It should be noted that sometimes the webcam may not start after the raspberry PI is restarted. So you need to rerun Motion.

It should be noted that the first webcam construction method is not convenient for access to Android mobile phones, so I did not use it here, and I will only expand the explanation here.

PC access to Python is very simple, directly use the VideoCapture() method of OpenCv module, enter the webcam URL. Use pseudocode as follows:

VideoCapture() is 0, which means to open the internal camera of the computer, and 1 or 2, which means to open the external camera, which means to open the video file path, which means to open the video file URL, which means to open the webcam. Cap = cv2.videocapture (URL)Copy the code
  • Method 2. Mjpg-streamer mode

Step 1: Install the required modules

sudo apt-get updatesudo 
sudo apt-get install subversionsudo 
sudo apt-get install libjpeg8-devsudo 
sudo apt-get install imagemagicksudo 
sudo apt-get install libv4l-devsudo 
sudo apt-get install cmakesudo 
sudo apt-get install git
Copy the code

Git an open source project: mJPg-streamer

sudo git clone github.com/jacksonliam/mjpg-streamer.git 
cd mjpg-streamer/mjpg-streamer-experimentalsudo 
make all
sudo make install
Copy the code

Git process is slow, you can wait for a period of time, wait for 100% confirm completion and then execute the next command to start the USB camera, the command is as follows:

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

It should be noted that the commands for configuring a USB camera are different from those for the dedicated raspberry PI camera. Here I configured a USB camera, and the specific commands are as follows:

/input_uvc.so" -o "./output_http.so -w./ WWW "RaspiCamera:  ./mjpg_streamer -i "./input_raspicam.so" -o "./output_http.so -w ./www"Copy the code

In addition, to use the dedicated raspberry PI camera, you need to enable the dedicated camera configuration, and enter the following command:

sudo raspi-config
Copy the code

Click camera Enable to enable.

The above has realized all the webcam construction. However, every time we start the raspberry PI, we still need to manually execute the corresponding command, which is quite troublesome. So let’s set the current entry to a system boot entry.

Step 3: Set autoboot

CD Go to the system home directory, create an sh executable file, and run the following command:

sudo nano videoStart.sh
Copy the code

Enter the following information in the videostart. sh file:

cd /home/pi/mjpg-streamer/mjpg-streamer-experimental/

./mjpg_streamer -i "./input_uvc.so" -d /dev/video0 -f 30 -r 1280x720 " -o 

"./output_http.so -p 8080 -w ./www"
Copy the code

Then exit the save, and finally give an executable permission by typing:

sudo chmod +x /home/pi/videoStart.sh
Copy the code

To create another directory, type the following command:

sudo mkdir .config/autostart
Copy the code

To create a new file, enter the following command:

sudo nano .config/autostart/my.desktop
Copy the code

The content of the document is as follows:

[Desktop Entry]

Type=shell

Exec=/home/pi/videoStart.sh
Copy the code

Finally, save and exit, so that each startup will automatically execute the corresponding file command, eliminating the trouble of manual execution.

Step 4: Test

To view the image, open the browser on PC and enter the following url to see the static screenshot:

http://raspberry PI IP>:8080/? Action =snapshot

I am here is the address: http://192.168.0.112:8080/? action=snapshot

Enter the following two urls to see a moving image:

http://raspberry PI IP>:8080/? Action =stream

The raspberry pie here address: http://192.168.0.112:8080/? action=stream

This address does not work well on some browsers, you can use the following url:

http://< Raspberry PI IP>:8080/javascript_simple.html

Summary: After continuous exploration of raspberry PI and PC video data communication “trilogy” ends here, hope to help friends ~

So with live video streaming on the LAN, how do you watch it on the Internet? That here I will give you a recommendation can penetrate the LAN software: peanut shell, presumably contact with the Internet friends, should have a certain understanding of this, with their own router can achieve LAN computer and Internet docking.