加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入
  • 正文
    • 0、环境
    • 1. v4l2-utils工具包
    • 2. media-ctl
    • 4. 显示图片
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

Camera | 3.瑞芯微平台MIPI摄像头常用调试命令

09/24 10:45
3.2万
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

Camera | 1.Camera基础知识

Camera | 2.MIPI、CSI基础

前面2篇我们讲解了camera的一些基础概念和知识。

本文主要讲述在瑞芯微平台上摄像头开发常用的调试命令。

0、环境

soc  : rk3568   
board: EVB1-DDR4-V10
软  件:Android 11
Linux:4.19.232
Camera:ov13850

1. v4l2-utils工具包

v4l-utils工具是由Linux维护的V4L2开发工具包。

它提供了一套用于配置V4L2子设备属性的V4L2和媒体框架相关工具,测试V4L2设备,并提供开发库,如libv4l2等等。

v4l-utils工具包主要包含两个常用工具,分别是media-ctl、v4l2-ctl

瑞芯微的SDK在Buildroot固件中,已经编译好了v4l2-utils软件包里面的工具(Android通常默认支持)。

ubuntu系统安装方法:

peng@ubuntu:~$ sudo apt install v4l-utils

2. media-ctl

media-ctl是v4l2-utils包中的一个工具,主要用来查看、配置Media Framework的各Entity的信息,如格式、裁剪、链接使能等。

V4l2-ctl 工具则是针对/dev/video0,/dev/video1 等 video设备,它在 video 设备上进行 set_fmt,reqbuf(申请buf),qbuf(送buf回队列),dqbuf(从队列取出buf),stream_on,stream_off 等一系列操作。

 n为4的倍数(0,1,2,3…)
 /dev/videon+0:视频输出 SP主通道
 /dev/videon+1:视频输出 MP自身通道
 /dev/videon+2:3A统计
 /dev/videon+3:3A参数设置

1)找到video设备

拓扑结构中有多个的Entity,一些是sub device,一些是video device。前者对应的设备节点是/dev/v4l-subdev,后者对应的是/dev/video。多个的video device中,最常关注的是哪个设备可以输出图像。

$ media-ctl -d /dev/media0 -e "rkisp_selfpath"
/dev/video1
$ media-ctl -d /dev/media0 -e "rkisp_mainpath"
/dev/video0

上面两个命令分别显示出/dev/media0这个链路中,RKISP的SP及MP节点的设备路径。RKISP有两个视频输出设备,它们都能输出图像。

2)显示拓扑结构

使用以下命令可以显示拓扑结构:

$ media-ctl -p -d /dev/media0

主要关注的是有没有找到Sensor的Entity。如果没有找到Sensor的Entity,说明Sensor注册有问题,请按FAQ文档排查。

例如,开发板上接上ov13850摄像头后可以看到如下的输出:

rk3568_r:/ # media-ctl -d /dev/media0 -p               
media-ctl -d /dev/media0 -p                            
Opening media device /dev/media0                       
Enumerating entities                                   
Found 13 entities                                      
Enumerating pads and links                             
Media controller API version 0.0.255                   
                                                       
Media device information                               
------------------------                               
driver          rkisp-vir0                             
model           rkisp0                                 
serial                                                 
bus info                                               
hw revision     0x0                                    
driver version  0.0.255                                
                                                       
Device topology                                        
- entity 1: rkisp-isp-subdev (4 pads, 7 links)         
            type V4L2 subdev subtype Unknown           
            device node name /dev/v4l-subdev0          
        pad0: Sink                                     
                [fmt:SBGGR10/2112x1568                 
                 crop.bounds:(0,0)/2112x1568           
                 crop:(0,0)/2112x1568]                 
                <- "rkisp-csi-subdev":1 [ENABLED]      
                <- "rkisp_rawrd0_m":0 []               
                <- "rkisp_rawrd2_s":0 []               
        pad1: Sink                                     
                <- "rkisp-input-params":0 [ENABLED]    
        pad2: Source                                   
                [fmt:YUYV2X8/2112x1568                 
                 crop.bounds:(0,0)/2112x1568           
                 crop:(0,0)/2112x1568]                 
                -> "rkisp_mainpath":0 [ENABLED]        
                -> "rkisp_selfpath":0 [ENABLED]        
        pad3: Source                                   
                -> "rkisp-statistics":0 [ENABLED]      
                                                       
