基于linux-2.6.35的网络视频服务器移植

2019-07-13 02:20发布

作者:曹忠明,华清远见嵌入式学院讲师。 一、环境 主机环境 :ubuntu 10.10
        目标机 :FS2410(S3C2410)
        主机工具链 :gcc-4.4.5
        交叉工具链 :arm-none-linux-gnueabi-gcc-4.3.2
        摄像头 :ZC301 二、移植过程 1、配置内核是内核支持芯片为ZC301的摄像头
        Make menuconfig
                Device Drivers ---> 
                        <*> Multimedia support --->
                                <*> Video For Linux 
                                [*] Enable Video For Linux API 1 (DEPRECATED) (NEW)
                                [*] Video capture adapters (NEW) --->
                                        [*] V4L USB devices (NEW) ---> 
                                                <*> USB Video Class (UVC) 
                                                [*] UVC input events device support (NEW)
                                        <*> USB ZC0301[P] webcam support (DEPRECATED) 2、重新编译内核 make zImage 通过上面两个步骤就可以驱动我们的摄像头了。但是这个驱动是基于V4l2的。以前基于 V4L的一些上层应用就不能用了,或需要做大量的修改!这里我们要实现网络视频的功能,以前都是用servfox这个网络视频服务器,但是这个服务器就是 基于V4L的,我们如果想用的话就得对servfox的源码进行修改。这里我们选用另外一种方案mjpg-stream。 3、mjpg-stream的移植 关于mjpg-stream的资料大家可以在下面这个网址查看:http://sourceforge.net/apps/mediawiki/mjpg-streamer/index.php?title=Main_Page 
        mjpg-stream的移植需要jpeg的库,所以我们先移植jpeg的库 (1)jpeg库的移植         1)jpeg源码包通过下面这个网址下载
                http://www.ijg.org/files/jpegsrc.v8b.tar.gz
                2)解压源码包
                tar xvf jpegsrc.v8b.tar.gz
                3)配置源码
                cd jpeg-8b
                ./configure --prefix=/home/linux/s3c2410-2.6.35/video/jpeg --host=arm-none-linux-gnueabi
                4)编译
                make
                5)安装
                make install
                6)拷贝库到文件系统中
                cp //home/linux/s3c2410-2.6.35/video/jpeg /lib/libjpeg.so.8 /source/rootfs/lib (2)mjpg-stream的移植         1)mjpg-stream源码包通过下面这个网址下载
                http://sourceforge.net/projects/mjpg-streamer/ 
                2)解压源码
                tar xvf mjpg-streamer-r63.tar.gz
                3)修改源码
                cd mjpg-streamer-r63
                修改顶层makefile及plugins目录中的各级makefile将所有
                CC=gcc
                修改为
                CC=arm-none-linux-gnueabi-gcc【arm-linux-gcc】         修改plugins/input_uvc/Makfile
                修改
                CFLAGS += -O2 -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC
                为
                CFLAGS += -O2 -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -I/home/linux/s3c2410-2.6.35/video/jpeg/include
                修改
                $(CC) $(CFLAGS) -ljpeg -o $@ input_uvc.c v4l2uvc.lo jpeg_utils.lo dynctrl.lo
                为
                $(CC) $(CFLAGS) -ljpeg -L/home/linux/s3c2410-2.6.35/video/jpeg/lib -o $@ input_uvc.c v4l2uvc.lo jpeg_utils.lo dynctrl.lo          jpeg_utils.c:27: fatal error: jpeglib.h: No such file or directory
                4)编译
                make
                5)测试
                mkdir /source/rootfs/mjpg
                cp *.so /source/rootfs/mjpg
                cp mjpg-stream /source/rootfs/bin 把*.so  www文件夹 可执行文件mjpg_streamer  start.sh复制到一个新建目录mjpg,然后把mjpg复制到开发板
mkdir ./mjpg                  
cp *.so start.sh ./mjpg cp -r www ./mjpg
        打开开开发板运行
                mjpg_streamer -i "/mjpg/input_uvc.so" -o "/mjpg/output_http.so -w /www"
                在源码目录下有start.sh,这个脚本里有一些mjpg-stream的使用方法及说明         打开一个网页输入下面地址就能够看到一个视频(开发板的IP为192.168.1.202):
                http://192.168.1.202:8080/?action=stream 
                打开一个网页输入下面地址就能够看到一个静态图片:
                http://192.168.1.202:8080/?action=snapshot 
                6)在mjpg源码下有一个www的目录,这个一个网络使用mjpg的实例,结合web服务器(boa)可以实现一些其他相关功能。

*************************************************************************************************************************************************************************************************************************
*************************************************************************************************************************************************************************************************************************
过程记录:
下载的 mjpg-streamer-r63.tar.gz
编译完成
执行命令 mjpg_streamer 出现下面错误
MJPG-streamer [525]: starting application                                                  
MJPG Streamer Version.: 2.0                                                                
MJPG-streamer [525]: MJPG Streamer Version.: 2.0                                           
                                                                                           
