OpenWrt中mjpg-streamer支持JPG格式和YUYV格式的摄像头。对于只支持YUYV格式的摄像头,运行mjpg-streamer的命令需要添加‘-y’(或‘--yuv')参数。
手上刚好两个摄像头,有一个支持JPG格式,另一个不支持。为了避免切换摄像头时更改mjpg-streamer启动脚本,对默认的启动脚本/etc/init.d/mjpg-streamer做了少许更改,以支持那两种摄像头,更改如下:
- #!/bin/sh /etc/rc.common
- # Copyright (C) 2009 OpenWrt.org
- # Modified by Yihui Xiong(xiongyihui3@gmail.com), Aug 27, 2012
- START=50
- NAME=mjpg_streamer
- PROG=/usr/bin/$NAME
- start() {
- config_load mjpg-streamer
- config_get device core device
- config_get resolution core resolution
- config_get fps core fps
- config_get port core port
- config_get www core www
- config_get_bool enabled core enabled
- if [ $enabled -eq 0 ]; then
- exit -1
- fi
- # wait for device's initialization
- # sleep 3
- if [ -e $device ]; then
- $PROG -i "input_uvc.so -d $device -n -f $fps -r $resolution" \
- -o "output_http.so -p $port -w $www" &
- else
- # not find device
- exit -2
- fi
- sleep 3
- # check if mjpeg streamer is running
- pgrep $NAME
- if [ $? -ne 0 ]; then
- # mjpeg streamer exited, perhaps the camera doesn't support JPG format
- # try to start mjpg streamer with YUYV format
- $PROG -i "input_uvc.so -d $device -n -y -f $fps -r $resolution" \
- -o "output_http.so -p $port -w $www" &
- fi
- }
- stop() {
- killall -9 $NAME
- }
复制代码 注:此脚本依赖于busybox中的pgrep
此脚本利用busybox中的pgrep检查mjpg-streamer第一次是否正常启动,如果参数错误,则第一次启动会失败,然后第二次启动mjpg-streamer。两次启动mjpg-streamer的差异在于,后一次启动时添加了参数‘-y’。
另外,附上配置文件,添加网页路径配置选项,/etc/config/mjpg-streamer内容如下:
- config mjpg-streamer core
- option device "/dev/video0"
- option resolution "640x480"
- option fps "12"
- option port "8080"
- option www "/www/camera"
- option enabled "true"
复制代码
|