Video Decoding, Processing, and Display (NVR Scenario)
This section describes the typical process, key APIs, and precautions for video processing in the NVR scenario.
The network video recorder (NVR) refers to the storage and forwarding of the network video system. The NVR works with the network camera to record, store, and forward videos audios. In addition, the NVR provides the local human-machine interface, video decoding, video display, and voice intercom functions.
NVR Video Scenario
This section describes the NVR service processing flow, which includes:
- Video decoding and display process
The video decoding and display process involves the VDEC, VPSS, VO, HDMI, and enhanced functions such as Region Management Function, TDE Graphics Drawing, and HiFB for Managing Overlaid Graphics Layers.
Call hi_mpi_sys_bind to bind the VDEC channel with the VPSS group, and bind the VPSS group with the VO device. In this way, data is automatically transferred from the VDEC to the VPSS, and from the VPSS to the VO device. The VO module can automatically read the output data of the HiFB by using underlying registers.
If the TDE, HiFB, and VO are not in the same app process, start the VO process first, initialize the media data processing system by calling hi_mpi_sys_init in the TDE and HiFB process, and deinitialize the media data processing system by calling hi_mpi_sys_exit before exiting the process.
- Intelligent analysis process of video decoding
The intelligent analysis process of video decoding involves the VDEC, VPSS, intelligent analysis module for model inference, and enhanced functions such as the Region module. For details about the API call sequence of the region management function, see Region Management Function.

Video Decoding and Display Process
The video decoding and display process involves the VDEC, VPSS, VO, HDMI, and enhanced functions such as Region Management Function, TDE Graphics Drawing, and HiFB for Managing Overlaid Graphics Layers.
The API call sequence for starting and running the NVR video decoding and display service is as follows:
- Call hi_mpi_sys_init to initialize the media system.
- Create VDEC channels as required and instruct the decoder to start receiving streams.
- Call hi_mpi_vdec_create_chn to create a channel.
- Call hi_mpi_vdec_get_chn_param to obtain channel attributes, set channel attributes as required, and then call hi_mpi_vdec_set_chn_param to set channel parameters.
- Before decoding, call hi_mpi_vdec_start_recv_stream to instruct the decoder to start receiving streams.
- Create multiple VPSS groups as required and enable them.
- Call hi_mpi_vpss_create_grp to create VPSS groups.
- Call hi_mpi_vpss_start_grp to enable the VPSS groups.
- Call hi_mpi_vpss_set_chn_attr to set the channel attributes. When working with the VO module is needed, set the channel attribute to the auto mode.
- Call hi_mpi_vpss_enable_chn to enable the VPSS channel.
- Call hi_mpi_sys_bind to bind the VDEC channel to a VPSS group. The output data decoded by the VDEC is directly sent to the corresponding VPSS group for further processing.
- For example, a single monitor outputs four channels of videos. The following table lists the binding information.
VDEC Channel
VPSS Group
VO Channel
VO Video Layer
VO device ID
HDMI ID
1
1
1
Video layer
VHD0
0
HDMI0
2
2
2
3
3
3
4
4
4
- For example, two monitors each outputs four channels of videos. The following table lists the binding information.
VDEC Channel
VPSS Group
VO Channel
VO Video Layer
VO Device ID
HDMI ID
1
1
1
Video layer
VHD0
0
HDMI0
2
2
2
3
3
3
4
4
4
5
5
5
Video layer
VHD1
1
HDMI1
6
6
6
7
7
7
8
8
8
- For example, a single monitor outputs four channels of videos. The following table lists the binding information.
- Enable the VO device and VO channel (create multiple VO channels as required).
- Call hi_mpi_vo_set_pub_attr to set the attributes of the display device, and call hi_mpi_vo_enable to enable the display device.
- Call hi_mpi_vo_set_video_layer_attr to set the attributes of the display video layer, and call hi_mpi_vo_enable_video_layer to enable the display video layer.
- Call hi_mpi_vo_set_chn_attr to set the attributes of the display channel, and call hi_mpi_vo_enable_chn to enable the display channel.
- Initialize HDMI peripherals.
- Call hi_mpi_sys_bind to bind a VPSS group to a VO channel. The output data processed by the VPSS is directly sent to the corresponding VO channel for further processing.
For details about the binding information, see 4.
- Call hi_mpi_vdec_send_stream repeatedly to send each frame of decoded streams.
Note:
- After a VDEC channel is bound to a VPSS group (see 4), you can set vdec_pic_info to NULL when call hi_mpi_vdec_send_stream to send streams. The decoding result data is directly sent to the corresponding VPSS group for further processing. You cannot obtain the decoding result data by calling hi_mpi_vdec_get_frame.
- Video decoding supports the playback mode and the preview mode. You can call hi_mpi_vdec_get_display_mode and hi_mpi_vdec_set_display_mode to query and set the mode. Playback control is supported when the playback mode is required for recording playback.
The API call sequence for releasing resources of the NVR video decoding and display service is as follows:
- Call hi_mpi_sys_unbind to unbind the VO channel from the VPSS group.
- Call hi_mpi_sys_unbind to unbind the VPSS group from the VDEC channel.
- Release HDMI peripheral resources.
- Release the VO device and channel resources.
- Destroy the VPSS group.
- Destroy the VDEC channel.
- Call hi_mpi_sys_exit to deinitialize the media data processing system.
Intelligent Analysis Process of Video Decoding
The intelligent analysis process of video decoding involves the VDEC, VPSS, intelligent analysis module for model inference, and enhanced functions such as the Region module. For details about the API call sequence of the region management function, see Region Management Function.
The process of starting and running the video decoding intelligent analysis service is as follows:
- Call hi_mpi_sys_init to initialize the media system.
- Create VDEC channels as required and instruct the decoder to start receiving streams.
- Call hi_mpi_vdec_create_chn to create a channel.
- Call hi_mpi_vdec_get_chn_param to obtain channel attributes, set channel attributes as required, and then call hi_mpi_vdec_set_chn_param to set channel parameters.
- Before decoding, call hi_mpi_vdec_start_recv_stream to instruct the decoder to start receiving streams.
- Create multiple VPSS groups as required and enable them.
- Call hi_mpi_sys_bind to bind the VDEC channel to a VPSS group. The output data decoded by the VDEC is directly sent to the corresponding VPSS group for further processing.
For details about the binding information, see 4.
- Call hi_mpi_vdec_send_stream repeatedly to send each frame of decoded streams.
Note:
After a VDEC channel is bound to a VPSS group (see 4), you can set vdec_pic_info to NULL when call hi_mpi_vdec_send_stream to send streams. The decoding result data is directly sent to the corresponding VPSS group for further processing. You cannot obtain the decoding result data by calling hi_mpi_vdec_get_frame.
- Call hi_mpi_vpss_get_chn_frame to obtain the image data processed by the VPSS and send the data for model inference (for details, see Model Management). After the inference is complete, call hi_mpi_vpss_release_chn_frame to release a frame of channel image.
Note:
When there are multiple channels, you can obtain the handle to a specified channel by calling hi_mpi_vpss_get_chn_fd, and wait for the processing result by calling the epoll interface (for details, see hi_mpi_sys_create_epoll). After the VPSS completes processing, the epoll is automatically woken up. In this case, you can obtain the processed image data by calling hi_mpi_vpss_get_chn_frame.
If the size and format of the image processed by the VPSS do not meet the requirements before being sent for inference, the image needs to be further processed by the VPC and AIPP functions of the DVPP. For details, see the descriptions of the VPC and AIPP in Overview.
The API call sequence for releasing resources of the NVR video decoding intelligent analysis service is as follows:
- Call hi_mpi_sys_unbind to unbind the VPSS group from the VDEC channel.
- Destroy the VPSS group.
- Destroy the VDEC channel.
- Call hi_mpi_sys_exit to deinitialize the media data processing system.
Region Management Function
The overlaid on screen displays (OSDs) and color blocks in a video are called regions. The Region module is used to manage region resources in a unified manner, and display specific information (such as the channel ID and timestamp) on a video, or fill color blocks in a video for covering.
The Region module must be used together with the VPSS module, and the VPSS group and VPSS associated with the Region module must have been created. The API call sequence is as follows:

- Initialize.
- Modify region information.
- Set the channel display attributes of a region.
- Set the canvas information of the region.
- Destroy allocations.
TDE Graphics Drawing
The TDE is a two-dimensional graphics acceleration engine. It uses hardware to provide fast graphics drawing functions for the On Screen Display (OSD) and Graphics User Interface (GUI). The functions include quick copy, quick color filling, and pattern filling. (Currently, only alpha blending is supported.)
- Start the TDE device by calling hi_tde_open.
- Create a TDE job by calling hi_tde_begin_job.
- Call the command execution APIs, such as hi_tde_quick_copy, hi_tde_quick_fill, and hi_tde_pattern_fill.
Before calling a command execution API, call int ioctl (int fd, FBIOGET_FSCREENINFO, fb_fix_screeninfo *fix) provided by the HiFB to obtain the user mode address of the display buffer as the memory address of the target bitmap. After the TDE job is complete, the data of the target bitmap is stored in the memory address as the input data of the HiFB.
- If a command fails to be added, call hi_tde_cancel_job to cancel the job. If a command is successfully added, call hi_tde_end_job to submit the job.
- Wait until the TDE job is complete.
Currently, hi_tde_wait_for_done is provided to wait for the completion of a specified TDE job, and hi_tde_wait_all_done is provided to wait for the completion of all jobs on the current TDE device.
HiFB for Managing Overlaid Graphics Layers
The HiFB is used to manage overlaid graphics layers. It not only provides the basic functions of Linux framebuffer, but also provides extended functions such as modifying the display start position of a graphics layer and inter-layer alpha.
- Open the FB device by calling the open function. Device files fb0–fb4 correspond to graphics layers G0–G4. G0 and G1 are HD graphics layers, G2 is the cursor graphics layer, and G3 and G4 are SD graphics layers.
For details about the FB device, VO device, supported color formats, and resolution of each graphics layer, see Table 1.
- Pass the command code FBIOGET_VSCREENINFO by calling ioctl to obtain the basic attributes of the screen.
- Pass the command code FBIOPUT_VSCREENINFO by calling ioctl to set the basic attributes of the screen.
- Pass the command code FBIOGET_FSCREENINFO by calling ioctl to obtain the user mode address of the display buffer.
- Map the user-mode virtual address by calling mmap.
- The system calls ioctl to pass function-related command codes to set function attributes.
- Unmap the user-mode virtual address by calling munmap.
- Close the FB device by calling close.
If the HiFB works with the VO in the same process, you must disable the FB device after disabling the VO by calling hi_mpi_vo_disable.
If the HiFB and VO are not in the same process, stop the VO app process.