- entity 6: rkisp-csi-subdev (6 pads, 5 links)         
            type V4L2 subdev subtype Unknown           
            device node name /dev/v4l-subdev1          
        pad0: Sink                                     
                [fmt:SBGGR10/4224x3136]                
                <- "rockchip-csi2-dphy0":1 [ENABLED]   
        pad1: Source                                   
                [fmt:SBGGR10/4224x3136]                
                -> "rkisp-isp-subdev":0 [ENABLED]      
        pad2: Source                                   
                [fmt:SBGGR10/4224x3136]                
                -> "rkisp_rawwr0":0 [ENABLED]          
        pad3: Source                                   
                [fmt:SBGGR10/4224x3136]                
        pad4: Source                                   
                [fmt:SBGGR10/4224x3136]                
                -> "rkisp_rawwr2":0 [ENABLED]          
        pad5: Source                                   
                [fmt:SBGGR10/4224x3136]                
                -> "rkisp_rawwr3":0 [ENABLED]          
                                                       
- entity 13: rkisp_mainpath (1 pad, 1 link)            
             type Node subtype V4L                     
             device node name /dev/video0              
        pad0: Sink                                     
                <- "rkisp-isp-subdev":2 [ENABLED]      
                                                       
- entity 19: rkisp_selfpath (1 pad, 1 link)            
             type Node subtype V4L                     
             device node name /dev/video1              
        pad0: Sink                                     
                <- "rkisp-isp-subdev":2 [ENABLED]      
                                                       
- entity 25: rkisp_rawwr0 (1 pad, 1 link)              
             type Node subtype V4L                     
             device node name /dev/video2              
        pad0: Sink                                     
                <- "rkisp-csi-subdev":2 [ENABLED]      
                                                       
- entity 31: rkisp_rawwr2 (1 pad, 1 link)              
             type Node subtype V4L                     
             device node name /dev/video3              
        pad0: Sink                                     
                <- "rkisp-csi-subdev":4 [ENABLED]      
                                                       
- entity 37: rkisp_rawwr3 (1 pad, 1 link)              
             type Node subtype V4L                     
             device node name /dev/video4              
        pad0: Sink                                     
                <- "rkisp-csi-subdev":5 [ENABLED]      
                                                       
- entity 43: rkisp_rawrd0_m (1 pad, 1 link)            
             type Node subtype V4L                     
             device node name /dev/video5              
        pad0: Source                                   
                -> "rkisp-isp-subdev":0 []             
                                                       
- entity 49: rkisp_rawrd2_s (1 pad, 1 link)            
             type Node subtype V4L                     
             device node name /dev/video6              
        pad0: Source                                   
                -> "rkisp-isp-subdev":0 []             
                                                       
- entity 55: rkisp-statistics (1 pad, 1 link)          
             type Node subtype V4L                     
             device node name /dev/video7              
        pad0: Sink                                     
                <- "rkisp-isp-subdev":3 [ENABLED]      
                                                       
- entity 61: rkisp-input-params (1 pad, 1 link)        
             type Node subtype V4L                     
             device node name /dev/video8              
        pad0: Source                                   
                -> "rkisp-isp-subdev":1 [ENABLED]      
                                                       
- entity 67: rockchip-csi2-dphy0 (2 pads, 2 links)     
             type V4L2 subdev subtype Unknown          
             device node name /dev/v4l-subdev2         
        pad0: Sink                                     
                [fmt:SBGGR10/4224x3136]                
                <- "m00_b_ov13850 4-0010":0 [ENABLED]  
        pad1: Source                                   
                [fmt:SBGGR10/4224x3136]                
                -> "rkisp-csi-subdev":0 [ENABLED]      
                                                       
- entity 70: m00_b_ov13850 4-0010 (1 pad, 1 link)      
             type V4L2 subdev subtype Sensor           
             device node name /dev/v4l-subdev3         
        pad0: Source                                   
                [fmt:SBGGR10/4224x3136]                
                -> "rockchip-csi2-dphy0":0 [ENABLED]   

从entity70信息中可以看到:

    该Entity完整的名称是:m00_b_ov13850 4-0010它是一个V4L2 subdev(Sub-Device) Sensor它对应的节点是/dev/v4l-subdev3,应用程序(如v4l2-ctl)可以打开它,并进行配置它仅有一个输出(Source)节点,记为pad0它的输出格式是[fmt:SBGGR10/4224x3136],其中SBGGR10是一种mbus-code的简称它的Source pad0 链接到"rockchip-csi2-dphy0"的pad0,并且当前的状态是 ENABLED。

