[The 3rd Xuantie Cup RISC-V Application Innovation Competition] LicheePi 4A 7. Play USB camera real-time video in the browser
[Copy link]
1. My initial plan was to use webrtc as the audio and video function of the mobile phone monitoring development board. After a week, I found that when I opened the browser on the development board and opened the camera in the browser, I needed to click confirmation. This was still a small problem, but the mic of the development board was very low. It was okay for learning, but forget it for conversation. Moreover, if the webrtc signaling server and the transfer server were placed on the cloud server, the https function needed to be enabled. After the development board and the mobile phone were connected in the local area network, the CPU usage was also quite high. After the audio and video at both ends were connected, it occupied more than 230% of the CPU. Due to time constraints, I had to give up.
2. Later, I used ffmpeg to push the stream and nginx as the server. However, if I want to add the remote control function to the video interface on my mobile phone, the code is difficult to control, so I gave up.
3. So I adopted the livego solution, using livego as the media server, open source go code, and mmjpeg streaming to push the video to livego. However, when playing, the CPU usage is also 200%+, but the delay is very large. If the video file is pushed to livego and then played on the web page, the delay is not visible. If the video of the USB camera is pushed to livego, the delay is unbearable. For example, when controlling a car, the camera of the car on the mobile phone shows that it is still far away from hitting the wall. As a result, the car is controlled to move forward, but the picture seen is actually the picture 2 seconds later. As a result, the car has already hit the wall. After spending several days, I had to give up.
3. Finally, I had to choose the mjpge-streamer solution that I had not liked before. The C code is open source and I am very satisfied with it after testing. The installation and configuration methods are as follows:
Download source code git clone
//下载源代码
git clone https://github.com/jacksonliam/mjpg-streamer.git
//安装支持库
sudo apt-get install cmake libjpeg-dev
//进入文件夹
cd mjpg-streamer/mjpg-streamer-experimental
//编译,会多出来mjpg_stream文件,还有很多.so文件
make
sudo make install
//运行程序,我这里采用/dev/video0,不知为什么用/dev/video1失败
./mjpg_streamer -i "input_uvc.so -d /dev/video0" -o "output_http.so -w www"
//然后浏览器中打开,就能看到实时的画面了,而且很流畅,没有延时,CPU占用很低, 10%以下
http://192.168.31.59:8080/stream_simple.html
#注意,192.168.31.59是我开发板的IP地址
|