Prevent GStreamer from changing camera format

1k Views Asked by At

Running GStreamer pipeline that feeds from v4l2src element may change camera format implicitly.

Here is an example (also note that /dev/video0 is everywhere implied).

One of my cameras supports these formats

$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'YUYV' (YUYV 4:2:2)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
        Size: Discrete 1280x800
            Interval: Discrete 0.133s (7.500 fps)
        Size: Discrete 1280x1024
            Interval: Discrete 0.133s (7.500 fps)

The current format is

$ v4l2-ctl --get-fmt-video
Format Video Capture:
    Width/Height      : 640/480
    Pixel Format      : 'YUYV' (YUYV 4:2:2)
    Field             : None
    Bytes per Line    : 1280
    Size Image        : 614400
    Colorspace        : Default
    Transfer Function : Default (maps to Rec. 709)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization      : Default (maps to Limited Range)
    Flags             : 

If I just run this pipeline

$ gst-launch-1.0 -e v4l2src ! videoconvert ! autovideosink

This will change the current format (before the pipeline is run, but it will also be left in that state) to

$ v4l2-ctl --get-fmt-video
Format Video Capture:
    Width/Height      : 1280/1024
    Pixel Format      : 'YUYV' (YUYV 4:2:2)
    Field             : None
    Bytes per Line    : 2560
    Size Image        : 2621440
    Colorspace        : Default
    Transfer Function : Default (maps to Rec. 709)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization      : Default (maps to Limited Range)
    Flags             : 

And this is not what I want. What I want is for GStreamer to use already set format and not change it. How I can accomplish that programmatically (gst-launch-1.0 was just an example, I'm primarily interested in doing this in code)?

1

There are 1 best solutions below

0
On

When the caps-negotiation between pipeline elements is taking place, the first match will be used. Most probably it is not what you set up.

To enforce given format, define caps explicitly:

gst-launch-1.0 -e v4l2src ! videoconvert ! \
video/x-raw,format=YVYU,width=640,height=480,framerate=15/1 ! \
videoconvert ! xvimagesink

To set the caps in C/C++, use:

gst_util_set_object_arg(element, "caps", "video/x-raw, width=640, height=480, format=YUY2");