Video Encoding Application
This chapter describes the GK7206 video encoding application example — sample_venc. The application demonstrates complete video encoding functionality, including H.265/H.264/MJPEG encoding, RTSP streaming, multiple rate control modes, QP Map, ROI, JPEG snapshots, and other advanced features.
The application source code is located in the SDK directory sample/venc/. It serves as a reference template for developing video encoding and streaming applications.
Important note (updated 2026-07-24)
The sample_venc source code has been modified so that all save paths changed from "." to "/sd_card" (8 places in total). It now writes to /sd_card directly no matter which directory it is run from — no cd /sd_card needed. The prerequisite is that the SD card is mounted at /sd_card.
1 Application Overview
1.1 Features
- Multiple encoding formats: H.265, H.264, MJPEG, JPEG
- Multiple stream modes: main stream + sub stream, MJPEG stream + JPEG snapshot
- Multiple rate control modes: CBR, VBR, AVBR, FixQP
- RTSP streaming: built-in RTSP server for real-time stream pushing
- Advanced encoding features:
- QP Map (quantization parameter map)
- ROI (region of interest encoding)
- Ring-buffer low-latency encoding
- JPEG snapshot split-and-zoom encoding
- File encoding: supports encoding a YUV file into a stream file
- Automatic save path: all output files are saved to
/sd_cardautomatically
1.2 Technical Specifications
| Parameter | Value |
|---|---|
Encoding formats | H.265, H.264, MJPEG, JPEG |
Resolution | Per the sensor configuration (e.g. 2560×1440) |
Frame rate | Determined by the sensor (usually 30 FPS) |
Rate control modes | CBR, VBR, AVBR, FixQP |
GOP modes | NORMALP, SMARTP |
RTSP port | 554 |
Output path | /sd_card (hard-coded in the source) |
Memory footprint | Relatively high (requires a sensor) |
1.3 Test Case List
| index | Name | Test command | Expected behavior (success) | Possible failure cause |
|---|---|---|---|---|
| 0 | Low-latency ring buffer | ./sample_venc 0 | Prints rtsp://<ip>:554/livestream/0, .../1; any key other than q captures a picture | Output written to /tmp → Killed (OOM) |
| 1 | Main + sub stream | ./sample_venc 1 | Same dual RTSP streams as above | Same as above |
| 2 | qpmap | ./sample_venc 2 | qpmap encoding over RTSP | sensor/VB failure |
| 3 | roi | ./sample_venc 3 | roi encoding over RTSP | Same as above |
| 4 | mjpeg+snap | ./sample_venc 4 | MJPEG stream + key-triggered JPEG capture | Same as above |
| 5 | snap zoom | ./sample_venc 5 | snap split-and-zoom encoding | Same as above |
| File | YUV→stream | ./sample_venc /sd_card/in.yuv 1920 1080 h264 | Generates an encoded stream file | Wrong YUV file/format |
1.4 Directory Structure
sample/venc/
├── Makefile # Build script
└── sample_venc.c # Main program2 Build and Deployment
2.1 Prerequisites
Before building this application, make sure the following preparations have been completed:
- SDK environment is set up: follow SDK Compilation to set up the cross-compilation toolchain and SDK configuration
- Sensor is connected: an SC465SL or compatible image sensor must be connected
2.2 Build the Application
# Enter the sample directory
cd <SDK_PATH>/sample
# Build the venc sample
make -C venc clean && make -C vencOr build from the top level:
make -C sample all2.3 Deploy to the Board
# Mount the SD card
mkdir -p /sd_card
mount -t vfat /dev/mmcblk1p1 /sd_card
# Transfer to the development board via SCP
scp sample/venc/sample_venc root@<board IP>:/sd_card/
# Or download via TFTP
tftp -g -r sample_venc <board IP>Warning
The SD card must be mounted at /sd_card, otherwise the program cannot save the captured pictures.
2.4 Run the Application
# Add execute permission
chmod +x /sd_card/sample_venc
# Run (index 0: low-latency ring buffer)
./sample_venc 0
# Interactively select the rate control mode
c # Select CBR
# Interactively select the GOP mode
0 # Select NORMALP2.5 Expected Output
Index 0: Low-latency ring buffer
Startup flow:
please input choose rc mode!
c) cbr.
v) vbr.
a) avbr.
f) fixQp
c
please input choose gop mode!
0) NORMALP.
1) SMARTP.
0
[SENSOR][Func]:sc465sl_set_slave_addr [Line]:1637 [Info]:Sensor dev [0] set slave addr 0x60 success.
[SENSOR][Func]:sc465sl_i2c_init [Line]:1664 [Info]:====== i2c[1] init success!=======
[SENSOR][Func]:sc465sl_set_wdr_mode [Line]:487 [Info]:linear mode
[sample_comm_isp_sensor_init]-368: sensor i2c_id = 1, clk_id = 1
[SENSOR][Func]:sc465sl_get_ae_common_default [Line]:858 [Info]:man_ratio_enable: 0
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 30.000000
[ISP]isp_init[1113]: isp[0] init success
[ISP]isp_run[771]: isp run.
[sample_comm_vi_start_dev]-1066: mipi_rate: 864.
[ISP]isp_start[503]: isp0 start.
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:952 [Info]:============================================================================
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:953 [Info]:=== SC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success! =
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:954 [Info]:============================================================================
rtsp://192.168.49.17:554/livestream/0
rtsp://192.168.49.17:554/livestream/1
[venc] save path = /sd_card (orig '.', readonly rootfs)
---press 'q' to exit or any other key to capture pic---
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 25.000000
^C[ISP]isp_stop[522]: isp0 stop.
[ISP]isp_exit[1183]: isp0 start exit
[ISP]isp_exit[1218]: isp0 exit success
[main]-1772: program exit normally!Interactive selection of the rate control mode:
please input choose rc mode!
c) cbr.
v) vbr.
a) avbr.
f) fixQp
cInteractive selection of the GOP mode:
please input choose gop mode!
0) NORMALP
1) SMARTP
0Success indicators:
- The RTSP addresses are displayed:
rtsp://<ip>:554/livestream/0andlivestream/1 [venc] save path = /sd_cardindicates the save path is correct- The sensor initialized successfully:
SC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success! - The interactive prompt
---press 'q' to exit or any other key to capture pic---is displayed
Fixed and variable parts
- Fixed parts: the sensor model (SC465SL), resolution (2560x1440), frame rates (25/30 fps), MIPI rate (864), and save path hint
- Variable parts: the IP address in the RTSP URLs (varies with the board's network configuration)
Index 1: Main + sub stream
Expected output:
please input choose rc mode!
c) cbr.
v) vbr.
a) avbr.
f) fixQp
c
please input choose gop mode!
0) NORMALP.
1) SMARTP.
0
[SENSOR][Func]:sc465sl_set_slave_addr [Line]:1637 [Info]:Sensor dev [0] set slave addr 0x60 success.
[SENSOR][Func]:sc465sl_i2c_init [Line]:1664 [Info]:====== i2c[1] init success!=======
[SENSOR][Func]:sc465sl_set_wdr_mode [Line]:487 [Info]:linear mode
[sample_comm_isp_sensor_init]-368: sensor i2c_id = 1, clk_id = 1
[SENSOR][Func]:sc465sl_get_ae_common_default [Line]:858 [Info]:man_ratio_enable: 0
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 30.000000
[ISP]isp_init[1113]: isp[0] init success
[ISP]isp_run[771]: isp run.
[sample_comm_vi_start_dev]-1066: mipi_rate: 864.
[ISP]isp_start[503]: isp0 start.
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:952 [Info]:============================================================================
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:953 [Info]:=== SC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success! =
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:954 [Info]:============================================================================
rtsp://192.168.49.17:554/livestream/0
rtsp://192.168.49.17:554/livestream/1
[venc] save path = /sd_card (orig '.', readonly rootfs)
---------------press any key to exit!---------------
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 25.000000
^C[ISP]isp_stop[522]: isp0 stop.
[ISP]isp_exit[1183]: isp0 start exit
[ISP]isp_exit[1218]: isp0 exit success
[main]-1772: program exit normally!Success indicator: two RTSP stream addresses are displayed — the main stream (0) and the sub stream (1).
Fixed and variable parts
- Fixed parts: the sensor model, resolution, frame rates, MIPI rate, and save path hint
- Variable parts: the IP address in the RTSP URLs, and the interactive prompt (
---press 'q' to exitvs---------------press any key to exit!---------------)
Index 2: qpmap
Expected output:
please input choose gop mode!
0) NORMALP.
1) SMARTP.
0
[SENSOR][Func]:sc465sl_set_slave_addr [Line]:1637 [Info]:Sensor dev [0] set slave addr 0x60 success.
[SENSOR][Func]:sc465sl_i2c_init [Line]:1664 [Info]:====== i2c[1] init success!=======
[SENSOR][Func]:sc465sl_set_wdr_mode [Line]:487 [Info]:linear mode
[sample_comm_isp_sensor_init]-368: sensor i2c_id = 1, clk_id = 1
[SENSOR][Func]:sc465sl_get_ae_common_default [Line]:858 [Info]:man_ratio_enable: 0
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 30.000000
[ISP]isp_init[1113]: isp[0] init success
[ISP]isp_run[771]: isp run.
[sample_comm_vi_start_dev]-1066: mipi_rate: 864.
[ISP]isp_start[503]: isp0 start.
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:952 [Info]:============================================================================
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:953 [Info]:=== SC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success! =
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:954 [Info]:============================================================================
rtsp://192.168.49.17:554/livestream/0
rtsp://192.168.49.17:554/livestream/1
[venc] save path = /sd_card (orig '.', readonly rootfs)
---------------press any key to exit!---------------
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 25.000000
^C[ISP]isp_stop[522]: isp0 stop.
[ISP]isp_exit[1183]: isp0 start exit
[ISP]isp_exit[1218]: isp0 exit success
[main]-1772: program exit normally!Success indicator: qpmap initializes successfully and the RTSP addresses are displayed.
Fixed and variable parts
- Fixed parts: the sensor model, resolution, frame rates, MIPI rate, and save path hint
- Variable parts: the IP address in the RTSP URLs
Index 3: roi
Expected output:
please input choose rc mode!
c) cbr.
v) vbr.
a) avbr.
f) fixQp
c
please input choose gop mode!
0) NORMALP.
1) SMARTP.
0
[SENSOR][Func]:sc465sl_set_slave_addr [Line]:1637 [Info]:Sensor dev [0] set slave addr 0x60 success.
[SENSOR][Func]:sc465sl_i2c_init [Line]:1664 [Info]:====== i2c[1] init success!=======
[SENSOR][Func]:sc465sl_set_wdr_mode [Line]:487 [Info]:linear mode
[sample_comm_isp_sensor_init]-368: sensor i2c_id = 1, clk_id = 1
[SENSOR][Func]:sc465sl_get_ae_common_default [Line]:858 [Info]:man_ratio_enable: 0
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 30.000000
[ISP]isp_init[1113]: isp[0] init success
[ISP]isp_run[771]: isp run.
[sample_comm_vi_start_dev]-1066: mipi_rate: 864.
[ISP]isp_start[503]: isp0 start.
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:952 [Info]:============================================================================
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:953 [Info]:=== SC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success! =
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:954 [Info]:============================================================================
rtsp://192.168.49.17:554/livestream/0
rtsp://192.168.49.17:554/livestream/1
[venc] save path = /sd_card (orig '.', readonly rootfs)
---------------press any key to exit!---------------
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 25.000000
^C[ISP]isp_stop[522]: isp0 stop.
[ISP]isp_exit[1183]: isp0 start exit
[ISP]isp_exit[1218]: isp0 exit success
[main]-1772: program exit normally!Success indicator: roi initializes successfully and the RTSP addresses are displayed.
Fixed and variable parts
- Fixed parts: the sensor model, resolution, frame rates, MIPI rate, and save path hint
- Variable parts: the IP address in the RTSP URLs
Index 4: mjpeg+snap
Expected output:
please input choose rc mode!
c) cbr.
v) vbr.
a) avbr.
f) fixQp
c
[SENSOR][Func]:sc465sl_set_slave_addr [Line]:1637 [Info]:Sensor dev [0] set slave addr 0x60 success.
[SENSOR][Func]:sc465sl_i2c_init [Line]:1664 [Info]:====== i2c[1] init success!=======
[SENSOR][Func]:sc465sl_set_wdr_mode [Line]:487 [Info]:linear mode
[sample_comm_isp_sensor_init]-368: sensor i2c_id = 1, clk_id = 1
[SENSOR][Func]:sc465sl_get_ae_common_default [Line]:858 [Info]:man_ratio_enable: 0
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 30.000000
[ISP]isp_init[1113]: isp[0] init success
[ISP]isp_run[771]: isp run.
[sample_comm_vi_start_dev]-1066: mipi_rate: 864.
[ISP]isp_start[503]: isp0 start.
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:952 [Info]:============================================================================
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:953 [Info]:=== SC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success! =
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:954 [Info]:============================================================================
[venc] save path = /sd_card (orig '.', readonly rootfs)
---press 'q' to exit or any other key to capture pic---
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 25.000000
^C[ISP]isp_stop[522]: isp0 stop.
[ISP]isp_exit[1183]: isp0 start exit
[ISP]isp_exit[1218]: isp0 exit success
[main]-1772: program exit normally!Success indicator: the MJPEG stream address is displayed and JPEG pictures can be captured by pressing keys.
Fixed and variable parts
- Fixed parts: the sensor model, resolution, frame rates, MIPI rate, and save path hint
- Variable parts: no RTSP URL (this mode does not output an RTSP stream)
Index 5: snap zoom
Expected output:
[SENSOR][Func]:sc465sl_set_slave_addr [Line]:1637 [Info]:Sensor dev [0] set slave addr 0x60 success.
[SENSOR][Func]:sc465sl_i2c_init [Line]:1664 [Info]:====== i2c[1] init success!=======
[SENSOR][Func]:sc465sl_set_wdr_mode [Line]:487 [Info]:linear mode
[sample_comm_isp_sensor_init]-368: sensor i2c_id = 1, clk_id = 1
[SENSOR][Func]:sc465sl_get_ae_common_default [Line]:858 [Info]:man_ratio_enable: 0
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 30.000000
[ISP]isp_init[1113]: isp[0] init success
[ISP]isp_run[771]: isp run.
[sample_comm_vi_start_dev]-1066: mipi_rate: 864.
[ISP]isp_start[503]: isp0 start.
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:952 [Info]:============================================================================
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:953 [Info]:=== SC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success! =
[SENSOR][Func]:sc465sl_4lane_linear_2560x1440_init [Line]:954 [Info]:============================================================================
---press 'q' to exit or any other key to capture pic---
[SENSOR][Func]:sc465sl_calc_fps [Line]:1358 [Info]:sc465sl set fps = 25.000000
^C[ISP]isp_stop[522]: isp0 stop.
[ISP]isp_exit[1183]: isp0 start exit
[ISP]isp_exit[1218]: isp0 exit success
[main]-1772: program exit normally!Success indicator: the snap split-and-zoom encoding information and the RTSP addresses are displayed.
Fixed and variable parts
- Fixed parts: the sensor model, resolution, frame rates, MIPI rate, and interactive prompt
- Variable parts: no RTSP URL (this mode does not output an RTSP stream)
File encoding mode
Command: ./sample_venc /sd_card/in.yuv 1920 1080 h264
Expected output:
sample_venc file encode running
input file: /sd_card/in.yuv
width: 1920
height: 1080
codec: h264
...
encode completed, output: /sd_card/in.264Success indicator: an encoded stream file is generated, such as in.264, in.265, or in.mjpg.
Error cases
open file[./chn2_snap_0.jpg] err!Cause: the SD card is not mounted or the path is wrong Solution: confirm the SD card is mounted at /sd_card
KilledCause: out of memory (OOM); the output was written to the /tmp memory disk Solution: confirm the SD card is mounted and check that /sd_card is writable
2.6 Access from a Browser/Player
Use VLC or ffplay to pull the stream:
# Pull the main stream
ffplay rtsp://<board IP>:554/livestream/0
# Pull the sub stream
ffplay rtsp://<board IP>:554/livestream/13 Internal Execution Logic in Detail
3.1 Application Architecture
The application uses the following architecture:
Sensor → VI → VPSS → VENC → RTSP streaming
↓
MJPEG stream
↓
JPEG snapshot3.2 Video Pipeline Initialization Flow
// Step 1: System initialization (configures the VB memory pool)
sample_comm_sys_init(&sys_config);
// Step 2: ISP initialization
sample_comm_isp_init();
// Step 3: Start VI
sample_comm_vi_start(...);
// Step 4: Start VPSS
sample_comm_vpss_start(...);
// Step 5: Start VENC
sample_comm_venc_start(...);
// Step 6: Bind the modules
xmedia_bind_vi_to_vpss(...);
xmedia_bind_vpss_to_venc(...);
// Step 7: RTSP streaming
sample_comm_livestream_create(...);3.3 RTSP Streaming Implementation
RTSP streaming uses the built-in live_rtsp_server library:
// Create an RTSP session
sample_comm_livestream_create(venc_chn, livestream_type);
// Start the RTSP service
sample_comm_livestream_start();3.4 Snapshot Function
The snapshot function is triggered by key presses:
// Wait for user input
c = getchar();
if (c != 'q') {
// Generate a JPEG snapshot
sample_venc_snap_process(venc_chn, snap_cnt);
// Print the save path
printf("[venc] save path = /sd_card/chn2_snap_%d.jpg\n", snap_cnt);
}3.5 Source Code Changes (2026-07-24)
8 save paths in the source changed from "." to "/sd_card":
// Original code (line comment kept)
// snprintf(snap_path, sizeof(snap_path), "./chn%d_snap_%d.jpg", chn, cnt);
// New code
snprintf(snap_path, sizeof(snap_path), "/sd_card/chn%d_snap_%d.jpg", chn, cnt);
printf("[venc] save path = %s\n", snap_path);Where the changes are located:
start_get_stream()function: 5 placescapture_jpeg()function: 2 placessplicingfunction: 1 place
4 Key Programming Points
4.1 Selecting the Rate Control Mode
The application provides interactive selection of the rate control mode:
sample_rc sample_venc_get_rc_mode(void)
{
char c;
printf("please input choose rc mode!\n");
printf("\t c) cbr.\n");
printf("\t v) vbr.\n");
printf("\t a) avbr.\n");
printf("\t f) fixQp\n");
c = getchar();
switch(c) {
case 'c': return SAMPLE_RC_CBR;
case 'v': return SAMPLE_RC_VBR;
case 'a': return SAMPLE_RC_AVBR;
case 'f': return SAMPLE_RC_FIXQP;
default: goto begin_get;
}
}4.2 Encoding Channel Configuration
// H.265 main stream
venc_chn_attr[0].type = XMEDIA_PT_H265;
venc_chn_attr[0].max_width = 2560;
venc_chn_attr[0].max_height = 1440;
venc_chn_attr[0].rc_mode = VENC_RC_MODE_H265CBR;
// H.264 sub stream
venc_chn_attr[1].type = XMEDIA_PT_H264;
venc_chn_attr[1].max_width = 640;
venc_chn_attr[1].max_height = 480;
venc_chn_attr[1].rc_mode = VENC_RC_MODE_H264CBR;
// JPEG snapshot
venc_chn_attr[2].type = XMEDIA_PT_JPEG;
venc_chn_attr[2].max_width = 2560;
venc_chn_attr[2].max_height = 1440;4.3 Error Handling
Check the return value of every API call:
ret = sample_comm_sys_init(&sys_config);
if (ret != XMEDIA_SUCCESS) {
printf("sys init failed!\n");
goto exit0;
}
ret = sample_comm_isp_init();
if (ret != XMEDIA_SUCCESS) {
printf("isp init failed!\n");
goto exit1;
}5 Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
Killed (OOM) | Output written to the /tmp memory disk | Confirm the SD card is mounted at /sd_card |
open file[./chn2_snap_0.jpg] err! | Old source with the "." path on a read-only rootfs | Update to the new source and rebuild |
| Cannot pull the RTSP stream | Sensor initialization failed | Check the sensor connection and configuration |
| Encoding failure | Insufficient VB memory | Adjust the VB pool configuration |
| Snapshot failure | JPEG channel not configured | Check the VENC channel configuration |
6 Memory and Path Management
6.1 Memory Limits
The board has 128 MB of DDR in total, of which about 26 MB is available to Linux. Video encoding uses a lot of memory, so it is recommended to:
- Mount the SD card at
/sd_card - Write all output files to the SD card
- Free memory before testing:
sync; echo 3 > /proc/sys/vm/drop_caches
6.2 Path Management
Tips
The save path is hard-coded to /sd_card in the source, so there is no need to cd /sd_card. But the SD card must be mounted first.