ERROR: could not find input plugin                                                         
MJPG-streamer [525]: ERROR: could not find input plugin                                    
                                                                                           
       Perhaps you want to adjust the search path with:                                    
MJPG-streamer [525]:        Perhaps you want to adjust the search path with:               
                                                                                           
       # export LD_LIBRARY_PATH=/path/to/plugin/folder                                     
MJPG-streamer [525]:        # export LD_LIBRARY_PATH=/path/to/plugin/folder                
                                                                                           
       dlopen: input_uvc.so: cannot open shared object file: No such file or directory     
MJPG-streamer [525]:        dlopen: input_uvc.so: cannot open shared object file: No such。。。
原因及解决办法
这是找不到共享造成的。Linux和windows不一样,不会在可执行文件所在的目录搜索 共享库文件。解决办法:敲入如下命令:export LD_LIBRARY_PATH=/mjpg-streamer-r63:$LD_LIBRARY_PATH (我的共享库.so文件时放在/mjpg-streamer-r63目录里),设定共享库的搜索路径就可以了!
 
执行命令
./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so -y -d /dev/video0"
执行成功

输入网址
http://192.168.1.6:8080/?action=index.html

注意 命令参考start.sh,如
mkdir pics
./mjpg_streamer -o "output_http.so -w `pwd`/www" -o "output_file.so -f pics -d 15000"
每隔15秒存储一张图片。

#该命令由于程序默认是MJPG的,故只有MJPG摄像头有用,对输出yuyv格式的摄像头无效
./mjpg_streamer -o "output_http.so -w ./www"

#该命令参数-y指定yuyv摄像头,enable YUYV format and disable MJPEG mode
#./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so -y -d /dev/video0"

-----------------------------------------------------------------------         
-----------------------------------------------------------------------         
命令
./mjpg_streamer --help  

Usage: ./mjpg_streamer                                                          
  -i | --input " [parameters]"                                 
  -o | --output " [parameters]"                               
 [-h | --help ]........: display this help                                      
 [-v | --version ].....: display version information                            
 [-b | --background]...: fork to the background, daemon mode                    
-----------------------------------------------------------------------         
Example #1:                                                                     
 To open an UVC webcam "/dev/video1" and stream it via HTTP:                    
  ./mjpg_streamer -i "input_uvc.so -d /dev/video1" -o "output_http.so"          
-----------------------------------------------------------------------         
Example #2:                                                                     
 To open an UVC webcam and stream via HTTP port 8090:                           
  ./mjpg_streamer -i "input_uvc.so" -o "output_http.so -p 8090"                 
-----------------------------------------------------------------------         
Example #3:                                                                     
 To get help for a certain input plugin:                                        
  ./mjpg_streamer -i "input_uvc.so --help"                                      
-----------------------------------------------------------------------         
In case the modules (=plugins) can not be found:                                
 * Set the default search path for the modules with:                            
   export LD_LIBRARY_PATH=/path/to/plugins,                                     
 * or put the plugins into the "/lib/" or "/usr/lib" folder,                    
 * or instead of just providing the plugin file name, use a complete            
   path and filename:                                                           
   ./mjpg_streamer -i "/path/to/modules/input_uvc.so"                           
-----------------------------------------------------------------------         
-----------------------------------------------------------------------     
命令    
./mjpg_streamer -i "input_uvc.so --help"    
MJPG-streamer [1177]: starting application                                      
MJPG Streamer Version.: 2.0                                                     
MJPG-streamer [1177]: MJPG Streamer Version.: 2.0                               
                                                                                
 ---------------------------------------------------------------                
 Help for input plugin..: UVC webcam grabber                                    
 ---------------------------------------------------------------                
 The following parameters can be passed to this plugin:                         
                                                                                
 [-d | --device ].......: video device to open (your camera)                    
 [-r | --resolution ]...: the resolution of the video device,                   
                          can be one of the following strings:                  
                          QSIF QCIF CGA QVGA CIF VGA                            
                          SVGA XGA SXGA                                         
                          or a custom value like the following                  
                          example: 640x480                                      
 [-f | --fps ]..........: frames per second                                     
 [-y | --yuv ]..........: enable YUYV format and disable MJPEG mode             
 [-q | --quality ]......: JPEG compression quality in percent                   
                          (activates YUYV format, disables MJPEG)               
 [-m | --minimum_size ].: drop frames smaller then this limit, useful           
                          if the webcam produces small-sized garbage frames     
                          may happen under low light conditions                 
 [-n | --no_dynctrl ]...: do not initalize dynctrls of Linux-UVC driver         
 [-l | --led ]..........: switch the LED "on", "off", let it "blink" or leave   
                          it up to the driver using the value "auto"            
 ---------------------------------------------------------------