1. 模块
RPi Camera(H)
2. 配置摄像头
sudo raspi-config
-> Interfacing Options
-> Camera
3.拍照和摄像
raspistill -o image.jpg raspivid -o video.h264 -t 10000# -t 10000表示录制10秒
4. MJPG-streamer安装
4.1安装必要的库
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
4.2 git开源的project到本地,编译
sudo git clone https://github.com/jacksonliam/mjpg-streamer.git cd mjpg-streamer/mjpg-streamer-experimental sudo make all sudo make install
4.3 测试
#Picamera ./mjpg_streamer -i "./input_raspicam.so" -o "./output_http.so -w ./www" #usb摄像头 ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
http://192.168.1.188:8080
5.阿里云服务器
阿里云:https://promotion.aliyun.com/ntms/act/campus2018.html
系统镜像:Ubuntu
6.阿里云安装Apache2
sudo apt-get update sudo apt-get upgrade #安装Apache2 sudo apt-get install apache2 #启动Apache2 sudo /etc/init.d/apache2 start #加载模块 sudo a2enmod proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http #编辑proxy配置文件 sudo vim /etc/apache2/mods-enabled/proxy.conf
1.开启10005端口 2.sudo /etc/init.d/apache2 restart #重新启动Apache2
7.将树莓派的私钥拷贝到公网服务器
# 1.生成ssh公钥私钥 pi@raspberrypi:~ $ ssh-keygen -t rsa # 2.将私钥拷贝到公网服务器,完成对树莓派的信任配置 pi@raspberrypi:~ $ ssh-copy-id -i ~/.ssh/id_rsa 服务器用户名@服务器ip
8.树莓派通过ssh反向隧道将mjpeg-streamer的8080端口代理到公网VPS
autossh -M 5678 -NfR 10005:localhost:8080 自己的阿里云服务器用户名@服务器IP
# 8.开启mjpeg-streamer服务
9.查看视频
http://你的服务器ip/proxy/?action=stream
10.制作脚本
10.1定时拍照
cd ~/project/ mkdir photo touch jk.sh sudo nano jk.sh
cd ~/mjpg-streamer/mjpg-streamer-experimental ./mjpg_streamer -i "./input_raspicam.so" -o "./output_http.so -w ./www" #-o "output_file.so -f /home/pi/project/photo -d 3000"#1s等于1000,2小时为7200000
10. 启动阿里云脚本
sh aliyun.sh
11. 启动mjpeg-streamer
nohup sh jk.sh &
12.总结
12.1 配置系统
1.制作登陆阿里云脚本 2.制作自动输入密码登录阿里云脚本 3.将自动登录阿里云脚本写入系统定时启动文件
12.2 开机设置
#1.sh aliyun.sh #2.nohup sh jk.sh & crontab -e @reboot sh /home/pi/project/aliyun.sh /home/ @reboot nohup sh /home/pi/project/jk.sh & /home/
参考资料
0.linux设置开机自启动脚本的最佳方式:
https://blog.csdn.net/qq_35440678/article/details/80489102
1.MJPG-streamer安装:
http://shumeipai.nxez.com/2017/05/14/raspberry-pi-mjpg-streamer-installation.html
2.阿里云服务器+树莓派+mjpeg-streamer实现外网视频监控:https://blog.csdn.net/little_bobo/article/details/78810137
3.自动输入密码:https://www.cnblogs.com/wangxusummer/p/4128661.html (主)
https://blog.csdn.net/u010735120/article/details/81624919
https://blog.csdn.net/zhangjikuan/article/details/51105166