在openwrt上安装webcam

本文介绍如何在OpenWRT系统下配置并使用USB摄像头,包括安装必要的驱动及mjpg-streamer软件,并解决了启动过程中的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在openwrt上安装webcam

访问html格式文档在 这里
文档源码在 这里

硬件环境

  1. 摄像头淘宝买的杂牌 lsusb结果
    Bus 001 Device 005: ID 0c45:6340 Microdia
  1. 路由器
  • 路由型号 NETGEAR WNDR3700v2
  • 固件版本 OpenWrt Backfire 10.03.1 / LuCI 0.10.0 Release (0.10.0)
  • 内核版本 2.6.32.27

参考文档

开工

根据硬件信息查参考1

SN9C* open source Microdia drivers under development

我猜想次摄像头kernel驱动应该叫SN9CXX 再查参考2

kmod-video-sn9c102	Kernel modules for supporting SN9C102 camera chips.

猜想可能是这个驱动,开工安装

opkg update
opkg install kmod-video-sn9c102 mjpg-streamer

按照参考三,直接启动mjpg-stearmer,然后报错

/etc/init.d/mjpg-streamer start
MJPG Streamer Version: svn rev: exported
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 5
 i: Format............: MJPEG
Unable to set format: 1196444237 res: 640x480
 Init v4L2 failed !! exit fatal 
 i: init_VideoIn failed

找到参考4,发现以下命令可以让摄像头正常工作

mjpg_streamer -i "input_uvc.so -y -d /dev/video0 -r VGA -l on" -o "output_http.so -p 8080 -w /tmp/webcam"
MJPG Streamer Version: svn rev: exported
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 5
 i: Format............: YUV
 i: JPEG Quality......: 80
Adding control for Pan (relative)
Adding control for Tilt (relative)
Adding control for Pan Reset
Adding control for Tilt Reset
Adding control for Pan/tilt Reset
Adding control for Focus (absolute)
mapping control for Pan (relative)
mapping control for Tilt (relative)
mapping control for Pan Reset
mapping control for Tilt Reset
mapping control for Pan/tilt Reset
mapping control for Focus (absolute)
mapping control for LED1 Mode
mapping control for LED1 Frequency
mapping control for Disable video processing
mapping control for Raw bits per pixel
 o: www-folder-path...: /tmp/webcam/
 o: HTTP TCP port.....: 8080
 o: username:password.: disabled
 o: commands..........: enabled
^Csetting signal to stop
setting signal to stop
setting signal to stop
setting signal to stop
force cancellation of threads and cleanup resources
 o: cleaning up ressources allocated by server thread #00
force cancellation of threads and cleanup resources
 i: cleaning up ressources allocated by input thread
done

访问浏览器http://192.168.3.1:8080/?action=stream 一切正常

接着分析,如果命令行能够执行成功,并且有画面说明只要让启动脚本按照能够正常执行的命令方式运行就可以了 接着看/etc/init.d/mjpg-streamer,第十七行出现了问题

[ $enabled -gt 0 -a -c $device ] && sleep 3 && $SSD -S -m -p $PIDF -q -x $PROG -- --input "input_uvc.so --device ....

修改成下面的

[ $enabled -gt 0 -a -c $device ] && sleep 3 && $SSD -S -m -p $PIDF -q -x $PROG -- --input "input_uvc.so -y --device

再执行启动脚本就没问题了

记得要打开自启动

/etc/init.d/mjpg-streamer enable

录像

待续

### 将USB摄像头配置为IP摄像头的方法 #### 方法一:使用Android设备和专用应用 可以通过将USB摄像头连接到支持USB-OTG功能的Android设备上,再安装特定的应用程序来实现这一目标。例如,《USB摄像头》这款应用程序允许用户通过USB接口连接外部摄像头,并将其作为IP摄像头运行[^1]。该应用还提供RTSP和HTTP服务器的功能,从而使得其他设备能够通过网络访问视频流。 #### 方法二:基于Linux系统的解决方案 对于拥有一定技术背景的用户来说,在嵌入式Linux平台上(如OpenWRT路由器)部署WebCam服务是一种可行的选择。具体操作包括确保系统已加载最新版本的UVC驱动程序[^3],以及按照需求调整内核模块中的`uvc_ids[]`数组以兼容更多类型的USB摄像机。之后可借助FFmpeg或其他类似的工具创建一个简易的HTTP直播服务器[^2]。 #### 方法三:采用开源项目cam2web 另一个高效的方式是利用名为cam2web的开源项目。此项目的初衷正是为了简化把标准USB相机转化为具备互联网接入能力的过程[^4]。它不仅限于物理外接装置,同样适用于集成式的笔记本电脑前摄单元。一旦完成初始化设定后,任何联网终端都能经由指定URL地址接收到来自这些源产生的连续画面更新。 #### 方法四:编程方式获取并推送视频流 如果倾向于手动控制整个流程,则可以考虑运用Python配合OpenCV库读取来自本地连接端口的数据包,并进一步编码处理成为适合网络传播的形式[^5]。下面给出一段简单示例代码展示如何启动这样一个基本框架: ```python import cv2 from http.server import BaseHTTPRequestHandler, HTTPServer import threading class CamHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'multipart/x-mixed-replace; boundary=--jpgboundary') self.end_headers() cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() if not ret: break _, img_encoded = cv2.imencode('.jpg', frame) content = b'--jpgboundary\r\n' + \ b'Content-Type: image/jpeg\r\n' + \ f'Content-Length: {len(img_encoded)}\r\n'.encode() + \ b'\r\n' + img_encoded.tobytes() + b'\r\n' try: self.wfile.write(content) except Exception as e: print(e) break def start_server(): server_address = ('', 8080) httpd = HTTPServer(server_address, CamHandler) print("Starting server on port 8080...") httpd.serve_forever() threading.Thread(target=start_server).start() ``` 以上脚本会开启一个监听在8080端口上的小型HTTP服务器,客户端只需指向http://<your-ip>:8080即可观看实时影像。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值