Using the rocDecode bitstream reader APIs

Using the rocDecode bitstream reader APIs#

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;
}

Note

rocDecDestroyBitstreamReader must always be called to destroy the bitstream reader once processing is complete.