v4l2 and gstreamer usage guide

 

Table of contents

 V4L2

  compile

 Get camera information

 list device nodes        

 List the attribute parameters of a node

 Capture images and video

pixel format

   YUYV image format

   image size

 7yuv

MPP compression test

cross compile configuration

compression test

Greg

 capture video command

command parameters

codec information


The two command tools focus on different functions, v4l2 is mainly used for video capture; gstreamer is like a housekeeper, integrating all components to complete a certain function.

  

 V4L2

  compile

   1)   Select the corresponding version from the link below:

index/downloads/v4l-utils

 2) Unzip the compressed package, cd v4l-utils to set the platform GCC

export PATH=/home/rockchip/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu//bin:$PATH

导出PKG_CONFIG_LIBDIR=/home/rockchip/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/lib

   3) The --with-udevdir parameter sets the directory to avoid permission issues with the directory /lib/udev

./configure --host=aarch64-linux-gnu --prefix=/home/rockchip/v4l2/src/out --with-udevdir=/home/rockchip/v4l2/src/out

to install

customer@ubuntu:~/200/v4l-utils-1.20.0/out/bin$ file v4l2-ctl

 Get camera information

 list device nodes        

./v4l2-ctl --list-devices

Computer camera (1.1):

/dev/media1

rkisp1-statistics (platform: rkisp1):

/dev/video4

/dev/video5

rkisp1_mainpath (platform: ffb50000.rkisp1):

/dev/video0

/dev/video1

/dev/video2

/dev/video3

rkisp1 (platform:rkisp1):

/dev/media0

Computer camera (usb-ffd80000.usb-1.1):

/dev/video6

/dev/video7

 List the attribute parameters of a node

[root@rk1808:~]#./v4l2-ctl -d /dev/video6 --all

Driver Information:

Driver Name: uvcvideo

Card Type: PC Camera

Bus information: usb-ffd80000.usb-1.1

Driver version: 4.4.194

Capability : 0x84a00001

Video Capture

Metadata Capture

Streaming

Extended Pix Format

Device Capabilities

Device Caps : 0x04200001

Video Capture

Streaming

Extended Pix Format

Media Driver Info:

Driver name : uvcvideo

Model : PC Cam

Serial :

Bus info : 1.1

Media version : 0.1.0

Hardware revision: 0x00000007 (7)

Driver version : 4.4.194

Entity Info:

ID : 1

Name : PC Cam

Type : V4L2 I/O

Flags : default

Major : 81

Minor : 8

Pad : 0: Sink

Priority: 2

Video input : 0 (Camera 1: ok)

Format Video Capture: (video format, when using commands to capture, it needs to be consistent with this video format)

Width/Height : 640/480

Pixel Format : 'YUYV' (YUYV 4:2:2)

Field : None

Bytes per Line : 1280

Size Image : 614400

Colorspace : sRGB

Transfer Function : Default (maps to sRGB)

YCbCr/HSV Encoding: Default (maps to ITU-R 601)

Quantization : Default (maps to Limited Range)

Flags :

Crop Capability Video Capture: (Crop Capability)

Bounds : Left 0, Top 0, Width 640, Height 480

Default : Left 0, Top 0, Width 640, Height 480

Pixel Aspect: 1/1

Selection Video Capture: crop_default, Left 0, Top 0, Width 640, Height 480, Flags:

Selection Video Capture: crop_bounds, Left 0, Top 0, Width 640, Height 480, Flags:

Streaming Parameters Video Capture:

Capabilities : timeperframe (frame rate setting, after the frame rate is set here, it will have an impact on the frame rate of the subsequent captured video)

Frames per second: invalid (1/0)

Read buffers : 0

brightness 0x00980900 (int) : min=0 max=255 step=1 default=120 value=120

contrast 0x00980901 (int) : min=0 max=127 step=1 default=23 value=23

saturation 0x00980902 (int) : min=0 max=127 step=1 default=32 value=32

hue 0x00980903 (int) : min=-15 max=15 step=1 default=3 value=3

white_balance_temperature_auto 0x0098090c (bool) : default=1 value=1

gamma 0x00980910 (int) : min=1 max=10 step=1 default=8 value=8

gain 0x00980913 (int) : min=0 max=9 step=1 default=2 value=2

power_line_frequency 0x00980918 (menu) : min=0 max=2 default=2 value=2 (60 Hz)

0: Disabled

1: 50 Hz

2: 60 Hz

white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=1 default=5000 value=5000 flags=inactive

sharpness 0x0098091b (int) : min=0 max=15 step=1 default=1 value=1

backlight_compensation 0x0098091c (int) : min=0 max=1 step=1 default=0 value=0

exposure_auto_priority 0x009a0903 (bool) : default=0 value=1

 Capture images and video

1) ./v4l2-ctl -d /dev/video6 \--set-fmt-video=width=640,height=480,pixelformat=NV12 \--stream-mmap=3 \--stream-skip=3 \--stream-to=/tmp/cif.out \--stream-count=1 \--stream-poll

