文章目录
前言
在homeassistant中使用ffmpeg集成来使用usb摄像头一直是有问题的,只要你开启了stream基本上视频就出不来(默认配置default_config默认就开启了stream,如果非要用ffmpeg,就不用stream流,但是出来的效果也很差)在社区中采用的方法也是将usb转为web摄像头来使用;还有一种插件就是motioneye,这个插件可以解决usb摄像头的问题,但是这个插件的效果非常差,而且占用系统资源很大。因此这里采用的方法是使用MJPG-streamer来将usb摄像头数据转为web摄像头从而和homeassistant来完成联动,并且还可以设置验证身份访问,还是很安全的。
MJPG-streamer的安装
#/bin/bash
path=/home/pi/stream
stream_package=(subversion libjpeg-dev imagemagick libv4l-dev cmake git)
apt install ${stream_package[@]} -y
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
make all
make DESTDIR=${path} install
将此脚本以sudo运行,即可安装MJPG-streamer
usb摄像头
v4l2-ctl --list-devices
查看usb摄像头信息
web摄像头图像查看
然后·运行命令
./mjpg_streamer -i "../lib/mjpg-streamer/input_uvc.so -d /dev/video0 --resolution 1920x1080 " -o "../lib/mjpg-streamer/output_http.so -n -w /root/stream/www"
请注意库的位置根据你安装的位置改变
然后在局域网下打开浏览器输入
一定要是这种格式!!!
http://raspberry-ip-address:8080/?action=stream
即可查看到图像
mjpg_stream help
参数解释
输入
-n
表示不初始化Linux-uvc驱动程序的dynctrl
-y
表示使用YUV格式,默认:MJPEG(使用更多的cpu功率)
-f
表示帧率
-r
表示分辨率(可以为QQVGA QCIF CGA QVGA CIF PAL VGA SVGA XGA HD SXGA UXGA FHD 或者 如这种形式: 640x480)
-timestamp
用系统时间填充帧时间戳
-rot
设置图像旋转(0-359)
-hf
设置水平翻转(ture/false)
-vf
设置垂直翻转(ture/false)
输出
-n
禁止执行命令
-w
包含网页的文件夹平面层次结构(没有子文件夹)
-c
要求输入用户名和密码,调用方式如下
./mjpg_streamer -i "../lib/mjpg-streamer/input_uvc.so -d /dev/video1 -n -y -f 25 -r 640x480" -o "../lib/mjpg-streamer/output_http.so -n -c "wp:1152679377" -w /home/wp/www"
注意相应的在homeassistant配置文件中加上
-p
端口设置
-l
设置监听的ip
homeassistant使用
MJPEG IP Camera集成
根据此集成,只需要在configuration.yaml中添加即可
# Example configuration.yaml entry
camera:
- platform: mjpeg
mjpeg_url: http://192.168.1.92/mjpeg
其他
ffmpeg使用usb摄像头
注意不要用默认配置
homeassistant学习链接
链接
目前写的还很乱,后面会整理
树莓派(docker)nginx-rtmp-raspi
首先安装docker
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
github链接
nginx-rtmp构建webcam超详细链接
然后下载dockerfile脚本
git clone https://github.com/idlerun/nginx-rtmp-raspi
然后将Dockerfile替换掉
ARG baseimg=raspbian/stretch
FROM $baseimg as build
ENV DEBIAN_FRONTEND=noninteractive
ENV SRC_DIR=/src
RUN mkdir -p $SRC_DIR
RUN apt-get update
RUN apt-get install -y \
wget git libtool autoconf cmake \
build-essential pkg-config
WORKDIR $SRC_DIR
RUN wget -q http://zlib.net/zlib-1.2.11.tar.gz
RUN tar -zxf zlib-1.2.11.tar.gz
RUN wget https://www.openssl.org/source/openssl-1.1.1.tar.gz --no-check-certificate
RUN tar xf openssl-1.1.1.tar.gz
RUN wget -q https://nginx.org/download/nginx-1.15.6.tar.gz
RUN tar xf nginx-1.15.6.tar.gz
RUN wget -q https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz
RUN tar xf v1.2.1.tar.gz
RUN wget https://sourceforge.net/projects/pcre/files/pcre/8.42/pcre-8.42.tar.gz/download --no-check-certificate -O pcre-8.42.tar.gz
RUN tar -zxf pcre-8.42.tar.gz
WORKDIR /src/nginx-1.15.6
RUN mkdir -p /build /conf
RUN ./configure --prefix=/build \
--with-zlib=/src/zlib-1.2.11 \
--with-openssl=/src/openssl-1.1.1 \
--with-pcre=/src/pcre-8.42 \
--sbin-path=/usr/local/bin/nginx \
--conf-path=/conf/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx-error.log \
--http-log-path=/var/log/nginx-access.log \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--without-http_fastcgi_module \
--without-http_uwsgi_module \
--without-http_scgi_module \
--without-http_memcached_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-threads \
--add-module=../nginx-rtmp-module-1.2.1
RUN make -j4
RUN make install
FROM $baseimg
COPY --from=build /usr/local/bin/nginx /usr/local/bin/
COPY --from=build /build /build
COPY nginx.conf /conf/
RUN mkdir -p /web/www /web/hls
COPY index.html /web/www/
ENTRYPOINT nginx
替换后在文件夹nginx-rtmp-raspi
中
sudo bash build.sh
其中使用方法在stream.conf
中有
ffmpeg -re -f video4linux2 -i /dev/video0 -framerate 25 -vcodec h264_omx -map 0:v -b:v 800k -vprofile baseline -vf "scale=640:360" -f flv rtmp://localhost/show/stream
在浏览器中使用ip:8080
访问
问题
解决wget报错ERROR: The certificate of ‘xxxxx’ is not trusted
在wget指令后添加–no-check-certificate