Using the rocDecode RocVideoDecoder#
rocDecode provides two ways of decoding a video stream: using the rocDecode RocVideoDecoder on GPU or using the FFmpeg decoder on CPU.
This topic covers how to decode a video stream using the RocVideoDecoder class in |roc_video_dec|_. The RocVideoDecode class provides high-level calls to the core APIs in the api
folder of the rocDecode GitHub repository. For information about the core APIs, see Using the rocDecode core APIs.
The RocVideoDecoder takes a demultiplexed coded picture as input. The picture can be demultiplexed from a video stream using the FFmpeg demultiplexer.
To use the rocDecode video decoder, import the roc_video_dec.h
header file and instantiate RocVideoDecoder
.
The RocVideoDecoder
constructor takes the following parameters:
Parameter |
Description |
Default |
---|---|---|
|
|
0 |
|
|
0, OUT_SURFACE_MEM_DEV_INTERNAL |
|
|
No default, a value must be provided |
|
|
|
|
|
No cropping |
|
|
|
|
|
0, no delay in displaying the frames |
|
|
0 |
|
|
0 |
|
|
1000 |
For example, from videodecode.cpp
:
RocVideoDecoder viddec(device_id, mem_type, rocdec_codec_id, b_force_zero_latency, p_crop_rect, b_extract_sei_messages, disp_delay);
RocVideoDecoder
will create a parser and a decoder, and initialize HIP on the device.
The same decoder instance is reused when there’s a change to the video resolution without a change in the codec.
The decoder maintains a pool of frame buffers for decoded images that haven’t yet been displayed or processed. When the video stream resolution changes, the existing frame buffers in the buffer pool are deleted. The decoder is then reconfigured for the new resolution and new buffers are created.
To prevent the remaining frames in the buffers from being deleted along with the buffers, a callback function can be defined to consume the remaining frames.
The ReconfigParams_t
struct stores information on how to handle the reconfiguration. A callback, a user-defined flush mode, and a user-defined struct are passed to ReconfigParams_t
. The reconfiguration parameters are then passed to the decoder using SetReconfigParams
.
The reconfiguration parameters need to be defined prior to entering the decoding loop.
For example, the reconfiguration structs are defined in common.h
in the rocDecode samples and then used in videodecode.cpp
:
typedef enum ReconfigFlushMode_enum {
RECONFIG_FLUSH_MODE_NONE = 0, /**< Just flush to get the frame count */
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 1, /**< The remaining frames will be dumped to file in this mode */
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = 2, /**< Calculate the MD5 of the flushed frames */
} ReconfigFlushMode;
typedef struct ReconfigDumpFileStruct_t {
bool b_dump_frames_to_file;
std::string output_file_name;
void *md5_generator_handle;
} ReconfigDumpFileStruct;
reconfig_params.p_fn_reconfigure_flush = ReconfigureFlushCallback;
reconfig_user_struct.b_dump_frames_to_file = dump_output_frames;
reconfig_user_struct.output_file_name = output_file_path;
if (dump_output_frames) {
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
} else {
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
}
reconfig_params.p_reconfig_user_struct = &reconfig_user_struct;
viddec.SetReconfigParams(&reconfig_params);
In the decode loop, the demultiplexed coded picture is passed to DecodeFrame
. Once the frame is decoded and processed, it is released with ReleaseFrame
.