Using the rocDecode bitstream reader APIs#
2026-07-01
2 min read time
The rocDecode bitstream reader APIs are a simplified set of APIs that provide a way to use and test the decoder without relying on FFMpeg. The bitstream reader APIs can be used to extract and parse coded picture data from an elementary video stream for the decoder to consume.
Note
The bitstream reader APIs can only be used with elementary video streams and IVF container files.
The videodecoderaw.cpp sample demonstrates how to use the bitstream reader APIs, including how to create a bitstream reader and use it to extract picture data and pass it to the decoder:
RocdecBitstreamReader bs_reader = nullptr;
rocDecVideoCodec rocdec_codec_id;
int bit_depth;
if (rocDecCreateBitstreamReader(&bs_reader, input_file_path.c_str()) != ROCDEC_SUCCESS) {
std::cerr << "Failed to create the bitstream reader." << std::endl;
return 1;
}
[...]
# Decode loop:
do {
if (rocDecGetBitstreamPicData(bs_reader, &pvideo, &n_video_bytes, &pts) != ROCDEC_SUCCESS) {
std::cerr << "Failed to get picture data." << std::endl;
return 1;
}
[...]
n_frame_returned = viddec.DecodeFrame(pvideo, n_video_bytes, pkg_flags, pts, &decoded_pics);
}
The videodecoderaw.cpp example also demonstrates how to use the bitstream reader APIs to obtain the bit depth and codec of a stream:
if (rocDecGetBitstreamCodecType(bs_reader, &rocdec_codec_id) != ROCDEC_SUCCESS) {
std::cerr << "Failed to get stream codec type." << std::endl;
return 1;
}
[...]
if (rocDecGetBitstreamBitDepth(bs_reader, &bit_depth) != ROCDEC_SUCCESS) {
std::cerr << "Failed to get stream bit depth." << std::endl;
return 1;
}
rocDecDestroyBitstreamReader must always be called to destroy the bitstream reader once processing is complete.
Note
To run the sample, you’ll need to set the ROCM_PATH environment variable to point to the location of your ROCm installation, then set LD_PRELOAD and LIBVA_DRIVERS_PATH to point to the ROCm systems libraries and drivers:
export LD_PRELOAD=$ROCM_PATH/lib/rocm_sysdeps/lib/librocm_sysdeps_va.so.2:$ROCM_PATH/lib/rocm_sysdeps/lib/librocm_sysdeps_va-drm.so.2
export LIBVA_DRIVERS_PATH=$ROCM_PATH/lib/rocm_sysdeps/lib/