1、使用motion(方法一推荐)

1、安装motion

1
sudo apt-get install motion

2、修改 /etc/default/motion文件

1
sudo nano /etc/default/motion

改成:(多半是没有这个文件,那就创建一个呗)

start_motion_daemon=yes

3、修改/etc/motion/motion.conf配置文件

1
sudo nano /etc/motion/motion.conf

如果在之前开启过motion服务要先杀死motion进程

1
sudo killall -TERM motion

将文件的对应功能开启,可以参考以下这个配置

1
2
3
4
5
6
7
8
9
10
11
12
13
#Start in daemon (background) mode and release terminal (default: off)
daemon on
# The mini-http server listens to this port for requests (default: 0 = disabled)
stream_port 8081
# Restrict stream connections to localhost only (default: on)
stream_localhost off
# TCP/IP port for the http server to listen on (default: 0 = disabled)
webcontrol_port 8080
# Restrict control connections to localhost only (default: on)
webcontrol_localhost off
# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 100

4、打开motion

1、手动开启

1
sudo motion

2、开机自启动

1
2
sudo nano /etc/rc.local
# exit 0前添加 motion , 保存,就会开机自动运行了。

5、在网页或者手机上查看

保持在同一局域网、同一网段,访问http://树莓派IP:8080

image-20231024143726104

6、如果视频出现卡顿解决办法

打开/etc/motion/motion.conf这个配置文件

1
2
stream_maxrate 100    # 可能你的配置文件中没有这个,自己加进去
framerate 100 # 改变他的帧数

2、使用MJPG-Streamer(方法二)

1、安装MJPG-Streamer

1、下载MJPG和git

1
2
3
4
5
6
sudo apt-get install cmake libjpeg8-dev

sudo apt-get install git

sudo git clone https://github.com/jacksonliam/mjpg-streamer.git

2、编译

1
2
3
cd mjpg-streamer/mjpg-streamer-experimental
sudo make all
sudo make install

2、开启服务

1、raspbian系统

1
2
3
4
5
6
7
# 方法一
sudo mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so -x 1920 -y 1080 -fps 30 -ex night -rot 180 -p 8080"
# -p指定端口 -fps 帧率 -rot 旋转 -x/y 分辨率

# 方法二
sudo mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so -x 1920 -y 1080 -fps 30 -ex night -rot 180 -p 8080" &
# 后台运行 返回pid

2、ubuntu系统

1
2
cd mjpg-streamer/mjpg-streamer-experimental
sudo ./start.sh # 简单粗暴 默认分辨率640*480

3、本地的服务器显示画面

访问 http://树莓派IP:8080

image-20231024134755624

3、用vnc本地打开摄像头

1、luvcview

1
2
sudo apt-get install luvcview     #安装luvcview
luvcview -s 1080x720 #以1080*720表示采集的分辨率

2、我用上面那个会报错

image-20231029203640582

解决方法:

原因:这款软件不是在任意版本的操作系统下都适用的,要查看自己Ubuntu版本支持的uvcview。

输入命令:

1
sudo apt-cache search uvcview

image-20231029203726449

上面显示我们要用guvcview,所以安装这个东西

1
sudo apt-get install guvcview

然后打开

1
guvcview -d /dev/video0/

image-20231029203910826

选择自己的设备

image-20231029203940507