Video Module
Supported ICs: [RTL8735C]
Overview
The video_module is the AP-side interface to the video pipeline. Camera, ISP, and encoder control are handled by the VP firmware; applications configure streams through video_params_t and then connect the output to AP-side MMF modules.
AP / VP video pipeline and runtime control path.
video_params_t video_params = {
.stream_id = V1_STREAM_ID,
.format = VIDEO_H264,
.width = 1920,
.height = 1080,
.fps = 30,
.gop = 30,
.bps = 2000000,
.rc_mode = ENC_VBR,
.min_qp = 26,
.max_qp = 48,
.qlevel = 5,
.ainr_en = 0,
};
mm_context_t *video_ctx = mm_module_open(&video_module);
mm_module_ctrl(video_ctx, CMD_VIDEO_SET_PARAMS, (int)&video_params);
mm_module_ctrl(video_ctx, MM_CMD_SET_QUEUE_LEN, 60);
mm_module_ctrl(video_ctx, MM_CMD_INIT_QUEUE_ITEMS, MMQI_FLAG_DYNAMIC);
mm_module_ctrl(video_ctx, CMD_VIDEO_APPLY, 0);
stream_id
The ISP supports up to 5 simultaneous output channels. Each video_module instance occupies one channel.
Constant |
Value |
Typical use |
|---|---|---|
|
0 |
High-res encoded stream (recording / streaming) |
|
1 |
Mid-res encoded stream (live streaming) |
|
2 |
Low-fps encoded stream (JPEG snapshot) |
|
3 |
Raw NV12 output (motion detection) |
|
4 |
Raw RGB output (NN inference input) |
Note
The hardware encoder supports only the first 3 channels (V1-V3). V4 and V5 output raw (unencoded) ISP frames; gop, bps, rc_mode, min_qp, and max_qp have no effect on these channels.
format
Selects the output format of the channel.
Constant |
Value |
Description |
|---|---|---|
|
1 |
H.265 / HEVC encoded bitstream |
|
2 |
H.264 / AVC encoded bitstream |
|
4 |
JPEG encoded frame |
|
8 |
Raw YUV 4:2:0 semi-planar (NV12) |
|
16 |
Raw RGB888 (used for NN input on V5) |
|
5 |
Dual output: HEVC + JPEG simultaneously |
|
6 |
Dual output: H.264 + JPEG simultaneously |
fps / gop / bps
fps: Target frame rate of the channel output.gop: I-frame interval in frames. A common setting is to matchfps(one I-frame per second).bps: Target bitrate in bits per second for encoded streams. Has no effect for raw output (NV12, RGB).
rc_mode
Rate control mode for the encoder.
Constant |
Value |
Description |
|---|---|---|
|
0 |
Constrained VBR - bitrate bounded by |
|
1 |
Constant bitrate |
|
2 |
Variable bitrate - quality-first, |
|
3 |
Average bitrate |
|
4 |
Constant rate factor - fixed perceptual quality |
|
5 |
Constant QP - fixed quantisation parameter |
min_qp / max_qp
Quantisation parameter bounds used by VBR/CVBR rate control to limit quality variation. Lower QP = higher quality, larger frame size. Typical values: min_qp = 26, max_qp = 48.
qlevel
JPEG quality level (0-9). Only applies when format includes VIDEO_JPEG. Higher value = better quality.
ainr_en
Enables AI Noise Reduction (AINR). Set to 1 to enable, 0 to disable. AINR is a processing module inserted between the image sensor and the ISP, so it operates on the raw sensor data before any channel split. Enabling it on any one channel activates AINR globally for all active channels. AINR improves image quality in low-light conditions but increases processing load.
video_params.ainr_en = 1; /* enable AI noise reduction (applies to all channels) */
Encoder Parameter Configuration Timing
For AP applications, before encoder open means before CMD_VIDEO_APPLY is called. The usual sequence is:
Fill
video_params_tand any other init-time stream parameters.Send them with
CMD_VIDEO_SET_PARAMS.Configure the MMF queue.
Call
CMD_VIDEO_APPLY. This asks VP firmware to create the stream and open the encoder when the channel uses H.264, H.265, or JPEG.
After CMD_VIDEO_APPLY and stream start, keep runtime changes to controls that the AP/VP path and encoder driver can queue safely. If a running stream must change codec, resolution, profile, VUI/header, or HRD behavior, stop the stream and open it again with the new init-time configuration.
Common customer requests
Request |
Supported timing |
What to do |
|---|---|---|
Change codec / output format |
Init-time only |
Set |
Change width / height |
Init-time only |
Set |
Change initial frame rate |
Init-time configuration |
Set |
Tune bitrate while streaming |
Runtime supported |
Use the runtime bitrate control path. In the joint test example, use |
Tune QP range while streaming |
Runtime supported |
Use the runtime QP control path. In the joint test example, use |
Change GOP while streaming |
Runtime supported |
Use the runtime GOP control path. In the joint test example, use |
Request an I-frame |
Runtime supported |
Use |
Change profile / level / VUI / SEI / HRD |
Init-time only |
Configure before stream start. Changing these mid-stream can confuse the decoder, cause playback artifacts, or require the client to reconnect. |
Tune slice / deblock / CIR / ROI |
Runtime supported by the encoder driver |
Use only AP helpers that are explicitly provided by the SDK for these controls. They map to the queued coding-control path. |
Enable encoder rotation / mirror |
Not supported |
Encoder preprocess rotation/mirror is not enabled in RTL configuration, so no AP API is provided. |
CMD_VIDEO_* Parameter Reference
The tables below map every encoder-related parameter to its configuration timing and the exact AP-side command or helper to use.
Init-time only — configure in video_params_t (or via video_params_set_* helpers) before CMD_VIDEO_APPLY. These enter the encoder open sequence (VCEncInit(), SPS/PPS/VUI header, profile/level checks, or HRD model) and require a stream stop-and-reopen to change.
Parameters in this group are set in three different ways:
Direct field assignment — for basic fields like
stream_id,format,width,height. Assign directly in thevideo_params_tstruct initializer.Helper functions (
video_params_set_*) — for profile/level/tier, CABAC, SAR, and driver SEI. These set the internal flags automatically so you do not need to touchrc_ext.flagsorcoding.flagsyourself.rc_ext / coding flags — for advanced options not covered by a helper. You must set the flag bit and the value together. The flag tells VP that the field has been intentionally set — a value of
0is still meaningful (e.g.,pictureRc = 0explicitly disables picture RC), so VP ignores any field whose flag is not set.
video_params_t video_params = {
.stream_id = V1_STREAM_ID,
.format = VIDEO_H264,
.width = 1920,
.height = 1080,
.fps = 30,
.gop = 30,
.bps = 2000000,
.rc_mode = ENC_VBR,
};
/* Helper: sets profile, level, and internal flags automatically */
video_params_set_profile_level(&video_params, ENC_H264_MAIN, 41);
video_params_set_cabac(&video_params, 1); /* enable CABAC */
video_params_set_driver_sei(&video_params, 1); /* picture timing SEI */
/* rc_ext flags: must set flag AND value — VP ignores fields without flag */
video_params.rc_ext.flags |= VPAP_ENC_RC_EXT_HRD;
video_params.rc_ext.hrd = 1;
/* coding flags: same pattern */
video_params.coding.flags |= VPAP_ENC_CODING_FULL_RANGE;
video_params.coding.vuiVideoFullRange = 1;
mm_module_ctrl(video_ctx, CMD_VIDEO_SET_PARAMS, (int)&video_params);
mm_module_ctrl(video_ctx, CMD_VIDEO_APPLY, 0);
Parameter |
|
Description |
|---|---|---|
Stream channel |
|
V1–V5 channel. Determines the ISP output port and encoder instance. |
Output format / codec |
|
|
Resolution |
|
Sets ISP crop and encoder buffer geometry. Requires reopen to change. |
JPEG quality level |
|
JPEG encoding quality (0–9). No effect on H.264/H.265. |
Profile / Level |
|
H.264/H.265 profile and level. Affects SPS signaling and decoder compatibility. |
Tier |
|
H.265 Main / High tier. Affects maximum bitrate limits in level definitions. |
HRD conformance |
|
Enable HRD bitstream timing model. Conflicts with |
CPB buffer / max rate |
|
CPB buffer size in bits and max CPB bitrate. |
Filler data |
|
Insert filler NAL units to pad to target bitrate. Requires both |
VUI full range |
|
Full-range or limited-range signal in VUI. Affects decoder luma/chroma interpretation. |
HEVC SAO |
|
Enable HEVC Sample Adaptive Offset filter. Requires HW SAO support. |
H.264 CABAC |
|
Enable CABAC entropy coding. H.264 Baseline profile does not support CABAC. |
Sample aspect ratio |
|
Non-square pixel SAR in VUI. Omit for standard square-pixel content. |
Driver SEI |
|
Enable driver-generated picture timing and buffering period SEI messages. |
Init + Runtime — may be set in video_params_t before CMD_VIDEO_APPLY as the initial value, and updated after stream start using the listed CMD_VIDEO_* command via mm_module_ctrl().
For runtime updates, scalar parameters pass the new value directly as the third argument. Parameters that take a struct pass a pointer cast to int:
/* Scalar: pass value directly */
mm_module_ctrl(video_ctx, CMD_VIDEO_BITRATE, 1000000);
mm_module_ctrl(video_ctx, CMD_VIDEO_GOP, 60);
mm_module_ctrl(video_ctx, CMD_VIDEO_FPS, 15);
mm_module_ctrl(video_ctx, CMD_VIDEO_RCMODE, ENC_CBR);
/* Struct: fill a local struct and pass its address cast to int */
video_qp_range_t qp = { .min_qp = 28, .max_qp = 45 };
mm_module_ctrl(video_ctx, CMD_VIDEO_SET_QP, (int)&qp);
video_moving_bitrate_t moving = { .tolerance = 200, .frames = 30 };
mm_module_ctrl(video_ctx, CMD_VIDEO_MOVING_BITRATE, (int)&moving);
video_deblock_t deblock = { .disable = 0, .tc_offset = 0, .beta_offset = 0 };
mm_module_ctrl(video_ctx, CMD_VIDEO_DEBLOCK, (int)&deblock);
Init field |
Runtime CMD |
API function |
Description |
|---|---|---|---|
|
|
|
Output frame rate. |
|
|
|
I-frame interval in frames. |
|
|
|
Target bitrate in bps. |
|
|
|
Rate control mode (CVBR / CBR / VBR / ABR / CRF / CQP). |
|
|
|
Global QP lower bound. |
|
|
|
Global QP upper bound. |
|
|
|
Set both global min and max QP in one call. |
|
|
|
AI Noise Reduction. Configured on V1; applies globally to all channels. |
|
|
|
Initial picture QP ( |
|
|
|
I-frame QP range. Overrides global min/max QP for intra frames. |
|
|
|
QP offset applied to intra frames relative to inter (−51 to +51). |
|
|
|
Pin intra QP to a fixed value. |
|
|
|
Enable picture-level rate control. |
|
|
|
CTB-level RC mode (0=off / 1=subjective / 2=precise / 3=mixed). |
|
|
|
CTB RC granularity (0=64×64 / 1=32×32 / 2=16×16). |
|
|
|
Allow RC to skip frames to stay within bitrate target. |
|
|
|
RC averaging window (1–300 frames). |
|
|
|
Moving bitrate tolerance (0–2000 %) and monitoring window (10–120 frames). |
|
|
|
Constant Rate Factor ( |
|
|
|
VBR-style quality control. Cannot be enabled together with |
|
|
|
Slice height in CTB rows. |
|
|
|
Insert user_data_unregistered SEI before each encoded frame. |
|
|
|
Deblocking filter on/off and tc/beta offsets (−6 to +6). |
Runtime only — available only after CMD_VIDEO_APPLY. These have no init-time equivalent in the open command.
CMD |
API function |
Description |
|---|---|---|
|
|
Force the next encoded frame to be an I-frame. |
|
|
Cyclic Intra Refresh: continuously refresh a rotating band of CTBs instead of a full I-frame. |
|
|
Region of Interest: per-region QP delta for up to |
|
|
Configure an OSD overlay (position, size, alpha, YUV buffer pointer). |
|
|
Disable an OSD overlay by hardware index. |
|
|
Stop and close the encoder stream. |
|
|
Bulk update or read rate-control extension fields. Set |
|
|
Bulk update or read coding-control fields. Set |
Terms used in this section
RC: Rate control. Encoder logic that controls bitrate and quality.QP: Quantisation parameter. Lower QP usually means higher quality and larger frame size.GOP: Group of pictures. In this document it mainly refers to the I-frame interval.SPS/PPS/VUI: Bitstream header/signaling data used by decoders to interpret H.264/H.265 streams.HRD/CPB: Decoder buffering and bitstream timing model.CIR/ROI: Coding-control features that can be updated through the encoder coding-control path when the SDK exposes a runtime helper for them.
For media example usage, see Media Example .