Files
rocm-systems/docs/how-to/using-rocdecode.rst
T
Lisa 8a10f8be18 Documentation - 6.1 Updates (Lisa edits) (#260)
* Update video-decoding-pipeline.md

changed image alignment to left from center

* Update Create-a-decoder-using-rocDecCreateDecoder().md

language edits

* Update Create-parser-object-using-rocDecCreateVideoParser().md

Language edits

* Update Create-parser-object-using-rocDecCreateVideoParser().md

* Update Create-parser-object-using-rocDecCreateVideoParser().md

* Update Create-parser-object-using-rocDecCreateVideoParser().md

* Update Create-parser-object-using-rocDecCreateVideoParser().md

* Update Create-parser-object-using-rocDecCreateVideoParser().md

expanded SEI

* Update Decode-the-frame-using-rocDecDecodeFrame().md

language edits

* Update Destroy-the-decoder.md

* Update Decode-the-frame-using-rocDecDecodeFrame().md

* Update Destroy-the-parser-using-rocDecDestroyVideoParser().md

* Update Parse-video-data-using-rocDecParseVideoData().md

language and spacing edits

* Update Prepare-the-decoded-frame-for-further-processing.md

language and spacing edits

* Update Query-decode-capabilities-using-rocDecGetDecoderCaps().md

Language and spacing edits.

* Update Query-the-decoding-status.md

language edits and spacing

* Update Reconfigure-the-decorder.md

language edits and spacing fixes

* Update Use-rocDecode-API.md

language and spacing edits

* Update Use-rocDecode-API.md

* Update Destroy-the-decoder.md

updated to RocDecoder

* Update Parse-video-data-using-rocDecParseVideoData().md

Added link for callback

* Update Reconfigure-the-decorder.md

Corrected to  RocDecoder

* Delete docs/tutorial directory

Tutorial not required for the user guide.

* Add files via upload

* Delete docs/data/VideoDecoderPipeline.PNG

* Update video-decoding-pipeline.md

* Update video-decoding-pipeline.md

* Update video-decoding-pipeline.md

* Update README.md

* resolve conflicts

* Update video-decoding-pipeline.md

* Update video-decoding-pipeline.md

* Update video-decoding-pipeline.md

* Update install.md

* Update install.md

Minor language edits.

* Update install.md

* Update install.md

* Update install.md

* Update install.md

* Update README.md

Updated link to 
https://github.com/ROCm/rocDecode/blob/develop/rocDecode-setup.py

* Update _toc.yml.in

* Update index.md

* Update index.md

* Update index.md

corrections to index.md

* Update index.md

* Update index.md

* Create index.md

* Update index.md

Updated for installation and how to. Reference has header files. Need confirmation.

* Update index.md

* Update index.md

Changed AMD's rocDecode SDK Library to rocDecode SDK

* Update what-is-rocDecode.md

* Update _toc.yml.in

* Update _toc.yml.in

* Update _toc.yml.in

* Update _toc.yml.in

* Update _toc.yml.in

* Update _toc.yml.in

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Docs - Update config

* Docs - yml updates

* Docs - Updates

* Update _toc.yml.in

* Update _toc.yml.in

* Update _toc.yml.in

* Update what-is-rocDecode.md

* Update _toc.yml.in

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

Added installation content

* Update _toc.yml.in

* Update install.md

changed heading to Installation

* Update index.md

* Update what-is-rocDecode.md

removed installation content

* Update what-is-rocDecode.md

Updated product name

* Update install.md

* Update _toc.yml.in

* Update Create-a-decoder-using-rocDecCreateDecoder.md

* Update Create-parser-object-using-rocDecCreateVideoParser.md

* Update Decode-the-frame-using-rocDecDecodeFrame.md

* Update Destroy-the-decoder.md

* Update Destroy-the-parser-using-rocDecDestroyVideoParser.md

* Update Parse-video-data-using-rocDecParseVideoData.md

* Update Prepare-the-decoded-frame-for-further-processing.md

* Update Query-decode-capabilities-using-rocDecGetDecoderCaps.md

* Update Query-the-decoding-status.md

* Update Reconfigure-the-decorder.md

* Update Use-rocDecode-API.md

* Update _toc.yml.in

* Update _toc.yml.in

* Update index.md

* Update index.md

* Index - Change to RST

* Fix - index

* Update conf.py

copyright

* Cleanup - Index

* Update _toc.yml.in

* Update _toc.yml.in

* Update what-is-rocDecode.md

Added concept

* Add files via upload

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Rename VideoDecoderPipeline (1).png to VideoDecoderPipelinetest.png

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Rename VideoDecoderPipeline.png to VideoDecoderPipelinetest.png

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update index.md

Added a numbered list of actions.

* Update index.md

add links

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.md

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.md

corrected the order of steps.

* Update index.rst

Corrected the order of tasks

* Update _toc.yml.in

Reorder the how to

* Update install.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

updated image path

* Update index.rst

Fixed Reconfigure the decoder <https://github.com/ROCm/rocDecode/blob/master/docs/how-to/Reconfigure-the-decorder.html>`_to
Reconfigure the decoder <https://github.com/ROCm/rocDecode/blob/master/docs/how-to/Reconfigure-the-decoder.html>`_

* Rename Reconfigure-the-decorder.md to Reconfigure-the-decoder.md

Corrected the page name to Reconfigure the decoder

* Update index.rst

Updated to relative links

* Update index.rst

Updated index.rst

* Update index.rst

* Update index.md

* Update index.md

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

updated ref to doc

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Add files via upload

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.rst

* Update index.md

* Update index.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update install.md

* Update install.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update what-is-rocDecode.md

* Update index.md

* Update index.md

* Update _toc.yml.in

* Update _toc.yml.in

* Update what-is-rocDecode.md

* Update install.md

* Update install.md

* Update what-is-rocDecode.md

* Update index.md

* restructure & edits

* udpate readme

* cleanup

* verbiage

* minor fixes

* update changelog

* update changelog

* update title

* add metadata

* more metadata

* convert to RST

* intersphinx test

* edits, install reorg, address comments

* verbiage

* update requirements

* remove extraneous note

* Update docs/sphinx/requirements.in

* clean up install info

* update readme

* update readme

* update requirements

* formatting

* revert requirements

* Docs - Update Requirements

* requirements

* Update requirements

* Fix typo in requirements

pip-compile error

---------

Co-authored-by: Roopa Malavally <56051583+Rmalavally@users.noreply.github.com>
Co-authored-by: Kiriti Gowda <kiritigowda@gmail.com>
Co-authored-by: Pavel Tcherniaev <Pavel.Tcherniaev@amd.com>
Co-authored-by: Sam Wu <sjwu@ualberta.ca>
Co-authored-by: kiritigowda <kiriti.nageshgowda@amd.com>
Co-authored-by: Sam Wu <sam.wu2@amd.com>
2024-02-27 16:42:03 -05:00

215 строки
10 KiB
ReStructuredText

.. meta::
:description: Using rocDecode
:keywords: parse video, parse, decode, video decoder, video decoding, rocDecode, AMD, ROCm
********************************************************************
Using rocDecode
********************************************************************
To learn how to use the rocDecode SDK library and its different utilities, follow these instructions:
1. API overview
====================================================
All rocDecode APIs are exposed in the header files ``rocdecode.h`` and ``rocparser.h``. You can find
these files in the `api` folder in the rocDecode repository.
The samples use the ``RocVideoDecoder`` user class provided in ``roc_video_dec.h`` in the ``utils`` folder
of the rocDecode repository.
A video parser (defined in ``rocparser.h``) is needed to extract and decode headers from the bitstream
in order to organize the data into a structured format for the hardware decoder. The parser is critical in
video decoding, as it controls the decoding and display of a bitstream's individual frames and fields.
The parser object in ``rocparser.h`` has three main APIs:
* ``rocDecCreateVideoParser()``
* ``rocDecParseVideoData()``
* ``rocDecDestroyVideoParser()``
2. Create a parser object
====================================================
The ``rocDecCreateVideoParser()`` API creates a video parser object for the codec that you specify. The
API takes ``max_num_decode_surfaces``, which determines the Decoded Picture Buffer (DPB) size for
decoding. When creating a parser object, the application must register certain callback functions with
the driver, which is called from the parser during decode.
* ``pfn_sequence_callback`` is called when the parser encounters a new sequence header. The parser
informs you of the minimum number of surfaces needed by the parser's DPB to successfully decode
the bitstream. In addition, the caller can set additional parameters, like ``max_display_delay``, to
control frame decoding and display.
* The ``pfn_decode_picture`` callback function is triggered when a picture is set for decoding.
* The ``pfn_display_picture`` callback function is triggered when a frame in display order is ready to be
consumed by the caller.
* The ``pfn_get_sei_msg`` callback function is triggered when your Supplementation Enhancement
Information (SEI) message is parsed and sent back to the caller.
3. Parse video data
====================================================
Elementary stream video packets extracted from the de-multiplexer are fed into the parser using the
``rocDecParseVideoData()`` API.
During this call, the parser triggers the callbacks as it encounters a new sequence header, receives
compressed frame/field data ready to be decoded, or when it's ready to display a frame. If any of the
callbacks return a failure, it is propagated back to the application so the decoding can be ended
gracefully.
4. Query decode capabilities
====================================================
The ``rocDecGetDecoderCaps()`` API allows you to query the capabilities of the underlying hardware
video decoder. Decoder capabilities usually include supported codecs, maximum resolution, and
bit-depth.
The following pseudo-code illustrates the use of this API. The application handles the error
appropriately for non-supported decoder capabilities.
.. code:: cpp
RocdecDecodeCaps decode_caps;
memset(&decode_caps, 0, sizeof(decode_caps));
decode_caps.codec_type = p_video_format->codec;
decode_caps.chroma_format = p_video_format->chroma_format;
decode_caps.bit_depth_minus_8 = p_video_format->bit_depth_luma_minus8;
ROCDEC_API_CALL(rocDecGetDecoderCaps(&decode_caps));
if(!decode_caps.is_supported) {
ROCDEC_THROW("Rocdec:: Codec not supported on this GPU: ", ROCDEC_NOT_SUPPORTED);
return 0;
}
if ((p_video_format->coded_width > decode_caps.max_width) ||
(p_video_format->coded_height > decode_caps.max_height)) {
std::ostringstream errorString;
errorString << std::endl
<< "Resolution : " << p_video_format->coded_width << "x" << p_video_format->coded_height << std::endl
<< "Max Supported (wxh) : " << decode_caps.max_width << "x" << decode_caps.max_height << std::endl
<< "Resolution not supported on this GPU ";
const std::string cErr = errorString.str();
ROCDEC_THROW(cErr, ROCDEC_NOT_SUPPORTED);
return 0;
}
5. Create a decoder
====================================================
``rocDecCreateDecoder()`` creates an instance of the hardware video decoder object and provides you
with a handle upon successful creation. Refer to the ``RocDecoderCreateInfo`` structure for information
about the parameters passed for creating the decoder. For example,
``RocDecoderCreateInfo::codec_type`` represents the codec type of the video. The decoder handle
returned by ``rocDecCreateDecoder()`` must be retained for the entire decode session because the
handle is passed along with the other decoding APIs. In addition, you can inform display or crop
dimensions along with this API.
6. Decode the frame
====================================================
After de-multiplexing and parsing, you can decode bitstream data containing a frame/field using
hardware.
Use the ``rocDecDecodeFrame()`` API to submit a new frame for hardware decoding. Underneath the
driver, the Video Acceleration API (VA-API) is used to submit compressed picture data to the driver.
The parser extracts all the necessary information from the bitstream and fills the ``RocdecPicParams``
structure that's appropriate for the codec. The high-level ``RocVideoDecoder`` class connects the parser
and decoder used for all sample applications.
The ``rocDecDecodeFrame()`` call takes the decoder handle and the pointer to the ``RocdecPicParams``
structure and initiates the video decoding using VA-API.
7. Query the decoding status
====================================================
After submitting a frame for decoding, you can call ``rocDecGetDecodeStatus()`` to query the decoding
status for a given frame. A structure pointer, ``RocdecDecodeStatus*``, is filled and returned.
The API inputs are:
* ``decoder_handle``: A ``RocDecoder`` handler, ``rocDecDecoderHandle``.
* ``pic_idx``: An `int` value for the ``picIdx`` for which you want a status in order to index of the picture.
* ``decode_status``: A pointer to ``RocdecDecodeStatus`` as a return value.
The API returns one of the following statuses:
* Invalid (0): Decode status is not valid.
* In Progress (1): Decoding is in progress.
* Success (2): Decoding was successful and no errors were returned.
* Error (8): The frame was corrupted, but the error was not concealed.
* Error Concealed (9): The frame was corrupted and the error was concealed.
* Displaying (10): Decode is complete, display in progress.
8. Prepare the decoded frame for further processing
====================================================
The decoded frames can be used for further postprocessing using ``rocDecGetVideoFrame()``. The
successful completion of ``rocDecGetVideoFrame()`` indicates that the decoding process is complete and
the device memory pointer is inter-opped into the ROCm HIP address space in order to further process
the decoded frame in device memory. The caller gets the necessary information on the output surface,
such as YUV format, dimensions, and pitch from this call. In the high-level ``RocVideoDecoder`` class, we
provide four different surface type modes for the mapped surface, as specified in
``OutputSurfaceMemoryType``.
.. code:: cpp
typedef enum OutputSurfaceMemoryType_enum {
OUT_SURFACE_MEM_DEV_INTERNAL = 0, /**< Internal interopped decoded surface memory **/
OUT_SURFACE_MEM_DEV_COPIED = 1, /**< decoded output will be copied to a separate device memory **/
OUT_SURFACE_MEM_HOST_COPIED = 2 /**< decoded output will be copied to a separate host memory **/
OUT_SURFACE_MEM_NOT_MAPPED = 3 /**< decoded output is not available (interop won't be used): useful for decode only performance app*/
} OutputSurfaceMemoryType;
If the mapped surface type is ``OUT_SURFACE_MEM_DEV_INTERNAL``, the direct pointer to the decoded
surface is provided. You must call ``ReleaseFrame()`` (``RocVideoDecoder`` class). If the requested surface
type is ``OUT_SURFACE_MEM_DEV_COPIED`` or ``OUT_SURFACE_MEM_HOST_COPIED``, the internal
decoded frame is copied to another buffer, either in device memory or host memory. After that, it's
immediately unmapped for re-use by the ``RocVideoDecoder`` class.
Refer to the ``RocVideoDecoder`` class and
`samples <https://github.com/ROCm/rocDecode/tree/develop/samples>`_ for details on how to use
these APIs.
9. Reconfigure the decoder
====================================================
You can call ``rocDecReconfigureDecoder()`` to reuse a single decoder for multiple clips or when the
video resolution changes during the decode. The API currently supports resolution changes, resize
parameter changes, and target area parameter changes for the same codec without destroying an
ongoing decoder instance. This can improve performance and reduce overall latency.
The API inputs are:
* ``decoder_handle``: A ``RocDecoder`` handler, ``rocDecDecoderHandle``.
* ``reconfig_params``: You must specify the parameters for the changes in
``RocdecReconfigureDecoderInfo``. The width and height used for reconfiguration cannot exceed the
values set for ``max_width`` and ``max_height``, defined in ``RocDecoderCreateInfo``. If you need to
change these values, you have to destroy and recreate the session.
.. note::
You must call ``rocDecReconfigureDecoder()`` during ``RocdecParserParams::pfn_sequence_callback``.
10. Destroy the decoder
====================================================
You must call the ``rocDecDestroyDecoder()`` to destroy the session and free up resources.
The API input is:
* ``decoder_handle``: A ``RocDecoder`` handler, ``rocDecDecoderHandle``.
The API returns a ``RocdecDecodeStatus`` value.
11. Destroy the parser
====================================================
You must call ``rocDecDestroyVideoParser()`` to destroy the parser object and free up all allocated
resources at the end of video decoding.