# Configure
Source: [https://docs.qualcomm.com/doc/80-70015-20/topic/configure.html](https://docs.qualcomm.com/doc/80-70015-20/topic/configure.html)
Information on how to configure the V4L2 and GStreamer APIs for different features is
provided in the following topics.
## Configure V4L2 APIs for different features
The following information is about V4L2 control IDs, accepted format, ranges, and
sample code for different features.
**B-frame encode**
You can configure the VPU driver to enable B-frames in an encoder session using the
`VIDIOC_S_CTRL` ioctl system call. Set this configuration before
the `VIDIOC_STREAMON` on an output plane. The VPU driver supports
B-frame encode only with the Hierarchical coding. Dynamic configuration is not
supported.
| Control ID for H.264 and HEVC codec | Accepted format | Range |
| :---: | :---: | :---: |
| V4L2_CID_MPEG_VIDEO_B_FRAMESCopy to clipboard | Integer |
- {0, 1}
- 0: Disable B-frame
- 1: Enable 1 B-frame
|
The following code sample shows the static configuration to enable a single
B-frame:
v4l2_control control;
int ret = 0;
int bframes = 1;
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_B_FRAMES;
control.value = bframes;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE;
control.value = 0;// V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER;
control.value = 1;//Enable 1 layer
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}Copy to clipboard
**Encoder initial QP override**
You can configure the VPU driver to override the initial frame Quantization Parameter
(QP) for I, P, and B frames to an intended value of encoded frames. This override is
performed using the `VIDIOC_S_CTRL` ioctl system call. It also has
the flexibility to set initial frame QP for I only, or P only, or B only, or I and P
only, or P and B only and so on. This configuration is set before the
`VIDIOC_STREAMON` on an output plane and is only applicable to an
encoder session.
| Control ID for H.264 codec | Accepted format | QP range |
| --- | --- | --- |
| V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QPCopy to clipboard | Integer | Example according to the codec
standard:
- 1 to 51 for 8‑bit
- 1 to 63 (-12 to 51) for 10‑bit
|
| V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QPCopy to clipboard | Integer | Example according to the codec
standard:
- 1 to 51 for 8‑bit
- 1 to 63 (-12 to 51) for 10‑bit
|
| V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QPCopy to clipboard | Integer | Example according to the codec
standard:
- 1 to 51 for 8‑bit
- 1 to 63 (-12 to 51) for 10‑bit
|
| | | |
| | | |
| Control ID for HEVC codec | Accepted format | QP range |
| --- | --- | --- |
| V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QPCopy to clipboard | Integer | Example according to the codec
standard:
- 1 to 51 for 8‑bit
- 1 to 63 (-12 to 51) for 10‑bit
|
| V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QPICopy to clipboard | Integer | Example according to the codec
standard:
- 1 to 51 for 8‑bit
- 1 to 63 (-12 to 51) for 10‑bit
|
| V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QPCopy to clipboard | Integer | Example according to the codec
standard:
- 1 to 51 for 8‑bit
- 1 to 63 (-12 to 51) for 10‑bit
|
| | | |
| | | |
The following code sample shows the static configuration parameter to choose the
following:
- 40 as an initial QP for I frame
- 35 as an initial QP for P-Frame
- B-frame for H.264 session
v4l2_control control;
int ret = 0;
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP;
control.value = 40;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP;
control.value = 35;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP;
control.value = 35;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}Copy to clipboard
**Slice encode**
You can configure the VPU driver to encode a single frame to multiple slices using
the `VIDIOC_S_CTRL` ioctl system call. A slice boundary is specified
as the number of bits per slice or the number of macroblocks per slice. This
configuration is set before the `VIDIOC_STREAMON` on an output plane.
Dynamic configuration is not supported in this feature, and this configuration is
applicable only to an encoder session.
| Control ID for H.264 and HEVC | Accepted format | Range |
| :---: | :---: | :---: |
| V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODECopy to clipboard | enum
`
v4l2_mpeg_video_multi_slice_mode` | Values according to the codec standard:
enum
`
v4l2_mpeg_video_multi_slice_mode` |
| V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTESCopy to clipboard | Integer | 512 - MAX\_BITRATE/8
Unit: bits/second |
| V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MBCopy to clipboard | Integer | 1 to 36864
Unit: Macroblocks |
The following code sample shows the static configuration to encode frames with
multiple slices and with the maximum number of macroblocks per slice set to 400:
v4l2_control control;
int ret = 0;
v4l2_mpeg_video_multi_slice_mode slicemode = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB;
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE;
control.value = slicemode;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB;
control.value = 400;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
Copy to clipboard
**Intra refresh**
You can configure the VPU driver to enable the intrarefresh mode and intrarefresh
period using the `VIDIOC_S_CTRL` ioctl system call. This
configuration is set before the `VIDIOC_STREAMON` on an output plane.
It is to be noted that the intrarefresh period can be modified dynamically during
the session and this feature is applicable only to an encoder session.
| Control ID for H.264 and HEVC | Accepted format | Range |
| :---: | :---: | :---: |
| V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPECopy to clipboard | enum
`
v4l2_mpeg_video_intra_refresh_period_type` | `{V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_RANDOM,
V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_CYCLIC}`
Random
mode:
V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_RANDOMCopy to clipboard
Cyclic
mode:
V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_CYCLICCopy to clipboard |
| V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIODCopy to clipboard | Integer | Set the intrarefresh period to be less than an I-frame
interval
Unit: number of frames |
The following code sample shows the static configuration to enable the random intra
refresh for every 10 frames:
v4l2_control control;
int ret = 0;
v4l2_mpeg_video_intra_refresh_period_type refreshtype = V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_RANDOM;
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE;
control.value = refreshtype;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD;
control.value = 10;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}Copy to clipboard
**Rotation**
You can configure the VPU driver to rotate the input frame before encoding using the
`VIDIOC_S_CTRL` ioctl system call. This configuration is set
before the `VIDIOC_STREAMON` on an output plane. This feature does
not support dynamic configuration and is applicable only to an encoder session.
| Control ID for H264 and HEVC | Accepted format | Range |
| :---: | :---: | :---: |
| V4L2_CID_ROTATECopy to clipboard | Integer | {90, 180, 270}
Unit: degrees |
The following code sample shows the static configuration for rotating an input frame
to 90 degrees:
v4l2_control control;
int ret = 0;
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_ROTATE;
control.value = 90;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}Copy to clipboard
**Frame QP range**
You can configure the VPU driver to set the minimum and maximum frame QP range
parameters for I, P, and B frames to the intended values for encoded frames using
the `VIDIOC_S_CTRL` ioctl system call. Set this configuration before
the `VIDIOC_STREAMON` on an output plane. The values are valid for an
entire session. Dynamic configuration is not supported, and this feature is
applicable only to an encoder session.
| Control ID for H.264 codec | Accepted format | Range |
| --- | --- | --- |
| V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MIN_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MAX_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MIN_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MAX_QPCopy to clipboard | Integer | Example according to the codec
standard: 1 to 51 for 8‑bit |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
The following code sample shows the static configuration parameter to choose 40 as
the maximum QP and 10 as the minimum QP for the I, P, and B-frames in a H.264
session:
v4l2_control control;
int ret = 0;
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP;
control.value = 10;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP;
control.value = 10;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QP;
control.value = 10;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP;
control.value = 40;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP;
control.value = 40;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
memset(&control, 0, sizeof(control));
control.id = V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QP;
control.value = 40;
ret = ioctl(mDriverFd, VIDIOC_S_CTRL, &control);// mDriverFd returned from open() system call
if (ret) {
return -1;
}
Copy to clipboard
Alternatively, you can configure the following controls if you wish to have the same
minimum and maximum QP value for I, P, and B-frames:
| Control ID for H.264 codec | Accepted format | Range |
| --- | --- | --- |
| `V4L2_CID_MPEG_VIDEO_H264_MIN_QP` | Integer | Example according to the code
standard: 1 to 51 for 8‑bit |
| `V4L2_CID_MPEG_VIDEO_H264_MAX_QP` | Integer | Example according to the code
standard: 1 to 51 for 8‑bit |
| | | |
| Control ID for HEVC codec | Accepted format | Range |
| --- | --- | --- |
| `V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP` | Integer | Example according to the code
standard: 1 to 51 for 8‑bit |
| `V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP` | Integer | Example according to the code
standard: 1 to 51 for 8‑bit |
| | | |
## Configure GStreamer APIs for different features
For more information on the GStreamer element property for different features and
respective plugins, see [Qualcomm GST plugins](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-50/qim-sdk-plugins.html).
Last Published: Oct 15, 2024
[Previous Topic
Sample applications](https://docs.qualcomm.com/bundle/publicresource/80-70015-20/topics/samples.md) [Next Topic
Debug](https://docs.qualcomm.com/bundle/publicresource/80-70015-20/topics/debug.md)