拓扑结构图如下:【后面文章会详细讲解该结构图,请收藏本系列文章】

3)修改Entity的format、size

举例一,ov3850摄像头支持多个分辨率的输出,默认为1920x1080。现将输出分辨率改为640x480:

media-ctl -d/dev/media0
--set-v4l2' "m00_b_ov13850 4-0010":0[fmt:SBGGR10/640x480]'

修改ov3850输出后,rkisp-isp-subdev的大小及video device crop也相应要修改。因为后级的大小不能大于前级的大小。

~/>$ media-ctl -d/dev/media0 --set-v4l2 ' "rkisp-isp-subdev":0[fmt:SBGGR10/640x480]'
~/>$ media-ctl -d/dev/media0 --set-v4l2 ' "rkisp-isp-subdev":0[crop: (0, 0)/640x480]'
~/>$ media-ctl -d/dev/media0 --set-v4l2 ' "rkisp-isp-subdev":2[crop: (0, 0)/640x480]'
~/>$ v4l2-ctl -d/dev/video0
--set-selection=target=crop, top=0, left=0, width=640, height=480

3. v4l2-ctl

v4l2-ctl的帮助信息查看:

[root@RK356X:~]# v4l2-ctl -h
General/Common options:
--all           display all information available
-C, --get-ctrl <ctrl>[,<ctrl>...]
get the value of the controls [VIDIOC_G_EXT_CTRLS]
-c, --set-ctrl <ctrl>=<val>[,<ctrl>=<val>...]
set the value of the controls [VIDIOC_S_EXT_CTRLS]
-D, --info        show driver info [VIDIOC_QUERYCAP]
-d, --device <dev> use device <dev> instead of/dev/video0
if <dev> starts with a digit, then /dev/video<dev> is used
-e, --out-device <dev> use device <dev> for output streams instead of the default device as set with --device
if <dev> starts with a digit, then /dev/video<dev> is used
-h, --help display this help message
…………

也可以进入以下网站:

https://www.mankier.com/1/v4l2-ctl

1)列出所有设备

命令:

v4l2-ctl --list-devices

执行结果:

rk3568_r:/ # v4l2-ctl --list-devices
v4l2-ctl --list-devices
rkisp-statistics (platform: rkisp):
        /dev/video7
        /dev/video8

rkisp_mainpath (platform:rkisp-vir0):
        /dev/video0
        /dev/video1
        /dev/video2
        /dev/video3
        /dev/video4
        /dev/video5
        /dev/video6

2)指定设备的预览支持格式

v4l2-ctl --list-formats-ext --device /dev/video0
v4l2-ctl --list-formats-ext --device /dev/video1
rk3568_r:/ # v4l2-ctl --list-formats-ext --device /dev/video0   
v4l2-ctl --list-formats-ext --device /dev/video0                
ioctl: VIDIOC_ENUM_FMT                                          
        Index       : 0                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'UYVY'                                    
        Name        : UYVY 4:2:2                                
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 1                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: '422P'                                    
        Name        : Planar YUV 4:2:2                          
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 2                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV16'                                    
        Name        : Y/CbCr 4:2:2                              
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 3                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV61'                                    
        Name        : Y/CrCb 4:2:2                              
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 4                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'YM16'                                    
        Name        : Planar YUV 4:2:2 (N-C)                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 5                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV21'                                    
        Name        : Y/CrCb 4:2:0                              
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 6                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV12'                                    
        Name        : Y/CbCr 4:2:0                              
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 7                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NM21'                                    
        Name        : Y/CrCb 4:2:0 (N-C)                        
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 8                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NM12'                                    
        Name        : Y/CbCr 4:2:0 (N-C)                        
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 9                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'YU12'                                    
        Name        : Planar YUV 4:2:0                          
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 10                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'YM24'                                    
        Name        : Planar YUV 4:4:4 (N-C)                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 11                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'RGGB'                                    
        Name        : 8-bit Bayer RGRG/GBGB                     
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 12                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'GRBG'                                    
        Name        : 8-bit Bayer GRGR/BGBG                     
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 13                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'GBRG'                                    
        Name        : 8-bit Bayer GBGB/RGRG                     
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 14                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'BA81'                                    
        Name        : 8-bit Bayer BGBG/GRGR                     
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 15                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'RG10'                                    
        Name        : 10-bit Bayer RGRG/GBGB                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 16                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'BA10'                                    
        Name        : 10-bit Bayer GRGR/BGBG                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 17                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'GB10'                                    
        Name        : 10-bit Bayer GBGB/RGRG                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 18                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'BG10'                                    
        Name        : 10-bit Bayer BGBG/GRGR                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 19                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'RG12'                                    
        Name        : 12-bit Bayer RGRG/GBGB                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 20                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'BA12'                                    
        Name        : 12-bit Bayer GRGR/BGBG                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 21                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'GB12'                                    
        Name        : 12-bit Bayer GBGB/RGRG                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8  
                                                                
        Index       : 22                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'BG12'                                    
        Name        : 12-bit Bayer BGBG/GRGR                    
                Size: Stepwise 32x16 - 2112x1568 with step 8/8                                                 
