Raspberry Pi的Mjpg-streamer配置

系统配置为RPi3+罗技C310
首先使用

$ v4l2-ctl --list-formats
$ v4l2-ctl --list-formats-ext

检查摄像头支持的格式。
一般摄像头会有两种视频模式:YUV和MJPEG。
YUV会占用大量系统资源(树莓派3上大概跑到640*480@30fps就是极限了,几乎耗尽系统资源),mjpeg占用资源率在10%左右。
直接从sourceforge上拖下来的版本不带-y参数不能工作(-y:YUV选项,不加这个参数的话默认是取摄像头buffer的mjpeg),需要打补丁编译。

准备工作

$ sudo apt-get install libv4l-dev libjpeg8-dev subversion imagemagick v4l-utils

libv4l-dev和v4l-utils一般已经装过了
然后是从sourceforge上下载源码

$ svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer
$ cd mjpg-streamer-code/mjpg-streamer

然后打上树莓派论坛上的补丁
具体方法为创建一个名为input_uvc_patch的文件,内容为

--- plugins/input_uvc/input_uvc.c       (revision 174)
+++ plugins/input_uvc/input_uvc.c       (working copy)
@@ -405,9 +405,13 @@
         if(pcontext->videoIn->formatIn == V4L2_PIX_FMT_YUYV) {
             DBG("compressing frame from input: %d\n", (int)pcontext->id);
             pglobal->in[pcontext->id].size = compress_yuyv_to_jpeg(pcontext->videoIn, pglobal->in[pcontext->id].buf, pcontext->videoIn->framesizeIn, gquality);
+            /* copy this frame's timestamp to user space */
+            pglobal->in[pcontext->id].timestamp = pcontext->videoIn->buf.timestamp;
         } else {
             DBG("copying frame from input: %d\n", (int)pcontext->id);
-            pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->buf.bytesused);
+            pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->tmpbytesused);
+            /* copy this frame's timestamp to user space */
+            pglobal->in[pcontext->id].timestamp = pcontext->videoIn->tmptimestamp;
         }

 #if 0
@@ -418,8 +422,6 @@
         prev_size = global->size;
 #endif

-        /* copy this frame's timestamp to user space */
-        pglobal->in[pcontext->id].timestamp = pcontext->videoIn->buf.timestamp;

         /* signal fresh_frame */
         pthread_cond_broadcast(&pglobal->in[pcontext->id].db_update);
Index: plugins/input_uvc/v4l2uvc.c
===================================================================
--- plugins/input_uvc/v4l2uvc.c (revision 174)
+++ plugins/input_uvc/v4l2uvc.c (working copy)
@@ -450,6 +450,8 @@
         */

         memcpy(vd->tmpbuffer, vd->mem[vd->buf.index], vd->buf.bytesused);
+        vd->tmpbytesused = vd->buf.bytesused;
+        vd->tmptimestamp = vd->buf.timestamp;

         if(debug)
             fprintf(stderr, "bytes in used %d \n", vd->buf.bytesused);
Index: plugins/input_uvc/v4l2uvc.h
===================================================================
--- plugins/input_uvc/v4l2uvc.h (revision 174)
+++ plugins/input_uvc/v4l2uvc.h (working copy)
@@ -28,6 +28,7 @@


 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,8 @@
     int framecount;
     int recordstart;
     int recordtime;
+    uint32_t tmpbytesused;
+    struct timeval tmptimestamp;
 };

 /* context of each camera thread */

然后进行编译

$ patch -p0 < input_uvc_patch
$ make USE_LIBV4L2=true clean all
$ sudo make DESTDIR=/usr/local install

测试YUV模式

$./mjpg_streamer -i "./input_uvc.so -y -f 30 -r 640x480" -o "./output_http.so -w ./www"

测试mjpeg模式

./mjpg_streamer -i "./input_uvc.so -f 30 -r 1280x720" -o "./output_http.so -w ./www"

在电脑的浏览器中输入树莓派的http://树莓派ip:8080访问摄像头数据

你可能感兴趣的:(环境配置,RPi)