This chapter introduces the GK7206 video encoding sample, sample_venc. It covers the full encoding feature set: H.265/H.264/MJPEG encoding, RTSP streaming, several rate-control modes, QP Map, ROI, and JPEG snapshots.
The source lives in sample/venc/ in the SDK. It is a reference template for video encoding and streaming applications.
Important (updated 2026-07-24)
The
sample_vencsource has been changed: all save paths moved from"."to"/sd_card"(8 places in total). You can now run it from any directory and it writes straight to /sd_card — nocd /sd_cardneeded. The prerequisite is that the SD card is mounted at/sd_card.
/sd_card| Parameter | Value |
|---|---|
Codecs |
H.265, H.264, MJPEG, JPEG |
Resolution |
from the sensor configuration (e.g. 2560x1440) |
Frame rate |
set 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 use |
high (a sensor is required) |
| index | Name | Command | Expected result (pass) | Possible failure cause |
|---|---|---|---|---|
| 0 | low-latency ring buffer | ./sample_venc 0 |
prints rtsp://<ip>:554/livestream/0 and .../1; any key captures a snapshot |
output written to /tmp -> Killed (OOM) |
| 1 | main + sub stream | ./sample_venc 1 |
the same two RTSP streams | same as above |
| 2 | qpmap | ./sample_venc 2 |
qpmap-encoded RTSP stream | sensor/VB failure |
| 3 | roi | ./sample_venc 3 |
ROI-encoded RTSP stream | same as above |
| 4 | mjpeg+snap | ./sample_venc 4 |
MJPEG stream plus key-press JPEG capture | same as above |
| 5 | snapshot zoom | ./sample_venc 5 |
split-and-zoom snapshot encoding | same as above |
| file | YUV -> bitstream | ./sample_venc /sd_card/in.yuv 1920 1080 h264 |
a bitstream file is produced | wrong YUV file or format |
sample/venc/
├── Makefile # build script
└── sample_venc.c # main program
Before building this application, make sure the following are ready:
# enter the sample directory
cd <SDK_PATH>/sample
# build the venc sample
make -C venc clean && make -C venc
Or build it from the top level:
make -C sample all
# mount the SD card
mkdir -p /sd_card
mount -t vfat /dev/mmcblk1p1 /sd_card
# transfer to the board over SCP
scp sample/venc/sample_venc root@<board-IP>:/sd_card/
# or download it over TFTP
tftp -g -r sample_venc <board-IP>
Note
The SD card must be mounted at
/sd_card, otherwise the program cannot save the snapshot files.
# make it executable
chmod +x /sd_card/sample_venc
# run it (index 0: low-latency ring buffer)
./sample_venc 0
# interactively choose the rate-control mode
c # choose CBR
# interactively choose the GOP mode
0 # choose NORMALP
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!
Choose the rate-control mode interactively:
please input choose rc mode!
c) cbr.
v) vbr.
a) avbr.
f) fixQp
c
Choose the GOP mode interactively:
please input choose gop mode!
0) NORMALP
1) SMARTP
0
Success marker:
rtsp://<ip>:554/livestream/0 and livestream/1[venc] save path = /sd_card confirms the save pathSC465SL_27MInput_MIPI_4lane_12bit_30fps_2560x1440_linear init success!---press 'q' to exit or any other key to capture pic--- appearsFixed vs variable output
- Fixed: sensor model (SC465SL), resolution (2560x1440), frame rate (25/30 fps), MIPI rate (864), save-path notice
- Variable: the IP address in the RTSP URL (depends on the board's network configuration)
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 marker: two RTSP stream URLs are printed, main stream (0) and sub stream (1).
Fixed vs variable output
- Fixed: sensor model, resolution, frame rate, MIPI rate, save-path notice
- Variable: the IP address in the RTSP URL, and the prompt text (
---press 'q' to exitvs---------------press any key to exit!---------------)
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 marker: qpmap initialization succeeds and the RTSP URL is printed.
Fixed vs variable output
- Fixed: sensor model, resolution, frame rate, MIPI rate, save-path notice
- Variable: the IP address in the RTSP URL
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 marker: roi initialization succeeds and the RTSP URL is printed.
Fixed vs variable output
- Fixed: sensor model, resolution, frame rate, MIPI rate, save-path notice
- Variable: the IP address in the RTSP URL
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 marker: the MJPEG stream URL is printed and pressing a key captures a JPEG image.
Fixed vs variable output
- Fixed: sensor model, resolution, frame rate, MIPI rate, save-path notice
- Variable: none — this mode prints no RTSP URL (it does not stream over RTSP)
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 marker: the snapshot split-and-zoom information and the RTSP URL are printed.
Fixed vs variable output
- Fixed: sensor model, resolution, frame rate, MIPI rate, interactive prompt
- Variable: none — this mode prints no RTSP URL (it does not stream over RTSP)
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.264
Success marker: a bitstream file is produced, such as in.264, in.265, or in.mjpg.
open file[./chn2_snap_0.jpg] err!
Cause: the SD card is not mounted, or the path is wrong. Fix: make sure the card is mounted at /sd_card.
Killed
Cause: out of memory (OOM) because the output went to the /tmp ramdisk. Fix: mount the SD card and check that /sd_card is writable.
Pull the stream with VLC or ffplay:
# pull the main stream
ffplay rtsp://<board-IP>:554/livestream/0
# pull the sub stream
ffplay rtsp://<board-IP>:554/livestream/1
This application uses the following architecture:
Sensor -> VI -> VPSS -> VENC -> RTSP streaming
↓
MJPEG stream
↓
JPEG snapshot
// Step 1: system initialization (configure the VB pools)
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(...);
Streaming uses the built-in live_rtsp_server library:
// create the RTSP session
sample_comm_livestream_create(venc_chn, livestream_type);
// start the RTSP service
sample_comm_livestream_start();
Snapshots are triggered by a key press:
// wait for user input
c = getchar();
if (c != 'q') {
// generate a JPEG snapshot
sample_venc_snap_process(venc_chn, snap_cnt);
// print the saved path
printf("[venc] save path = /sd_card/chn2_snap_%d.jpg\n", snap_cnt);
}
Eight 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:
start_get_stream(): 5 placescapture_jpeg(): 2 placessplicing function: 1 placeThe sample lets you pick the rate-control mode interactively:
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;
}
}
// 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;
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;
}
| Problem | Likely cause | Fix |
|---|---|---|
Killed (OOM) |
output written to the /tmp ramdisk | make sure the SD card is mounted at /sd_card |
open file[./chn2_snap_0.jpg] err! |
the old "." path is on a read-only rootfs |
update to the current source and rebuild |
| Cannot pull the RTSP stream | sensor initialization failed | check the sensor connection and configuration |
| Encoding fails | not enough VB memory | adjust the VB pool configuration |
| Snapshot fails | JPEG channel not configured | check the VENC channel configuration |
The board has 128 MB of DDR, of which Linux can use about 26 MB. Video encoding is memory hungry, so:
/sd_cardsync; echo 3 > /proc/sys/vm/drop_cachesTip
The save path is hard-coded to
/sd_card, so there is no need tocd /sd_card. The card must still be mounted first.