rk3568_r:/ #                      
rk3568_r:/ # v4l2-ctl --list-formats-ext --device /dev/video1   
v4l2-ctl --list-formats-ext --device /dev/video1                
ioctl: VIDIOC_ENUM_FMT                                          
        Index       : 0                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'UYVY'                                    
        Name        : UYVY 4:2:2                                
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 1                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: '422P'                                    
        Name        : Planar YUV 4:2:2                          
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 2                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV16'                                    
        Name        : Y/CbCr 4:2:2                              
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 3                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV61'                                    
        Name        : Y/CrCb 4:2:2                              
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 4                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'YM16'                                    
        Name        : Planar YUV 4:2:2 (N-C)                    
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 5                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV21'                                    
        Name        : Y/CrCb 4:2:0                              
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 6                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NV12'                                    
        Name        : Y/CbCr 4:2:0                              
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 7                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NM21'                                    
        Name        : Y/CrCb 4:2:0 (N-C)                        
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 8                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'NM12'                                    
        Name        : Y/CbCr 4:2:0 (N-C)                        
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 9                                         
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'YU12'                                    
        Name        : Planar YUV 4:2:0                          
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 10                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'YM24'                                    
        Name        : Planar YUV 4:4:4 (N-C)                    
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 11                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'GREY'                                    
        Name        : 8-bit Greyscale                           
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 12                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'XR24'                                    
        Name        : 32-bit BGRX 8-8-8-8                       
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 13                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'RGBP'                                    
        Name        : 16-bit RGB 5-6-5                          
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  
                                                                
        Index       : 14                                        
        Type        : Video Capture Multiplanar                 
        Pixel Format: 'FBCG' (compressed)                       
        Name        : Rockchip fbc gain                         
                Size: Stepwise 32x16 - 1920x1080 with step 8/8  

3)获取指定设备的所有信息

v4l2-ctl --all --device /dev/video0

设备信息如下:

rk3568_r:/ # v4l2-ctl --all --device /dev/video0
v4l2-ctl --all --device /dev/video0
Driver Info:
        Driver name      : rkisp_v5
        Card type        : rkisp_mainpath
        Bus info         : platform:rkisp-vir0
        Driver version   : 1.8.0
        Capabilities     : 0x84201000
                Video Capture Multiplanar
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps      : 0x04201000
                Video Capture Multiplanar
                Streaming
                Extended Pix Format
Media Driver Info:
        Driver name      : rkisp-vir0
        Model            : rkisp0
        Serial           :
        Bus info         :
        Media version    : 4.19.255
        Hardware revision: 0x00000000 (0)
        Driver version   : 4.19.255
Interface Info:
        ID               : 0x0300000e
        Type             : V4L Video
Entity Info:
        ID               : 0x0000000d (13)
        Name             : rkisp_mainpath
        Function         : V4L2 I/O
        Pad 0x01000010   : Sink
          Link 0x02000011: from remote pad 0x1000004 of entity 'rkisp-isp-subdev': Data, Enabled
Priority: 2
Format Video Capture Multiplanar:
        Width/Height      : 2112/1568
        Pixel Format      : 'NV12'
        Field             : None
        Number of planes  : 1
        Flags             :
        Colorspace        : Default
        Transfer Function : Default
        YCbCr Encoding    : Default
        Quantization      : Full Range
        Plane 0           :
           Bytes per Line : 2112
           Size Image     : 4967424