The pixelformat 'NV12' is invalid

ount=1 \--stream-poll

2) ./v4l2-ctl -d /dev/video6 \--set-fmt-video=width=640,height=480,pixelformat=YUYV \--stream-mmap=3 \--stream-skip=3 \--stream-to=/tmp/cif.out \--stream-count=1 \--stream-poll

According to the previous query command, only YUYV format is supported.

Modify the stream-count of this command to 100, etc., then capture the frame video of the stream-count number.

pixel format

Take it out separately as a section, because this is the supported format of the camera and the entrance of the video.

For example, a camera in the picture below supports more formats than the ones listed above that only support YUYV.

Including supported resolutions, frame rates, etc.

 

The V4L2_PIX_FMT_MJPEG acquisition method obtains pictures compressed by MJPEG , the picture format is jpeg/jpg, and the suffix is ​​.jpg or .jpeg. Directly write the collected .jpeg data into a file sequentially and cyclically. The obtained stream cannot be played directly. It needs to be packaged into a video format such as avi to play normally.

The V4L2_PIX_FMT_YUYV acquisition method obtains the original image format file in yuyv format with the suffix .yuv, and the obtained yuv data file can be directly played by a professional yuv format viewer such as pYUV, and the yuv data can be played through HEVC (H265), H264, VP8, VP9 and other methods are used to encode and compress, and the h264 bit stream can be obtained through h.264 compression, and the H264 bit stream can be played directly with VLC player.

      MJPEG is a compressed format, so it still has 30fps at 1080P; while YUYV is the original image, 1080P only supports 5fps .

   YUYV image format

     The image or video of yuyv is collected above, so how to view it is a problem, and how to calculate the size?

   image size

 7yuv

   

MPP compression test

There are mpp test cases in the sdk

cross compile configuration

compression test

./mpi_enc_test -w 640 -h 480 -t 7 -i /tmp/cif.out -o /tmp/out_f8.h264 -n 100 -f 8

The -f parameter specifies the input video format, here is 8, which is YUYV. If not specified, the compressed video cannot be played

The meaning of each format of -f:

mpp[1055]: mpi: mpp color support list:
mpp[1055]: mpi: color: id 0          0x00000 YUV420SP,          NV12
mpp[1055]: mpi: color: id 1          0x00001 YUV420SP-10bit
mpp[1055]: mpi: color: id 2          0x00002 YUV422SP,          NV24
mpp[1055]: mpi: color: id 3          0x00003 YUV422SP-10bit
mpp[1055]: mpi: color: id 4          0x00004 YUV420P,          I420
mpp[1055]: mpi: color: id 5          0x00005 YUV420SP,          NV21
mpp[1055]: mpi: color: id 6          0x00006 YUV422P,          422P
mpp[1055]: mpi: color: id 7          0x00007 YUV422SP,          NV42
mpp[1055]: mpi: color: id 8          0x00008 YUV422-YUYV,          YUY2
mpp[1055]: mpi: color: id 10          0x0000a YUV422-UYVY,          UYVY
mpp[1055]: mpi: color: id 12          0x0000c YUV400-Y8,          Y800
mpp[1055]: mpi: color: id 65536 0x10000 RGB565
mpp[1055]: mpi: color: id 65537 0x10001 BGR565
mpp[1055]: mpi: color: id 65538 0x10002 RGB555
mpp[1055]: mpi: color: id 65539 0x10003 BGR555
mpp[1055]: mpi: color: id 65542 0x10006 RGB888
mpp[1055]: mpi: color: id 65543 0x10007 BGR888
mpp[1055]: mpi: color: id 65546 0x1000a ARGB8888
mpp[1055]: mpi: color: id 65547 0x1000b ABGR8888
mpp[1055]: mpi: color: id 65548 0x1000c BGRA8888
mpp[1055]: mpi: color: id 65549 0x1000d RGBA8888

compression time

​​​​​​​time ./mpi_enc_test -w 640 -h 480 -t 7 -i /tmp/cif.out -o /tmp/out_f8.h264 -n 100 -f 8

The time information is :

gstreamer

Borrow an icon from Rockchip

 capture video command

 gst-launch-1.0 v4l2src device=/dev/video6 num-buffers=100 ! videoconvert !video/x-raw,format=NV12,width=640,height=480 ! queue ! mpph264enc ! queue ! h264parse ! qtmux ! filesink location=/tmp/uvc_h264.mp4

command parameters

element

v4l2src

device=/dev/video6

num-buffers=100

! videoconvert

!video/x-raw,format=NV12,width=640,height=480

! queue ! mpph264enc

! queue ! h264parse

! qtmux

! filesink location=/tmp/uvc_h264.mp4

codec information

Through the above command, the compressed video codec information is as follows. Where does the frame rate come from ?

 

 

Guess you like

Origin blog.csdn.net/proware/article/details/128064939