Crop: Left 0, Top 0, Width 2112, Height 1568
Selection: crop, Left 0, Top 0, Width 2112, Height 1568, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 2112, Height 1568, Flags:
Selection: crop, Left 0, Top 0, Width 2112, Height 1568, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 2112, Height 1568, Flags:

User Controls

                       exposure 0x00980911 (int)    : min=4 max=3324 step=1 default=1536 value=1536

Image Source Controls

              vertical_blanking 0x009e0901 (int)    : min=192 max=29631 step=1 default=192 value=192
            horizontal_blanking 0x009e0902 (int)    : min=576 max=576 step=1 default=576 value=576 flags=read-only
                  analogue_gain 0x009e0903 (int)    : min=16 max=248 step=1 default=16 value=16

Image Processing Controls

                 link_frequency 0x009f0901 (intmenu): min=0 max=0 default=0 value=0 flags=read-only
                     pixel_rate 0x009f0902 (int64)  : min=0 max=0 step=0 default=0 value=120000000 flags=read-only
                   test_pattern 0x009f0903 (menu)   : min=0 max=4 default=0 value=0

4) 显示摄像头参数

v4l2-ctl --list-ctrls --device /dev/video0
或者
v4l2-ctl -d /dev/video0 -l 

显示摄像头参数

rk3568_r:/ # v4l2-ctl -d /dev/video0 -l     
v4l2-ctl -d /dev/video0 -l  
User Controls                                                                                                                                                               
                       exposure 0x00980911 (int)    : min=4 max=3324 step=1 default=1536 value=1536   
Image Source Controls                                                                                                                                                                                                                              
              vertical_blanking 0x009e0901 (int)    : min=192 max=29631 step=1 default=192 value=192   
            horizontal_blanking 0x009e0902 (int)    : min=576 max=576 step=1 default=576 value=576 flags=read-only 
                  analogue_gain 0x009e0903 (int)    : min=16 max=248 step=1 default=16 value=16   
Image Processing Controls                                                                                                       
                 link_frequency 0x009f0901 (intmenu): min=0 max=0 default=0 value=0 flags=read-only 
                     pixel_rate 0x009f0902 (int64)  : min=0 max=120000000 step=1 default=120000000 value=120000000 flags=read-only      
                   test_pattern 0x009f0903 (menu)   : min=0 max=4 default=0 value=0   

5)增加曝光exposure

exposure值区间为:  4-3324
命令实例:

v4l2-ctl -d /dev/video0 --set-ctrl exposure=3324

6)增加图片亮度analogue_gain

analogue_gain用于设置显示的图像的亮度

analogue_gain值区间:

16-248

命令实例:

v4l2-ctl -d /dev/video0 --set-ctrl analogue_gain=240

analogue_gain=16现象

analogue_gain=244现象【效果非常明显】

7)使用v4l2-ctl抓帧

v4l2-ctl -d /dev/video0 --set-fmt-video=width=800,height=600,pixelformat=NV12 --stream-mmap=3 --stream-to=/sdcard/out.yuv --stream-skip=9 --stream-count=1
m-mmap=3 --stream-to=/sdcard/out.yuv --stream-skip=9 --stream-count=1         <
<<<<<<<<< 7.51 fps
<

【看到<<<<<<<<< 7.51 fps 说明成功】

参数说明

-d: 摄像头对应设备文件
--set-fmt-video:指定了宽高及pxielformat(用FourCC表示)。NV12即用FourCC表示的pixelformat
--stream-mmap:指定buffer的类型为mmap,即由kernel分配的物理连续的或经过iommu映射的buffer
--stream-to:指定帧数据保存的文件路径
--stream-skip:指定丢弃(不保存到文件)前3帧
--stream-count:指定抓取的帧数,不包括--stream-skip丢弃的数量

其他参数
--set-selection,指定对输入图像进行裁剪。特别是当RKISP1的前级大小发生变化时要保证selection不大于前级输出大小。RKCIF的裁剪则是通过--set-crop参数设置的
--stream-poll,该选项指示v4l2-ctl采用异步IO,即在dqbuf前先用select等等帧数据完成,从而保证dqbuf不阻塞。否则dqbuf将会阻塞直到有数据帧到来

如果支持264的可以编码为h264查看

v4l2-ctl --device /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=H264 --stream-mmap=3 --stream-to=/sdcard/output --stream-count=100

v4l2-ctl --device /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=MJPG --stream-mmap --stream-to=/sdcard/output.mjpg --stream-count=300

8)测试显示信息test_pattern

参数test_pattern,可以用于测试显示图像

    • 0:摄像头1-3 测试图片

 

    命令实例:
v4l2-ctl -d /dev/video0 --set-ctrl test_pattern=0 

test_pattern = 1test_pattern = 2test_pattern = 3

4. 显示图片

上一节,抓取的图片、视频要可以拷贝到ubuntu中借助借助工具ffplay查看。

1)ffplay

FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。

采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。

它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的。

ffplay是FFmpeg提供的一个极为简单的音视频媒体播放器(由ffmpeg库和SDL库开发),可以用于音视频播放、可视化分析 ,提供音视频显示和播放相关的图像信息、音频的波形等信息,也可以用作FFmpeg API的测试工具使用。

由于是基于FFmpeg开发所以ffmpeg支持的视音频格式它基本上都支持,不过ffplay不是图形化界面需要通过CMD命令窗口来操作。

2)官网网站

http://www.ffmpeg.org/ffplay.html

3)ffplay命令选项:

基本格式: ffplay [选项] [‘输入文件’]

主要选项:

-x width      强制显示宽带
-y height      强制显示高度
-video_size size    设置帧尺寸 设置帧尺寸大小。
 适用于类似原始YUV等没有包含帧大小(WxH)的视频。
 例如:ffplay -pixel_format yuv420p -video_size 320x240 -framerate 5 yuv420p_320x240.yuv
-pixel_format format   设置像素格式。
-volume vol     设置起始音量。音量范围[0 ~100]
-window_title title   设置窗口标题(默认为输入文件名)
-loop number     设置播放循环次数
-showmode mode     设置显示模式,可用的模式值:0 显示视频,1 显示音频波形,2 显示音频频谱。缺省为0,如果视频不存在则自动选择2
-vf filtergraph    设置视频滤镜
-af filtergraph    设置音频滤镜
-f fmt       强制使用设置的格式进行解析。比如-f s16le 

-fs      以全屏模式启动
-an      禁用音频(不播放声音)
-vn      禁用视频(不播放视频)
-sn      禁用字幕(不显示字幕)
-nodisp     关闭图形化显示窗口,视频将不显示
-noborder     无边框窗口


-t duration   设置播放视频/音频长度,时间单位如 -ss选项
-ss pos    跳转到指定的位置,注意时间单位:
  比如:'55' 55 seconds, 
   '12:03:45' ,12 hours, 03 minutes and 45 seconds, 
   '23.189' 23.189 second


-bytes        按字节进行跳转(0=off 1=on -1=auto)。
-seek_interval interval   自定义左/右键定位拖动间隔(以秒为单位),默认值为10秒(代码没有看到实现)

4)显示图片

将文件**/sdcard/out.yuv从板子通过adb pull**命令拷贝出来,
运行于windows下:

adb pull /sdcard/out.yuv

再拷贝到ubuntu中,执行以下命令显示图片【用其他可以打开yuv格式图片的工具也可以】

ffplay out.yuv -f rawvideo -pixel_format nv12 -video_size 800x600

 

掌握了这些命令,我们就可以调试摄像头了。

后面还会继续更新几篇Camera文章,

建议大家订阅本专题!

瑞芯微电子

瑞芯微电子

瑞芯微专注于移动互联网、数字多媒体芯片设计,是专业的个人移动信息终端SOC解决方案供应商。瑞芯微在移动互联网领域有多个较完整的自主创新的知识产权群,为中国电子业发展做出积极努力。目前产品涵盖Android平板电脑、Android电视机顶盒(智能电视)、电子书、WIFI/蓝牙音频解决方案等。

瑞芯微专注于移动互联网、数字多媒体芯片设计,是专业的个人移动信息终端SOC解决方案供应商。瑞芯微在移动互联网领域有多个较完整的自主创新的知识产权群,为中国电子业发展做出积极努力。目前产品涵盖Android平板电脑、Android电视机顶盒(智能电视)、电子书、WIFI/蓝牙音频解决方案等。收起

查看更多

相关推荐

电子产业图谱

公众号『一口Linux』号主彭老师,拥有15年嵌入式开发经验和培训经验。曾任职ZTE,某研究所,华清远见教学总监。拥有多篇网络协议相关专利和软件著作。精通计算机网络、Linux系统编程、ARM、Linux驱动、龙芯、物联网。原创内容基本从实际项目出发,保持原理+实践风格,适合Linux驱动新手入门和技术进阶。