├── .Doxyfile ├── .DoxygenLayout.xml ├── .azuredevops └── rocm-ci.yml ├── .codecov.yaml ├── .github ├── CODEOWNERS └── dependabot.yml ├── .gitignore ├── .jenkins ├── common.groovy └── precheckin.groovy ├── .readthedocs.yaml ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README.md ├── api ├── amd_detail │ └── rocdecode_api_trace.h ├── rocdecode │ ├── roc_bitstream_reader.h │ ├── rocdecode.h │ └── rocparser.h └── rocdecode_version.h.in ├── cmake ├── FindFFmpeg.cmake ├── FindLibdrm_amdgpu.cmake └── FindLibva.cmake ├── cmake_modules └── rocdecode-config.cmake.in ├── data └── videos │ ├── AMD_driving_virtual_20-AV1.ivf │ ├── AMD_driving_virtual_20-AV1.mp4 │ ├── AMD_driving_virtual_20-H264.264 │ ├── AMD_driving_virtual_20-H264.mp4 │ ├── AMD_driving_virtual_20-H265.265 │ ├── AMD_driving_virtual_20-H265.mp4 │ └── AMD_driving_virtual_20-VP9.ivf ├── docker ├── README.md ├── rocDecode-on-ubuntu20.dockerfile └── rocDecode-on-ubuntu22.dockerfile ├── docs ├── .gitignore ├── conceptual │ ├── rocDecode-memory-types.rst │ └── video-decoding-pipeline.rst ├── conf.py ├── data │ ├── AMD-Logo-Doxygen.png │ ├── AMD_rocDecode_Logo.png │ └── VideoDecoderPipelinetest.png ├── doxygen │ ├── .gitignore │ ├── Doxyfile │ └── DoxygenLayout.xml ├── how-to │ ├── using-rocDecode-bitstream.rst │ ├── using-rocDecode-ffmpeg.rst │ ├── using-rocDecode-video-decoder.rst │ ├── using-rocDecode-videodecode-sample.rst │ └── using-rocdecode.rst ├── index.rst ├── install │ ├── rocDecode-build-and-install.rst │ ├── rocDecode-package-install.rst │ └── rocDecode-prerequisites.rst ├── license.md ├── reference │ ├── index.md │ ├── rocDecode-formats-and-architectures.rst │ └── rocDecode-tested-configurations.rst ├── sphinx │ ├── .gitignore │ ├── _toc.yml.in │ ├── requirements.in │ └── requirements.txt ├── tutorials │ ├── README.md │ └── rocDecode-samples.rst └── what-is-rocDecode.rst ├── rocDecode-setup.py ├── samples ├── README.md ├── common.h ├── videoDecode │ ├── CMakeLists.txt │ ├── README.md │ └── videodecode.cpp ├── videoDecodeBatch │ ├── CMakeLists.txt │ ├── README.md │ └── videodecodebatch.cpp ├── videoDecodeMem │ ├── CMakeLists.txt │ ├── README.md │ └── videodecodemem.cpp ├── videoDecodeMultiFiles │ ├── CMakeLists.txt │ ├── README.md │ └── videodecodemultifiles.cpp ├── videoDecodePerf │ ├── CMakeLists.txt │ ├── README.md │ └── videodecodeperf.cpp ├── videoDecodePicFiles │ ├── CMakeLists.txt │ ├── README.md │ └── videodecodepicfiles.cpp ├── videoDecodeRGB │ ├── CMakeLists.txt │ ├── README.md │ └── videodecrgb.cpp ├── videoDecodeRaw │ ├── CMakeLists.txt │ ├── README.md │ └── videodecoderaw.cpp └── videoToSequence │ ├── CMakeLists.txt │ ├── README.md │ └── videotosequence.cpp ├── src ├── amd_detail │ ├── rocdecode_api_dispatch_interface.cpp │ └── rocdecode_api_trace.cpp ├── bit_stream_reader │ ├── bs_reader_handle.h │ ├── es_reader.cpp │ ├── es_reader.h │ └── roc_bs_reader_api.cpp ├── commons.h ├── parser │ ├── av1_defines.h │ ├── av1_parser.cpp │ ├── av1_parser.h │ ├── avc_defines.h │ ├── avc_parser.cpp │ ├── avc_parser.h │ ├── hevc_defines.h │ ├── hevc_parser.cpp │ ├── hevc_parser.h │ ├── parser_handle.h │ ├── roc_video_parser.cpp │ ├── roc_video_parser.h │ ├── rocparser_api.cpp │ ├── vp9_defines.h │ ├── vp9_parser.cpp │ └── vp9_parser.h └── rocdecode │ ├── dec_handle.h │ ├── roc_decoder.cpp │ ├── roc_decoder.h │ ├── rocdecode_api.cpp │ └── vaapi │ ├── vaapi_videodecoder.cpp │ └── vaapi_videodecoder.h ├── test ├── CMakeLists.txt ├── rocDecodeNegativeApiTests │ ├── CMakeLists.txt │ ├── README.md │ ├── rocdecode_api_negative_tests.cpp │ ├── rocdecode_api_negative_tests.h │ └── rocdecodenegativetest.cpp └── testScripts │ ├── README.md │ ├── run_rocDecodeSamples.py │ └── run_rocDecode_Conformance.py └── utils ├── colorspace_kernels.cpp ├── colorspace_kernels.h ├── ffmpegvideodecode ├── ffmpeg_video_dec.cpp └── ffmpeg_video_dec.h ├── md5.h ├── resize_kernels.cpp ├── resize_kernels.h ├── rocvideodecode ├── roc_video_dec.cpp └── roc_video_dec.h ├── video_demuxer.h └── video_post_process.h /.azuredevops/rocm-ci.yml: -------------------------------------------------------------------------------- 1 | resources: 2 | repositories: 3 | - repository: pipelines_repo 4 | type: github 5 | endpoint: ROCm 6 | name: ROCm/ROCm 7 | 8 | variables: 9 | - group: common 10 | - template: /.azuredevops/variables-global.yml@pipelines_repo 11 | 12 | trigger: 13 | batch: true 14 | branches: 15 | include: 16 | - develop 17 | - mainline 18 | paths: 19 | exclude: 20 | - .github 21 | - .jenkins 22 | - docs 23 | - '.*.y*ml' 24 | - '*.md' 25 | - LICENSE 26 | 27 | pr: 28 | autoCancel: true 29 | branches: 30 | include: 31 | - develop 32 | - mainline 33 | paths: 34 | exclude: 35 | - .github 36 | - .jenkins 37 | - docs 38 | - '.*.y*ml' 39 | - '*.md' 40 | - LICENSE 41 | drafts: false 42 | 43 | jobs: 44 | - template: ${{ variables.CI_COMPONENT_PATH }}/rocDecode.yml@pipelines_repo 45 | -------------------------------------------------------------------------------- /.codecov.yaml: -------------------------------------------------------------------------------- 1 | # Configuration details 2 | # https://docs.codecov.io/docs/codecov-yaml 3 | 4 | # Validate YAML 5 | # curl --data-binary @.codecov.yaml https://codecov.io/validate 6 | 7 | # Coverage configuration 8 | coverage: 9 | status: 10 | patch: true 11 | 12 | range: 60..80 # First number represents red, and second represents green 13 | round: nearest # up, down, or nearest 14 | precision: 2 # Number of decimal places, between 0 and 5 15 | 16 | comment: # this is a top-level key 17 | layout: "diff, files" 18 | behavior: default 19 | require_changes: true # learn more in the Requiring Changes section below 20 | require_base: true # [true :: must have a base report to post] 21 | require_head: true # [true :: must have a head report to post] 22 | hide_project_coverage: true # [true :: only show coverage on the git diff] 23 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @rrawther @AryanSalmanpour 2 | # Documentation files 3 | docs/ @ROCm/rocm-documentation 4 | *.md @ROCm/rocm-documentation 5 | *.rst @ROCm/rocm-documentation 6 | .readthedocs.yaml @ROCm/rocm-documentation 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "pip" # See documentation for possible values 9 | directory: "/docs/sphinx" # Location of package manifests 10 | open-pull-requests-limit: 10 11 | schedule: 12 | interval: "daily" 13 | target-branch: "develop" 14 | labels: 15 | - "documentation" 16 | - "dependencies" 17 | - "ci:docs-only" 18 | reviewers: 19 | - "samjwu" 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | samples/*/build 3 | .vscode/ 4 | doxygen_output* 5 | samples/videoDecodeMultiFiles/example.txt 6 | api/rocdecode_version.h -------------------------------------------------------------------------------- /.jenkins/precheckin.groovy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env groovy 2 | @Library('rocJenkins@pong') _ 3 | import com.amd.project.* 4 | import com.amd.docker.* 5 | 6 | def runCI = 7 | { 8 | nodeDetails, jobName-> 9 | 10 | def prj = new rocProject('rocDecode', 'PreCheckin') 11 | 12 | def nodes = new dockerNodes(nodeDetails, jobName, prj) 13 | 14 | def commonGroovy 15 | 16 | boolean formatCheck = false 17 | 18 | def compileCommand = 19 | { 20 | platform, project-> 21 | 22 | commonGroovy = load "${project.paths.project_src_prefix}/.jenkins/common.groovy" 23 | commonGroovy.runCompileCommand(platform, project, jobName) 24 | } 25 | 26 | 27 | def testCommand = 28 | { 29 | platform, project-> 30 | 31 | commonGroovy.runTestCommand(platform, project) 32 | } 33 | 34 | def packageCommand = 35 | { 36 | platform, project-> 37 | 38 | commonGroovy.runPackageCommand(platform, project) 39 | } 40 | 41 | buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) 42 | } 43 | 44 | ci: { 45 | String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) 46 | 47 | def propertyList = ["compute-rocm-dkms-no-npi-hipclang":[pipelineTriggers([cron('0 1 * * 0')])]] 48 | propertyList = auxiliary.appendPropertyList(propertyList) 49 | 50 | def jobNameList = ["compute-rocm-dkms-no-npi-hipclang":([ubuntu20:['gfx90a'], ubuntu22:['gfx1101'], sles15sp1:['gfx908'], rhel8:['gfx1030'], rhel9:['gfx942']])] 51 | jobNameList = auxiliary.appendJobNameList(jobNameList) 52 | 53 | propertyList.each 54 | { 55 | jobName, property-> 56 | if (urlJobName == jobName) { 57 | properties(auxiliary.addCommonProperties(property)) 58 | } 59 | } 60 | 61 | jobNameList.each 62 | { 63 | jobName, nodeDetails-> 64 | if (urlJobName == jobName) { 65 | stage(jobName) { 66 | runCI(nodeDetails, jobName) 67 | } 68 | } 69 | } 70 | 71 | // For url job names that are not listed by the jobNameList i.e. compute-rocm-dkms-no-npi-1901 72 | if(!jobNameList.keySet().contains(urlJobName)) { 73 | properties(auxiliary.addCommonProperties([pipelineTriggers([cron('0 1 * * *')])])) 74 | stage(urlJobName) { 75 | runCI([ubuntu22:['gfx942']], urlJobName) 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | version: 2 5 | 6 | sphinx: 7 | configuration: docs/conf.py 8 | 9 | formats: [htmlzip, pdf, epub] 10 | 11 | python: 12 | install: 13 | - requirements: docs/sphinx/requirements.txt 14 | 15 | build: 16 | os: ubuntu-22.04 17 | tools: 18 | python: "3.10" 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog for rocDecode 2 | 3 | Full documentation for rocDecode is available at [https://rocm.docs.amd.com/projects/rocDecode/en/latest/](https://rocm.docs.amd.com/projects/rocDecode/en/latest/) 4 | 5 | ## rocDecode 0.13.2 (unreleased) 6 | 7 | ### Added 8 | 9 | * VP9 IVF container file parsing support in bitstream reader. 10 | * CTest for VP9 decode on bitstream reader. 11 | * HEVC/AVC/AV1/VP9 stream syntax error handling. 12 | * HEVC stream bit depth change handling and DPB buffer size change handling through decoder reconfiguration. 13 | * AVC stream DPB buffer size change handling through decoder reconfiguration. 14 | * rocDecode now uses the Cmake CMAKE_PREFIX_PATH directive. 15 | 16 | ### Optimized 17 | 18 | * Decode session start latency reduction. 19 | * Bitstream type detection optimization in bitstream reader. 20 | 21 | ### Resolved issues 22 | 23 | * Fixed a bug in picture files sample "videoDecodePicFiles" that can results in incorrect output frame count. 24 | * Fixed a decoded frame output issue in video size change cases. 25 | * Removed incorrect asserts of bitdepth_minus_8 in GetBitDepth() and num_chroma_planes in GetNumChromaPlanes() API calls in RocVideoDecoder utility class. 26 | 27 | ### Removed 28 | 29 | * GetStream() interface call from RocVideoDecoder utility class 30 | 31 | ### Changed 32 | 33 | * Changed asserts in query API calls in RocVideoDecoder utility class to error reports, to avoid hard stop during query in case error occurs and to let the caller decide actions. 34 | * `libdrm_amdgpu` is now explicitly linked with rocdecode. 35 | 36 | ## rocDecode 0.10.0 for ROCm 6.4 37 | 38 | ### Added 39 | 40 | * The new bitstream reader feature. The bitstream reader contains built-in stream file parsers, including an elementary stream file parser and an IVF container file parser. It can parse AVC/HEVC/AV1 elementary stream files and AV1 IVF container files. Additional format support can be added in the future. 41 | * VP9 decode support. 42 | * More CTests: VP9 test and tests on video decode raw sample. 43 | * Two new samples, videodecoderaw and videodecodepicfiles, have been added. videodecoderaw uses the bitstream reader instead of the FFMPEG demuxer to get picture data, and videodecodepicfiles shows how to decode an elementary video stream stored in multiple files with each file containing bitstream data of a coded picutre 44 | 45 | ### Changed 46 | 47 | * AMD Clang++ is now the default CXX compiler. 48 | * Moved MD5 code out of roc video decode utility. 49 | 50 | ### Removed 51 | 52 | * FFMPEG executable requirement for the package 53 | 54 | ## rocDecode 0.8.0 for ROCm 6.3 55 | 56 | ### Added 57 | 58 | * AV1 decode support 59 | 60 | ### Changed 61 | 62 | * Clang is now the default CXX compiler. 63 | * The new minimum supported version of va-api is 1.16. 64 | * New build and runtime options have been added to the `rocDecode-setup.py` setup script. 65 | * Added FFMpeg based software decoding into utils. 66 | * Modified videodecode sample to allow FFMpeg based decoding 67 | 68 | ### Removed 69 | 70 | * Make tests have been removed. CTEST is now used for both Make tests and package tests. 71 | * `mesa-amdgpu-dri-drivers` has been removed as a dependency on RHEL and SLES. 72 | 73 | ### Resolved issues 74 | 75 | * Fixed a bug in the size of output streams in the `videoDecodeBatch` sample. 76 | 77 | ## rocDecode 0.7.0 78 | 79 | ### Added 80 | 81 | * Clang - Default CXX compiler 82 | * Parser - Add new API rocDecParserMarkFrameForReuse() 83 | 84 | ### Optimized 85 | 86 | * Setup Script - Build and runtime install options 87 | 88 | ### Changed 89 | 90 | * CTest - Core tests for make test and package test 91 | 92 | ### Resolved issues 93 | 94 | * Sample - Bugfix for videoDecodeBatch 95 | 96 | ### Tested configurations 97 | 98 | * Linux 99 | * Ubuntu - `20.04` / `22.04` 100 | * RHEL - `8` / `9` 101 | * SLES - `15 SP5` 102 | * ROCm: 103 | * rocm-core - `6.2.0.60200-66` 104 | * amdgpu-core - `1:6.2.60200-2009582` 105 | * libva-dev - `2.7.0-2` / `2.14.0-1` 106 | * mesa-amdgpu-va-drivers - `1:24.2.0.60200-2009582` 107 | * FFmpeg - `4.2.7` / `4.4.2-0` 108 | * rocDecode Setup Script - `V2.2.0` 109 | 110 | 111 | ## rocDecode 0.6.0 112 | 113 | ### Additions 114 | 115 | * AVC decode support 116 | * FFMPEG V5.X Support 117 | * Mariner - Build Support 118 | 119 | ### Optimizations 120 | 121 | * Setup Script - Error Check install 122 | 123 | ### Changes 124 | 125 | * Dependencies - Updates to core dependencies 126 | * LibVA Headers - Use public headers 127 | * mesa-amdgpu-va-drivers - RPM Package available on RPM from ROCm 6.2 128 | 129 | ### Fixes 130 | 131 | * Package deps 132 | * RHEL/SLES - Additional required packages `mesa-amdgpu-dri-drivers libdrm-amdgpu` 133 | 134 | ### Tested configurations 135 | 136 | * Linux 137 | * Ubuntu - `20.04` / `22.04` 138 | * RHEL - `8` / `9` 139 | * ROCm: 140 | * rocm-core - `6.1.0.60100-64` 141 | * amdgpu-core - `1:6.1.60100-1741643` 142 | * libva-dev - `2.7.0-2` / `2.14.0-1` 143 | * mesa-amdgpu-va-drivers - `1:24.1.0` 144 | * mesa-amdgpu-dri-drivers - `24.1.0.60200` 145 | * FFmpeg - `4.2.7` / `4.4.2-0` 146 | * rocDecode Setup Script - `V2.1.0` 147 | 148 | ## rocDecode 0.5.0 149 | 150 | ### Changes 151 | 152 | * Added HEVC decode support 153 | * Changed setup updates 154 | * Added AMDGPU package support 155 | * Optimized package dependencies 156 | * Updated README 157 | 158 | ### Fixes 159 | 160 | * Minor bug fix and updates 161 | 162 | ### Tested configurations 163 | 164 | * Linux distribution 165 | * Ubuntu - `20.04` / `22.04` 166 | * ROCm: 167 | * rocm-core - `6.1.0.60100-28` 168 | * amdgpu-core - `1:6.1.60100-1731559` 169 | * FFMPEG - `4.2.7` / `4.4.2-0` 170 | * rocDecode Setup Script - `V1.4` 171 | 172 | ## rocDecode 0.4.0 173 | 174 | ### Changes 175 | 176 | * Added CTest - Tests for install verification 177 | * Added Doxygen - Support for API documentation 178 | * Changed setup updates 179 | * Optimized CMakeList Cleanup 180 | * Added README 181 | 182 | ### Fixes 183 | 184 | * Minor bug fix and updates 185 | 186 | ### Tested configurations 187 | 188 | * Linux distribution 189 | * Ubuntu - `20.04` / `22.04` 190 | * ROCm: 191 | * rocm-core - `5.6.1.50601-93` 192 | * amdgpu-core - `1:5.6.50601-1649308` 193 | * FFMPEG - `4.2.7` / `4.4.2-0` 194 | * libva-dev - `2.7.0-2` / `2.14.0-1` 195 | * rocDecode Setup Script - `V1.1` 196 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved 4 | 5 | NOTICE REGARDING STANDARDS 6 | 7 | AMD does not provide a license or sublicense to any Intellectual Property Rights 8 | relating to any standards, including but not limited to any audio and/or video 9 | codec technologies such as MPEG-2, MPEG-4; AVC/H.264; HEVC/H.265; AAC decode/FFMPEG; 10 | AAC encode/FFMPEG; VC-1; and MP3 (collectively, the “Media Technologies”). 11 | For clarity, you will pay any royalties due for such third party technologies, 12 | which may include the Media Technologies that are owed as a result of 13 | AMD providing the Software to you. 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy 16 | of this software and associated documentation files (the "Software"), to deal 17 | in the Software without restriction, including without limitation the rights 18 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | copies of the Software, and to permit persons to whom the Software is 20 | furnished to do so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /api/amd_detail/rocdecode_api_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #include "rocdecode/rocdecode.h" 25 | #include "rocdecode/rocparser.h" 26 | #include "rocdecode/roc_bitstream_reader.h" 27 | 28 | // Define version macros for the rocDecode API dispatch table, specifying the MAJOR and STEP versions. 29 | // 30 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 31 | // 32 | // 1. When adding new functions to the rocDecode API dispatch table, always append the new function pointer 33 | // to the end of the table and increment the dispatch table's version number. Never rearrange the order of 34 | // the member variables in the dispatch table, as doing so will break the Application Binary Interface (ABI). 35 | // 2. In critical situations where the type of an existing member variable in a dispatch table has been changed 36 | // or removed due to a data type modification, it is important to increment the major version number of the 37 | // rocDecode API dispatch table. If the function pointer type can no longer be declared, do not remove it. 38 | // Instead, change the function pointer type to `void*` and ensure it is always initialized to `nullptr`. 39 | // 40 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 41 | // 42 | 43 | // The major version number should ideally remain unchanged. Increment the ROCDECODE_RUNTIME_API_TABLE_MAJOR_VERSION only 44 | // for fundamental changes to the rocDecodeDispatchTable struct, such as altering the type or name of an existing member variable. 45 | // Please DO NOT REMOVE it. 46 | #define ROCDECODE_RUNTIME_API_TABLE_MAJOR_VERSION 0 47 | 48 | // Increment the ROCDECODE_RUNTIME_API_TABLE_STEP_VERSION when new runtime API functions are added. 49 | // If the corresponding ROCDECODE_RUNTIME_API_TABLE_MAJOR_VERSION increases reset the ROCDECODE_RUNTIME_API_TABLE_STEP_VERSION to zero. 50 | #define ROCDECODE_RUNTIME_API_TABLE_STEP_VERSION 1 51 | 52 | // rocDecode API interface 53 | typedef rocDecStatus (ROCDECAPI *PfnRocDecCreateVideoParser)(RocdecVideoParser *parser_handle, RocdecParserParams *params); 54 | typedef rocDecStatus (ROCDECAPI *PfnRocDecParseVideoData)(RocdecVideoParser parser_handle, RocdecSourceDataPacket *packet); 55 | typedef rocDecStatus (ROCDECAPI *PfnRocDecDestroyVideoParser)(RocdecVideoParser parser_handle); 56 | typedef rocDecStatus (ROCDECAPI *PfnRocDecCreateDecoder)(rocDecDecoderHandle *decoder_handle, RocDecoderCreateInfo *decoder_create_info); 57 | typedef rocDecStatus (ROCDECAPI *PfnRocDecDestroyDecoder)(rocDecDecoderHandle decoder_handle); 58 | typedef rocDecStatus (ROCDECAPI *PfnRocDecGetDecoderCaps)(RocdecDecodeCaps *decode_caps); 59 | typedef rocDecStatus (ROCDECAPI *PfnRocDecDecodeFrame)(rocDecDecoderHandle decoder_handle, RocdecPicParams *pic_params); 60 | typedef rocDecStatus (ROCDECAPI *PfnRocDecGetDecodeStatus)(rocDecDecoderHandle decoder_handle, int pic_idx, RocdecDecodeStatus *decode_status); 61 | typedef rocDecStatus (ROCDECAPI *PfnRocDecReconfigureDecoder)(rocDecDecoderHandle decoder_handle, RocdecReconfigureDecoderInfo *reconfig_params); 62 | typedef rocDecStatus (ROCDECAPI *PfnRocDecGetVideoFrame)(rocDecDecoderHandle decoder_handle, int pic_idx, void *dev_mem_ptr[3], uint32_t *horizontal_pitch, RocdecProcParams *vid_postproc_params); 63 | typedef const char* (ROCDECAPI *PfnRocDecGetErrorName)(rocDecStatus rocdec_status); 64 | typedef rocDecStatus (ROCDECAPI *PfnRocDecCreateBitstreamReader)(RocdecBitstreamReader *bs_reader_handle, const char *input_file_path); 65 | typedef rocDecStatus (ROCDECAPI *PfnRocDecGetBitstreamCodecType)(RocdecBitstreamReader bs_reader_handle, rocDecVideoCodec *codec_type); 66 | typedef rocDecStatus (ROCDECAPI *PfnRocDecGetBitstreamBitDepth)(RocdecBitstreamReader bs_reader_handle, int *bit_depth); 67 | typedef rocDecStatus (ROCDECAPI *PfnRocDecGetBitstreamPicData)(RocdecBitstreamReader bs_reader_handle, uint8_t **pic_data, int *pic_size, int64_t *pts); 68 | typedef rocDecStatus (ROCDECAPI *PfnRocDecDestroyBitstreamReader)(RocdecBitstreamReader bs_reader_handle); 69 | 70 | // rocDecode API dispatch table 71 | struct RocDecodeDispatchTable { 72 | // ROCDECODE_RUNTIME_API_TABLE_STEP_VERSION == 0 73 | size_t size; 74 | PfnRocDecCreateVideoParser pfn_rocdec_create_video_parser; 75 | PfnRocDecParseVideoData pfn_rocdec_parse_video_data; 76 | PfnRocDecDestroyVideoParser pfn_rocdec_destroy_video_parser; 77 | PfnRocDecCreateDecoder pfn_rocdec_create_decoder; 78 | PfnRocDecDestroyDecoder pfn_rocdec_destroy_decoder; 79 | PfnRocDecGetDecoderCaps pfn_rocdec_get_gecoder_caps; 80 | PfnRocDecDecodeFrame pfn_rocdec_decode_frame; 81 | PfnRocDecGetDecodeStatus pfn_rocdec_get_decode_status; 82 | PfnRocDecReconfigureDecoder pfn_rocdec_reconfigure_decoder; 83 | PfnRocDecGetVideoFrame pfn_rocdec_get_video_frame; 84 | PfnRocDecGetErrorName pfn_rocdec_get_error_name; 85 | // PLEASE DO NOT EDIT ABOVE! 86 | // ROCDECODE_RUNTIME_API_TABLE_STEP_VERSION == 1 87 | PfnRocDecCreateBitstreamReader pfn_rocdec_create_bitstream_reader; 88 | PfnRocDecGetBitstreamCodecType pfn_rocdec_get_bitstream_codec_type; 89 | PfnRocDecGetBitstreamBitDepth pfn_rocdec_get_bitstream_bit_depth; 90 | PfnRocDecGetBitstreamPicData pfn_rocdec_get_bitstream_pic_data; 91 | PfnRocDecDestroyBitstreamReader pfn_rocdec_destroy_bitstream_reader; 92 | // PLEASE DO NOT EDIT ABOVE! 93 | // ROCDECODE_RUNTIME_API_TABLE_STEP_VERSION == 2 94 | 95 | // ******************************************************************************************* // 96 | // READ BELOW 97 | // ******************************************************************************************* // 98 | // Please keep this text at the end of the structure: 99 | 100 | // 1. Do not reorder any existing members. 101 | // 2. Increase the step version definition before adding new members. 102 | // 3. Insert new members under the appropriate step version comment. 103 | // 4. Generate a comment for the next step version. 104 | // 5. Add a "PLEASE DO NOT EDIT ABOVE!" comment. 105 | // ******************************************************************************************* // 106 | }; -------------------------------------------------------------------------------- /api/rocdecode/roc_bitstream_reader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "rocdecode/rocdecode.h" 26 | 27 | /*! 28 | * \file 29 | * \brief The AMD rocBitstreamReader Library. 30 | * 31 | * \defgroup group_roc_bitstream_reader rocDecode Parser: AMD ROCm Video Bitstream Reader API 32 | * \brief AMD The rocBitstreamReader is a toolkit to read picture data from bitstream files for decoding on AMD’s GPUs. 33 | */ 34 | 35 | #if defined(__cplusplus) 36 | extern "C" { 37 | #endif /* __cplusplus */ 38 | 39 | /*********************************************************************************/ 40 | //! HANDLE of rocBitstreamReader 41 | //! Used in subsequent API calls after rocDecCreateBitstreamReader 42 | /*********************************************************************************/ 43 | typedef void *RocdecBitstreamReader; 44 | 45 | /************************************************************************************************/ 46 | //! \ingroup group_roc_bitstream_reader 47 | //! \fn rocDecStatus ROCDECAPI rocDecCreateBitstreamReader(RocdecBitstreamReader *bs_reader_handle, const char *input_file_path) 48 | //! Create video bitstream reader object and initialize 49 | /************************************************************************************************/ 50 | extern rocDecStatus ROCDECAPI rocDecCreateBitstreamReader(RocdecBitstreamReader *bs_reader_handle, const char *input_file_path); 51 | 52 | /************************************************************************************************/ 53 | //! \ingroup group_roc_bitstream_reader 54 | //! \fn rocDecStatus ROCDECAPI rocDecGetBitstreamCodecType(RocdecBitstreamReader bs_reader_handle, rocDecVideoCodec *codec_type) 55 | //! Get the codec type of the bitstream 56 | /************************************************************************************************/ 57 | extern rocDecStatus ROCDECAPI rocDecGetBitstreamCodecType(RocdecBitstreamReader bs_reader_handle, rocDecVideoCodec *codec_type); 58 | 59 | /************************************************************************************************/ 60 | //! \ingroup group_roc_bitstream_reader 61 | //! \fn rocDecStatus ROCDECAPI rocDecGetBitstreamBitDepth(RocdecBitstreamReader bs_reader_handle, int *bit_depth) 62 | //! Get the bit depth of the bitstream 63 | /************************************************************************************************/ 64 | extern rocDecStatus ROCDECAPI rocDecGetBitstreamBitDepth(RocdecBitstreamReader bs_reader_handle, int *bit_depth); 65 | 66 | /************************************************************************************************/ 67 | //! \ingroup group_roc_bitstream_reader 68 | //! \fn rocDecStatus ROCDECAPI rocDecGetBitstreamPicData(RocdecBitstreamReader bs_reader_handle, uint8_t **pic_data, int *pic_size, int64_t *pts) 69 | //! Read one unit of picture data from the bitstream. The unit can be a frame or field for AVC/HEVC, 70 | //! a temporal unit for AV1, or a frame (including superframe) for VP9. The picture data unit is pointed 71 | //! by pic_data. The size of the unit is specified by pic_size. The presentation time stamp, if available, 72 | //! is given by pts. 73 | /************************************************************************************************/ 74 | extern rocDecStatus ROCDECAPI rocDecGetBitstreamPicData(RocdecBitstreamReader bs_reader_handle, uint8_t **pic_data, int *pic_size, int64_t *pts); 75 | 76 | /************************************************************************************************/ 77 | //! \ingroup group_roc_bitstream_reader 78 | //! \fn rocDecStatus ROCDECAPI rocDecDestroyBitstreamReader(RocdecBitstreamReader bs_reader_handle) 79 | //! Destroy the video parser object 80 | /************************************************************************************************/ 81 | extern rocDecStatus ROCDECAPI rocDecDestroyBitstreamReader(RocdecBitstreamReader bs_reader_handle); 82 | 83 | #if defined(__cplusplus) 84 | } 85 | #endif /* __cplusplus */ 86 | -------------------------------------------------------------------------------- /api/rocdecode_version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 - 2025 Advanced Micro Devices, Inc. All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef _ROCDECODE_VERSION_H_ 24 | #define _ROCDECODE_VERSION_H_ 25 | 26 | /*! 27 | * \file 28 | * \brief rocDecode version 29 | * \defgroup group_rocdecode_version rocDecode Version 30 | * \brief rocDecode version 31 | */ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif /* __cplusplus */ 36 | 37 | #define ROCDECODE_MAJOR_VERSION @PROJECT_VERSION_MAJOR@ 38 | #define ROCDECODE_MINOR_VERSION @PROJECT_VERSION_MINOR@ 39 | #define ROCDECODE_MICRO_VERSION @PROJECT_VERSION_PATCH@ 40 | 41 | /** 42 | * ROCDECODE_CHECK_VERSION: 43 | * @major: major version, like 1 in 1.2.3 44 | * @minor: minor version, like 2 in 1.2.3 45 | * @micro: micro version, like 3 in 1.2.3 46 | * 47 | * Evaluates to %TRUE if the version of ROCDECODE is greater than 48 | * @major, @minor and @micro 49 | */ 50 | #define ROCDECODE_CHECK_VERSION(major, minor, micro) \ 51 | (ROCDECODE_MAJOR_VERSION > (major) || \ 52 | (ROCDECODE_MAJOR_VERSION == (major) && ROCDECODE_MINOR_VERSION > (minor)) || \ 53 | (ROCDECODE_MAJOR_VERSION == (major) && ROCDECODE_MINOR_VERSION == (minor) && ROCDECODE_MICRO_VERSION >= (micro))) 54 | 55 | #ifdef __cplusplus 56 | } // end extern "C" block 57 | #endif 58 | 59 | #endif //_ROCDECODE_VERSION_H_ header guard 60 | -------------------------------------------------------------------------------- /cmake/FindFFmpeg.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | ################################################################################ 24 | # - Try to find ffmpeg libraries (libavcodec, libavformat and libavutil) 25 | # Once done this will define 26 | # 27 | # FFMPEG_FOUND - system has ffmpeg or libav 28 | # FFMPEG_INCLUDE_DIR - the ffmpeg include directory 29 | # FFMPEG_LIBRARIES - Link these to use ffmpeg 30 | ################################################################################ 31 | 32 | set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig") 33 | include(FindPackageHandleStandardArgs) 34 | 35 | find_package_handle_standard_args( 36 | FFmpeg 37 | FOUND_VAR FFMPEG_FOUND 38 | REQUIRED_VARS 39 | FFMPEG_LIBRARIES 40 | FFMPEG_INCLUDE_DIR 41 | AVCODEC_INCLUDE_DIR 42 | AVCODEC_LIBRARY 43 | AVFORMAT_INCLUDE_DIR 44 | AVFORMAT_LIBRARY 45 | AVUTIL_INCLUDE_DIR 46 | AVUTIL_LIBRARY 47 | VERSION_VAR FFMPEG_VERSION 48 | ) 49 | 50 | if(FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR) 51 | set(FFMPEG_FOUND TRUE) 52 | else() 53 | # use pkg-config to get the directories and then use these values 54 | # in the FIND_PATH() and FIND_LIBRARY() calls 55 | find_package(PkgConfig) 56 | if(PKG_CONFIG_FOUND) 57 | pkg_check_modules(_FFMPEG_AVCODEC libavcodec) 58 | pkg_check_modules(_FFMPEG_AVFORMAT libavformat) 59 | pkg_check_modules(_FFMPEG_AVUTIL libavutil) 60 | endif() 61 | 62 | # AVCODEC 63 | find_path(AVCODEC_INCLUDE_DIR 64 | NAMES libavcodec/avcodec.h 65 | PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS} 66 | /usr/local/include 67 | /usr/include 68 | /opt/local/include 69 | /sw/include 70 | PATH_SUFFIXES ffmpeg libav 71 | ) 72 | mark_as_advanced(AVCODEC_INCLUDE_DIR) 73 | find_library(AVCODEC_LIBRARY 74 | NAMES avcodec 75 | PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS} 76 | /usr/local/lib 77 | /usr/lib 78 | /opt/local/lib 79 | /sw/lib 80 | ) 81 | mark_as_advanced(AVCODEC_LIBRARY) 82 | 83 | # AVFORMAT 84 | find_path(AVFORMAT_INCLUDE_DIR 85 | NAMES libavformat/avformat.h 86 | PATHS ${_FFMPEG_AVFORMAT_INCLUDE_DIRS} 87 | /usr/local/include 88 | /usr/include 89 | /opt/local/include 90 | /sw/include 91 | PATH_SUFFIXES ffmpeg libav 92 | ) 93 | mark_as_advanced(AVFORMAT_INCLUDE_DIR) 94 | find_library(AVFORMAT_LIBRARY 95 | NAMES avformat 96 | PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS} 97 | /usr/local/lib 98 | /usr/lib 99 | /opt/local/lib 100 | /sw/lib 101 | ) 102 | mark_as_advanced(AVFORMAT_LIBRARY) 103 | 104 | # AVUTIL 105 | find_path(AVUTIL_INCLUDE_DIR 106 | NAMES libavutil/avutil.h 107 | PATHS ${_FFMPEG_AVUTIL_INCLUDE_DIRS} 108 | /usr/local/include 109 | /usr/include 110 | /opt/local/include 111 | /sw/include 112 | PATH_SUFFIXES ffmpeg libav 113 | ) 114 | mark_as_advanced(AVUTIL_INCLUDE_DIR) 115 | find_library(AVUTIL_LIBRARY 116 | NAMES avutil 117 | PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS} 118 | /usr/local/lib 119 | /usr/lib 120 | /opt/local/lib 121 | /sw/lib 122 | ) 123 | mark_as_advanced(AVUTIL_LIBRARY) 124 | 125 | if(AVCODEC_LIBRARY AND AVFORMAT_LIBRARY) 126 | set(FFMPEG_FOUND TRUE) 127 | endif() 128 | 129 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS 58.18.100 OR _FFMPEG_AVFORMAT_VERSION VERSION_LESS 58.12.100 OR _FFMPEG_AVUTIL_VERSION VERSION_LESS 56.14.100) 130 | if(FFMPEG_FOUND) 131 | message("-- ${White}FFMPEG required min version - 4.0.4 Found:${FFMPEG_VERSION}") 132 | message("-- ${White}AVCODEC required min version - 58.18.100 Found:${_FFMPEG_AVCODEC_VERSION}${ColourReset}") 133 | message("-- ${White}AVFORMAT required min version - 58.12.100 Found:${_FFMPEG_AVFORMAT_VERSION}${ColourReset}") 134 | message("-- ${White}AVUTIL required min version - 56.14.100 Found:${_FFMPEG_AVUTIL_VERSION}${ColourReset}") 135 | endif() 136 | set(FFMPEG_FOUND FALSE) 137 | message( "-- ${Yellow}NOTE: FindFFmpeg failed to find -- FFMPEG${ColourReset}" ) 138 | endif() 139 | 140 | if(FFMPEG_FOUND) 141 | set(FFMPEG_INCLUDE_DIR ${AVFORMAT_INCLUDE_DIR} CACHE INTERNAL "") 142 | set(FFMPEG_LIBRARIES 143 | ${AVCODEC_LIBRARY} 144 | ${AVFORMAT_LIBRARY} 145 | ${AVUTIL_LIBRARY} 146 | CACHE INTERNAL "" 147 | ) 148 | endif() 149 | 150 | if(FFMPEG_FOUND) 151 | message("-- ${White}Using FFMPEG -- \n\tLibraries:${FFMPEG_LIBRARIES} \n\tIncludes:${FFMPEG_INCLUDE_DIR}${ColourReset}") 152 | else() 153 | if(FFmpeg_FIND_REQUIRED) 154 | message(FATAL_ERROR "{Red}FindFFmpeg -- libavcodec or libavformat or libavutil NOT FOUND${ColourReset}") 155 | endif() 156 | endif() 157 | endif() 158 | 159 | -------------------------------------------------------------------------------- /cmake/FindLibdrm_amdgpu.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2024 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | find_library(LIBDRM_AMDGPU_LIBRARY NAMES drm_amdgpu HINTS /opt/amdgpu/lib/x86_64-linux-gnu /opt/amdgpu/lib64 /usr/lib/x86_64-linux-gnu /usr/lib64) 25 | find_path(LIBDRM_AMDGPU_INCLUDE_DIR NAMES libdrm/amdgpu.h libdrm/amdgpu_drm.h PATHS /opt/amdgpu/include /usr/include /usr/ /usr/local/include NO_DEFAULT_PATH) 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(Libdrm_amdgpu DEFAULT_MSG LIBDRM_AMDGPU_INCLUDE_DIR LIBDRM_AMDGPU_LIBRARY) 29 | mark_as_advanced(LIBDRM_AMDGPU_INCLUDE_DIR LIBDRM_AMDGPU_LIBRARY) 30 | 31 | if(Libdrm_amdgpu_FOUND) 32 | if(NOT TARGET Libdrm_amdgpu::drm_amdgpu) 33 | add_library(Libdrm_amdgpu::drm_amdgpu UNKNOWN IMPORTED) 34 | set_target_properties(Libdrm_amdgpu::drm_amdgpu PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBDRM_AMDGPU_INCLUDE_DIR}" 35 | IMPORTED_LOCATION "${LIBDRM_AMDGPU_LIBRARY}") 36 | endif() 37 | message("-- ${White}Using Libdrm_amdgpu -- \n\tLibraries:${LIBDRM_AMDGPU_LIBRARY} \n\tIncludes:${LIBDRM_AMDGPU_INCLUDE_DIR} ${ColourReset}") 38 | else() 39 | if(Libdrm_amdgpu_FIND_REQUIRED) 40 | message(FATAL_ERROR "{Red}FindLibdrm_amdgpu -- Libdrm_admgpu NOT FOUND${ColourReset}") 41 | endif() 42 | endif() -------------------------------------------------------------------------------- /cmake/FindLibva.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | find_library(LIBVA_LIBRARY NAMES va HINTS /opt/amdgpu/lib/x86_64-linux-gnu /opt/amdgpu/lib64 /usr/lib/x86_64-linux-gnu /usr/lib64) 25 | find_library(LIBVA_DRM_LIBRARY NAMES va-drm HINTS /opt/amdgpu/lib/x86_64-linux-gnu /opt/amdgpu/lib64 /usr/lib/x86_64-linux-gnu /usr/lib64) 26 | find_path(LIBVA_INCLUDE_DIR NAMES va/va.h PATHS /opt/amdgpu/include NO_DEFAULT_PATH) 27 | 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args(Libva DEFAULT_MSG LIBVA_INCLUDE_DIR LIBVA_LIBRARY) 30 | mark_as_advanced(LIBVA_INCLUDE_DIR LIBVA_LIBRARY LIBVA_DRM_LIBRARY) 31 | 32 | if(Libva_FOUND) 33 | # Find VA Version 34 | file(READ "${LIBVA_INCLUDE_DIR}/va/va_version.h" VA_VERSION_FILE) 35 | string(REGEX MATCH "VA_MAJOR_VERSION ([0-9]*)" _ ${VA_VERSION_FILE}) 36 | set(va_ver_major ${CMAKE_MATCH_1}) 37 | string(REGEX MATCH "VA_MINOR_VERSION ([0-9]*)" _ ${VA_VERSION_FILE}) 38 | set(va_ver_minor ${CMAKE_MATCH_1}) 39 | string(REGEX MATCH "VA_MICRO_VERSION ([0-9]*)" _ ${VA_VERSION_FILE}) 40 | set(va_ver_micro ${CMAKE_MATCH_1}) 41 | message("-- ${White}Found Libva Version: ${va_ver_major}.${va_ver_minor}.${va_ver_micro}${ColourReset}") 42 | 43 | if((${va_ver_major} GREATER_EQUAL 1) AND (${va_ver_minor} GREATER_EQUAL 16)) 44 | message("-- ${White}\tLibva Version Supported${ColourReset}") 45 | else() 46 | set(Libva_FOUND FALSE) 47 | message("-- ${Yellow}\tLibva Version Not Supported${ColourReset}") 48 | endif() 49 | endif() 50 | 51 | if(Libva_FOUND) 52 | if(NOT TARGET Libva::va) 53 | add_library(Libva::va UNKNOWN IMPORTED) 54 | set_target_properties(Libva::va PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBVA_INCLUDE_DIR}" 55 | IMPORTED_LOCATION "${LIBVA_LIBRARY}") 56 | endif() 57 | if(NOT TARGET Libva::va_drm) 58 | add_library(Libva::va_drm UNKNOWN IMPORTED) 59 | set_target_properties(Libva::va_drm PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBVA_INCLUDE_DIR}" 60 | IMPORTED_LOCATION "${LIBVA_DRM_LIBRARY}") 61 | endif() 62 | message("-- ${White}Using Libva -- \n\tLibraries:${LIBVA_LIBRARY} \n\tIncludes:${LIBVA_INCLUDE_DIR}${ColourReset}") 63 | message("-- ${White}Using Libva-drm -- \n\tLibraries:${LIBVA_DRM_LIBRARY}${ColourReset}") 64 | else() 65 | if(Libva_FIND_REQUIRED) 66 | message(FATAL_ERROR "{Red}FindLibva -- Libva NOT FOUND${ColourReset}") 67 | endif() 68 | endif() -------------------------------------------------------------------------------- /cmake_modules/rocdecode-config.cmake.in: -------------------------------------------------------------------------------- 1 | # - Config file for the rocdecode package 2 | # It defines the following variables 3 | # ROCDECODE_INCLUDE_DIR - include directory for rocdecode 4 | # ROCDECODE_LIB_DIR - library directory for rocdecode 5 | # ROCDECODE_LIBRARY - library to link against 6 | 7 | @PACKAGE_INIT@ 8 | 9 | # Compute paths 10 | set_and_check(rocdecode_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 11 | set_and_check(ROCDECODE_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 12 | set_and_check(rocDecode_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 13 | set_and_check(rocdecode_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") 14 | set_and_check(ROCDECODE_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") 15 | set_and_check(rocDecode_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") 16 | set_and_check(rocdecode_LIBRARY "@PACKAGE_LIB_INSTALL_DIR@/librocdecode.so") 17 | set_and_check(ROCDECODE_LIBRARY "@PACKAGE_LIB_INSTALL_DIR@/librocdecode.so") 18 | set_and_check(rocDecode_LIBRARY "@PACKAGE_LIB_INSTALL_DIR@/librocdecode.so") 19 | 20 | 21 | get_filename_component(ROCDECODE_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 22 | include("${ROCDECODE_CMAKE_DIR}/rocdecode-targets.cmake") 23 | -------------------------------------------------------------------------------- /data/videos/AMD_driving_virtual_20-AV1.ivf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/data/videos/AMD_driving_virtual_20-AV1.ivf -------------------------------------------------------------------------------- /data/videos/AMD_driving_virtual_20-AV1.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/data/videos/AMD_driving_virtual_20-AV1.mp4 -------------------------------------------------------------------------------- /data/videos/AMD_driving_virtual_20-H264.264: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/data/videos/AMD_driving_virtual_20-H264.264 -------------------------------------------------------------------------------- /data/videos/AMD_driving_virtual_20-H264.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/data/videos/AMD_driving_virtual_20-H264.mp4 -------------------------------------------------------------------------------- /data/videos/AMD_driving_virtual_20-H265.265: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/data/videos/AMD_driving_virtual_20-H265.265 -------------------------------------------------------------------------------- /data/videos/AMD_driving_virtual_20-H265.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/data/videos/AMD_driving_virtual_20-H265.mp4 -------------------------------------------------------------------------------- /data/videos/AMD_driving_virtual_20-VP9.ivf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/data/videos/AMD_driving_virtual_20-VP9.ivf -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # rocDecode Docker 2 | 3 | ## Build - dockerfiles 4 | 5 | ``` 6 | sudo docker build -f {DOCKER_FILE_NAME}.dockerfile -t {DOCKER_IMAGE_NAME} . 7 | ``` 8 | 9 | ## Run - docker 10 | 11 | ``` 12 | sudo docker run -it --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --device=/dev/mem --group-add video --network host --privileged {DOCKER_IMAGE_NAME} 13 | ``` -------------------------------------------------------------------------------- /docker/rocDecode-on-ubuntu20.dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | # install base dependencies 4 | RUN apt-get update -y 5 | #RUN apt-get dist-upgrade -y 6 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y install gcc g++ cmake pkg-config git apt-utils sudo vainfo dialog 7 | 8 | # install ROCm 9 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y install initramfs-tools libnuma-dev wget keyboard-configuration && \ 10 | wget https://repo.radeon.com/amdgpu-install/6.1/ubuntu/focal/amdgpu-install_6.1.60100-1_all.deb && \ 11 | sudo apt-get install -y ./amdgpu-install_6.1.60100-1_all.deb && \ 12 | sudo amdgpu-install -y --usecase=rocm 13 | 14 | WORKDIR /workspace 15 | 16 | # install rocDecode package 17 | RUN DEBIAN_FRONTEND=noninteractive sudo apt install -y rocdecode rocdecode-dev rocdecode-test -------------------------------------------------------------------------------- /docker/rocDecode-on-ubuntu22.dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | # install base dependencies 4 | RUN apt-get update -y 5 | #RUN apt-get dist-upgrade -y 6 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y install gcc g++ cmake pkg-config git apt-utils sudo vainfo dialog libstdc++-12-dev 7 | 8 | # install ROCm 9 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y install initramfs-tools libnuma-dev wget keyboard-configuration && \ 10 | wget https://repo.radeon.com/amdgpu-install/6.1/ubuntu/jammy/amdgpu-install_6.1.60100-1_all.deb && \ 11 | sudo apt-get install -y ./amdgpu-install_6.1.60100-1_all.deb && \ 12 | sudo amdgpu-install -y --usecase=rocm 13 | 14 | WORKDIR /workspace 15 | 16 | # install rocDecode package 17 | RUN DEBIAN_FRONTEND=noninteractive sudo apt install -y rocdecode rocdecode-dev rocdecode-test -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | _doxygen/ 3 | -------------------------------------------------------------------------------- /docs/conceptual/rocDecode-memory-types.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: rocDecode memory types 3 | :keywords: parse video, parse, decode, video decoder, video decoding, rocDecode, AMD, ROCm, memory types 4 | 5 | ******************************************************************** 6 | rocDecode surface data memory locations 7 | ******************************************************************** 8 | 9 | Surface data memory refers to the memory used by rocDecode for decoded frames and processing results. There are three locations where surface data memory can be stored: device memory, host memory, and internal memory. 10 | 11 | Device memory refers to GPU memory. It's optimized for operations performed by the GPU, avoiding unnecessary memory transfers between the device and the host. It's used for standalone GPU processing and high-performance computing tasks where multiple operations are performed on the same data. 12 | 13 | 14 | Host memory refers to CPU memory. It's suitable for when the memory needs to be accessed or manipulated by CPU-side applications or when data needs to be transferred between systems. 15 | 16 | Internal memory refers to intermediate GPU memory that is shared between operators. It's optimized for operator chaining within GPU workflows. It keeps data localized on the GPU so it can be accessed by subsequent operations, reducing latency and improving throughput. For example, in image processing pipelines, the results of a resizing operator can directly feed into a filtering operator without needing to copy data to the host between each step. This optimization is especially useful for large datasets and real-time applications. 17 | 18 | 19 | The ``OutputSurfaceMemoryType_enum`` enum type defines ``OUT_SURFACE_MEM_DEV_COPIED``, ``OUT_SURFACE_MEM_HOST_COPIED``, and ``OUT_SURFACE_MEM_DEV_INTERNAL``, for the three different types of memory locations. ``OUT_SURFACE_MEM_DEV_COPIED`` indicates device, or GPU, memory. ``OUT_SURFACE_MEM_HOST_COPIED`` indicates host, or CPU, memory. And ``OUT_SURFACE_MEM_DEV_INTERNAL`` indicates intermediate GPU memory. 20 | 21 | ``OUT_SURFACE_MEM_DEV_COPIED`` is not supported when the FFmpeg decoder is used. 22 | 23 | A fourth enum, ``OUT_SURFACE_MEM_NOT_MAPPED``, is used only for performance purposes. The decoded frames are not available when this memory type is used. 24 | 25 | -------------------------------------------------------------------------------- /docs/conceptual/video-decoding-pipeline.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: Video decoding pipeline 3 | :keywords: video decoder, video decoding, rocDecode, AMD, ROCm 4 | 5 | ******************************************************************** 6 | Video decoding pipeline 7 | ******************************************************************** 8 | 9 | .. image:: ../data/VideoDecoderPipelinetest.png 10 | :alt: Video decoder pipeline test 11 | 12 | There are three main components in rocDecode: 13 | 14 | * Demuxer: Our demuxer is based on FFmpeg, a leading multimedia framework. For more information, 15 | refer to the `FFmpeg website `_. 16 | * Video parser APIs 17 | * Video decoder APIs 18 | 19 | rocDecode follows this workflow: 20 | 21 | 1. The demuxer extracts a segment of video data and sends it to the video parser. 22 | 2. The video parser extracts crucial information, such as picture and slice parameters, and sends it to 23 | the decoder APIs. 24 | 3. The hardware receives the picture and slice parameters, then decodes a frame using Video 25 | Acceleration API (VA-API). 26 | 4. This process repeats in a loop until all frames have been decoded. 27 | 28 | Steps in decoding video content for applications (available in the rocDecode Toolkit): 29 | 30 | 1. Demultiplex the content into elementary stream packets (FFmpeg) 31 | 2. Parse the demultiplexed packets into video frames for the decoder provided by rocDecode API. 32 | 3. Decode compressed video frames into YUV frames using rocDecode API. 33 | 4. Wait for the decoding to finish. 34 | 5. Get the decoded YUV frame from amd-gpu context to HIP (using VAAPI-HIP interoperability under 35 | ROCm). 36 | 6. Run HIP kernels in the mapped YUV frame. For example, format conversion, scaling, object detection, 37 | classification, and others. 38 | 7. Release the decoded frame. 39 | 40 | .. note:: 41 | YUV is a color space that represents images using luminance (Y) for brightness and two chrominance 42 | components (U and V) for color information. 43 | 44 | The preceding steps are demonstrated in the sample applications located in our 45 | `GitHub repository `_ directory. 46 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved. 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # Configuration file for the Sphinx documentation builder. 24 | # 25 | # This file only contains a selection of the most common options. For a full 26 | # list see the documentation: 27 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 28 | 29 | import re 30 | 31 | from rocm_docs import ROCmDocs 32 | 33 | with open('../CMakeLists.txt', encoding='utf-8') as f: 34 | match = re.search(r'.*\bset\(VERSION\s+\"?([0-9.]+)[^0-9.]+', f.read()) 35 | if not match: 36 | raise ValueError("VERSION not found!") 37 | version_number = match[1] 38 | left_nav_title = f"rocDecode {version_number} documentation" 39 | 40 | # for PDF output on Read the Docs 41 | project = "rocDecode documentation" 42 | author = "Advanced Micro Devices, Inc." 43 | copyright = "Copyright (c) 2024 - 2025 Advanced Micro Devices, Inc. All rights reserved." 44 | version = version_number 45 | release = version_number 46 | 47 | external_toc_path = "./sphinx/_toc.yml" 48 | 49 | docs_core = ROCmDocs(left_nav_title) 50 | docs_core.run_doxygen(doxygen_root="doxygen", doxygen_path="doxygen/xml") 51 | docs_core.enable_api_reference() 52 | docs_core.setup() 53 | 54 | external_projects_current_project = "rocdecode" 55 | 56 | for sphinx_var in ROCmDocs.SPHINX_VARS: 57 | globals()[sphinx_var] = getattr(docs_core, sphinx_var) 58 | -------------------------------------------------------------------------------- /docs/data/AMD-Logo-Doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/docs/data/AMD-Logo-Doxygen.png -------------------------------------------------------------------------------- /docs/data/AMD_rocDecode_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/docs/data/AMD_rocDecode_Logo.png -------------------------------------------------------------------------------- /docs/data/VideoDecoderPipelinetest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/rocDecode/0f89c9c17c3944d5359b6adb8cd7b5dfedc6501a/docs/data/VideoDecoderPipelinetest.png -------------------------------------------------------------------------------- /docs/doxygen/.gitignore: -------------------------------------------------------------------------------- 1 | html/ 2 | latex/ 3 | xml/ 4 | -------------------------------------------------------------------------------- /docs/how-to/using-rocDecode-bitstream.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: Using the rocDecode bitstream reader API 3 | :keywords: rocDecode, AMD, ROCm, bitstream decoder 4 | 5 | ******************************************************************** 6 | Using the rocDecode bitstream reader APIs 7 | ******************************************************************** 8 | 9 | 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. 10 | 11 | .. note:: 12 | 13 | The bitstream reader APIs can only be used with elementary video streams and IVF container files. 14 | 15 | 16 | The |videodecoderaw|_ 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: 17 | 18 | .. code:: C++ 19 | 20 | RocdecBitstreamReader bs_reader = nullptr; 21 | rocDecVideoCodec rocdec_codec_id; 22 | int bit_depth; 23 | if (rocDecCreateBitstreamReader(&bs_reader, input_file_path.c_str()) != ROCDEC_SUCCESS) { 24 | std::cerr << "Failed to create the bitstream reader." << std::endl; 25 | return 1; 26 | } 27 | [...] 28 | # Decode loop: 29 | do { 30 | if (rocDecGetBitstreamPicData(bs_reader, &pvideo, &n_video_bytes, &pts) != ROCDEC_SUCCESS) { 31 | std::cerr << "Failed to get picture data." << std::endl; 32 | return 1; 33 | } 34 | [...] 35 | n_frame_returned = viddec.DecodeFrame(pvideo, n_video_bytes, pkg_flags, pts, &decoded_pics); 36 | } 37 | 38 | 39 | The ``videodecoderaw.cpp`` example also demonstrates how to use the bitstream reader APIs to obtain the bit depth and codec of a stream: 40 | 41 | .. code:: C++ 42 | 43 | if (rocDecGetBitstreamCodecType(bs_reader, &rocdec_codec_id) != ROCDEC_SUCCESS) { 44 | std::cerr << "Failed to get stream codec type." << std::endl; 45 | return 1; 46 | } 47 | [...] 48 | if (rocDecGetBitstreamBitDepth(bs_reader, &bit_depth) != ROCDEC_SUCCESS) { 49 | std::cerr << "Failed to get stream bit depth." << std::endl; 50 | return 1; 51 | } 52 | 53 | 54 | .. note:: 55 | 56 | ``rocDecDestroyBitstreamReader`` must always be called to destroy the bitstream reader once processing is complete. 57 | 58 | 59 | .. |videodecode| replace:: ``videodecode.cpp`` 60 | .. _videodecode: https://github.com/ROCm/rocDecode/tree/develop/samples/videoDecode/videodecode.cpp 61 | 62 | .. |videodecoderaw| replace:: ``videodecoderaw.cpp`` 63 | .. _videodecoderaw: https://github.com/ROCm/rocDecode/tree/develop/samples/videoDecodeRaw 64 | 65 | .. |common| replace:: ``common.h`` 66 | .. _common: https://github.com/ROCm/rocDecode/blob/develop/samples/common.h 67 | 68 | .. |apifolder| replace:: ``api`` folder 69 | .. _apifolder: https://github.com/ROCm/rocDecode/tree/develop/api 70 | 71 | .. |utilsfolder| replace:: ``utils`` folder 72 | .. _utilsfolder: https://github.com/ROCm/rocDecode/tree/develop/utils 73 | 74 | 75 | .. |reconfig_struct| replace:: ``ReconfigParams_t`` 76 | .. _reconfig_struct: https://rocm.docs.amd.com/projects/rocDecode/en/latest/doxygen/html/structReconfigParams__t.html -------------------------------------------------------------------------------- /docs/how-to/using-rocDecode-ffmpeg.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: Using rocDecode with the FFMpeg demultiplexer 3 | :keywords: parse video, parse, rocDecode, AMD, ROCm, FFmpeg demuxer 4 | 5 | ******************************************************************** 6 | Using the rocDecode FFmpeg demultiplexer 7 | ******************************************************************** 8 | 9 | The rocDecode FFmpeg demultiplexer (demuxer) extracts coded picture data from digital media files. 10 | 11 | To use the rocDecode FFmpeg demuxer , import the ``video_demuxer.h`` header file. 12 | 13 | .. code:: C++ 14 | 15 | #include "video_demuxer.h" 16 | 17 | Instantiate a ``VideoDemuxer`` with the path to the video file. The ``GetCodecId`` and ``GetBitDepth`` functions can be used to obtain the video stream's codec ID and bit depth. The ``AVCodec2RocDecVideoCodec`` utility function converts the codec ID returned from the demuxer to its corresponding ``rocDecVideoCodec_enum`` value. 18 | 19 | .. code:: C++ 20 | 21 | VideoDemuxer *demuxer; 22 | demuxer = new VideoDemuxer(input_file_path.c_str()); 23 | rocdec_codec_id = AVCodec2RocDecVideoCodec(demuxer->GetCodecID()); 24 | bit_depth = demuxer->GetBitDepth(); 25 | 26 | Call ``Demux`` to extract frame data from the stream: 27 | 28 | .. code:: C++ 29 | 30 | demuxer->Demux(&pvideo, &n_video_bytes, &pts); 31 | 32 | The demuxer will demultiplex frames sequentially starting at the beginning of the stream. To start the demultiplexing and decoding process from a different frame, create a seek context that specifies a seek criteria and a seek mode. 33 | 34 | The seek criteria describes whether the demuxer needs to seek to a specific frame or seek to a specific timestamp. The seek mode indicates whether the demuxer should seek to the exact frame or to the previous keyframe. 35 | 36 | The seek criteria is defined by the ``SeekCriteriaEnum`` enum and the seek mode is defined by the ``SeekModeEnum`` enum. Both the ``SeekCriteriaEnum`` and the ``SeekModeEnum`` are defined in ``video_demuxer.h``. 37 | 38 | Set the seek criteria to ``SEEK_CRITERIA_FRAME_NUM`` to seek to a frame or to ``SEEK_CRITERIA_TIME_STAMP`` to seek to a timestamp. Set the seek mode to ``SEEK_MODE_EXACT_FRAME`` to seek to the exact frame or to ``SEEK_MODE_PREV_KEY_FRAME`` to seek to the previous keyframe. 39 | 40 | From |videodecode|_: 41 | 42 | .. code:: C++ 43 | 44 | VideoSeekContext video_seek_ctx; 45 | [...] 46 | do { 47 | [...] 48 | if (seek_criteria == 1 && first_frame) { 49 | // use VideoSeekContext class to seek to given frame number 50 | video_seek_ctx.seek_frame_ = seek_to_frame; 51 | video_seek_ctx.seek_crit_ = SEEK_CRITERIA_FRAME_NUM; 52 | video_seek_ctx.seek_mode_ = (seek_mode ? SEEK_MODE_EXACT_FRAME : SEEK_MODE_PREV_KEY_FRAME); 53 | demuxer->Seek(video_seek_ctx, &pvideo, &n_video_bytes); 54 | pts = video_seek_ctx.out_frame_pts_; 55 | std::cout << "info: Number of frames that were decoded during seek - " << video_seek_ctx.num_frames_decoded_ << std::endl; 56 | first_frame = false; 57 | } else if (seek_criteria == 2 && first_frame) { 58 | // use VideoSeekContext class to seek to given timestamp 59 | video_seek_ctx.seek_frame_ = seek_to_frame; 60 | video_seek_ctx.seek_crit_ = SEEK_CRITERIA_TIME_STAMP; 61 | video_seek_ctx.seek_mode_ = (seek_mode ? SEEK_MODE_EXACT_FRAME : SEEK_MODE_PREV_KEY_FRAME); 62 | demuxer->Seek(video_seek_ctx, &pvideo, &n_video_bytes); 63 | pts = video_seek_ctx.out_frame_pts_; 64 | std::cout << "info: Duration of frame found after seek - " << video_seek_ctx.out_frame_duration_ << " ms" << std::endl; 65 | first_frame = false; 66 | } else { 67 | demuxer->Demux(&pvideo, &n_video_bytes, &pts); 68 | } 69 | [...] 70 | } while (n_video_bytes); 71 | 72 | Delete the demuxer once demultiplexing is complete. 73 | 74 | .. code:: C++ 75 | 76 | delete demuxer; 77 | 78 | .. |videodecode| replace:: ``videodecode.cpp`` 79 | .. _videodecode: https://github.com/ROCm/rocDecode/tree/develop/samples/videoDecode/videodecode.cpp 80 | 81 | .. |videodecoderaw| replace:: ``videodecoderaw.cpp`` 82 | .. _videodecoderaw: https://github.com/ROCm/rocDecode/tree/develop/samples/videoDecodeRaw 83 | 84 | .. |common| replace:: ``common.h`` 85 | .. _common: https://github.com/ROCm/rocDecode/blob/develop/samples/common.h 86 | 87 | .. |apifolder| replace:: ``api`` folder 88 | .. _apifolder: https://github.com/ROCm/rocDecode/tree/develop/api 89 | 90 | .. |utilsfolder| replace:: ``utils`` folder 91 | .. _utilsfolder: https://github.com/ROCm/rocDecode/tree/develop/utils 92 | 93 | 94 | .. |reconfig_struct| replace:: ``ReconfigParams_t`` 95 | .. _reconfig_struct: https://rocm.docs.amd.com/projects/rocDecode/en/latest/doxygen/html/structReconfigParams__t.html 96 | 97 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: rocDecode documentation and API reference library 3 | :keywords: rocDecode, ROCm, API, documentation, video, decode, decoding, acceleration 4 | 5 | ******************************************************************** 6 | rocDecode documentation 7 | ******************************************************************** 8 | 9 | rocDecode provides APIs, utilities, and samples that you can use to easily access the video decoding 10 | features of your media engines (VCNs). It also allows interoperability with other compute engines on 11 | the GPU using Video Acceleration API (VA-API)/HIP. To learn more, see :doc:`what-is-rocDecode` 12 | 13 | The rocDecode public repository is located at `https://github.com/ROCm/rocDecode `_. 14 | 15 | .. grid:: 2 16 | :gutter: 3 17 | 18 | .. grid-item-card:: Install 19 | 20 | * :doc:`Installing rocDecode with the package installer <./install/rocDecode-package-install>` 21 | * :doc:`Building and installing rocDecode from source code <./install/rocDecode-build-and-install>` 22 | * `rocDecode Docker containers `_ 23 | 24 | .. grid:: 2 25 | :gutter: 3 26 | 27 | .. grid-item-card:: Conceptual 28 | 29 | * :doc:`Video decoding pipeline <./conceptual/video-decoding-pipeline>` 30 | * :doc:`rocDecode surface memory locations <./conceptual/rocDecode-memory-types>` 31 | 32 | .. grid-item-card:: How to 33 | 34 | * :doc:`Understand the rocDecode videodecode.cpp sample <./how-to/using-rocDecode-videodecode-sample>` 35 | * :doc:`Use the rocDecode RocVideoDecoder <./how-to/using-rocDecode-video-decoder>` 36 | * :doc:`Use the rocDecode FFmpeg demultiplexer <./how-to/using-rocDecode-ffmpeg>` 37 | * :doc:`Use the rocDecode bitstream reader APIs <./how-to/using-rocDecode-bitstream>` 38 | * :doc:`Use the rocDecode core APIs <./how-to/using-rocdecode>` 39 | 40 | 41 | .. grid-item-card:: Samples 42 | 43 | * :doc:`rocDecode samples <./tutorials/rocDecode-samples>` 44 | 45 | .. grid-item-card:: Reference 46 | 47 | * :doc:`rocDecode codec support and hardware capabilities <./reference/rocDecode-formats-and-architectures>` 48 | * :doc:`rocDecode tested configurations <./reference/rocDecode-tested-configurations>` 49 | * :doc:`API library <../doxygen/html/files>` 50 | * :doc:`Functions <../doxygen/html/globals>` 51 | * :doc:`Data structures <../doxygen/html/annotated>` 52 | 53 | To contribute to the documentation, refer to 54 | `Contributing to ROCm `_. 55 | 56 | You can find licensing information on the 57 | `Licensing `_ page. 58 | -------------------------------------------------------------------------------- /docs/install/rocDecode-build-and-install.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: Build and install rocDecode with the source code 3 | :keywords: install, building, rocDecode, AMD, ROCm, source code, developer 4 | 5 | ******************************************************************** 6 | Building and installing rocDecode from source code 7 | ******************************************************************** 8 | 9 | If you will be contributing to the rocDecode code base, or if you want to preview new features, build rocDecode from its source code. 10 | 11 | If you will not be previewing features or contributing to the code base, use the :doc:`package installers <./rocDecode-package-install>` to install rocDecode. 12 | 13 | Before building rocDecode, use `rocDecode-setup.py `_ to install all the required prerequisites: 14 | 15 | .. code:: shell 16 | 17 | python3 rocDecode-setup.py [--rocm_path ROCM_INSTALLATION_PATH; default=/opt/rocm] 18 | [--runtime {ON|OFF}; default=ON] 19 | [--developer {ON|OFF}; default=OFF] 20 | 21 | .. note:: 22 | 23 | Never run ``rocDecode-setup.py`` with ``--runtime OFF``. 24 | 25 | ``--developer ON`` is required to use the code samples. 26 | 27 | Build and install rocDecode using the following commands: 28 | 29 | .. code:: shell 30 | 31 | git clone https://github.com/ROCm/rocDecode.git 32 | cd rocDecode 33 | mkdir build && cd build 34 | cmake ../ 35 | make -j8 36 | sudo make install 37 | 38 | After installation, the rocDecode libraries will be copied to ``/opt/rocm/lib`` and the rocDecode header files will be copied to ``/opt/rocm/include/rocdecode``. 39 | 40 | Build and install the rocDecode test module. This module is required if you'll be using the rocDecode samples, and can only be installed if ``rocDecode-setup.py`` was run with ``--developer ON``. 41 | 42 | .. code:: shell 43 | 44 | mkdir rocdecode-test && cd rocdecode-test 45 | cmake /opt/rocm/share/rocdecode/test/ 46 | ctest -VV 47 | 48 | Run ``make test`` to test your build. To run the test with the verbose option, run ``make test ARGS="-VV"``. 49 | 50 | To create a package installer for rocDecode, run: 51 | 52 | .. code:: shell 53 | 54 | sudo make package 55 | 56 | -------------------------------------------------------------------------------- /docs/install/rocDecode-package-install.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: Installing rocDecode with the package installer 3 | :keywords: install, rocDecode, AMD, ROCm, basic, development, package 4 | 5 | ******************************************************************** 6 | Installing rocDecode with the package installer 7 | ******************************************************************** 8 | 9 | Three rocDecode packages are available: 10 | 11 | * ``rocdecode``: The rocDecode runtime package. This is the basic rocDecode package. It must always be installed. 12 | * ``rocdecode-dev``: The rocDecode development package. This package installs a full suite of libraries, header files, and samples. This package needs to be installed to use the rocDecode samples. 13 | * ``rocdecode-test``: A test package that provides a CTest to verify the installation. This package needs to be installed to use the rocDecode samples. 14 | 15 | All the required prerequisites are installed when the package installation method is used. 16 | 17 | 18 | Basic installation 19 | ======================================== 20 | 21 | Use the following commands to install only the rocDecode runtime package: 22 | 23 | .. tab-set:: 24 | 25 | .. tab-item:: Ubuntu 26 | 27 | .. code:: shell 28 | 29 | sudo apt install rocdecode 30 | 31 | .. tab-item:: RHEL 32 | 33 | .. code:: shell 34 | 35 | sudo yum install rocdecode 36 | 37 | .. tab-item:: SLES 38 | 39 | .. code:: shell 40 | 41 | sudo zypper install rocdecode 42 | 43 | 44 | Complete installation 45 | ======================================== 46 | 47 | Use the following commands to install ``rocdecode``, ``rocdecode-dev``, and ``rocdecode-test``: 48 | 49 | .. tab-set:: 50 | 51 | .. tab-item:: Ubuntu 52 | 53 | .. code:: shell 54 | 55 | sudo apt install rocdecode rocdecode-dev rocdecode-test 56 | 57 | .. tab-item:: RHEL 58 | 59 | .. code:: shell 60 | 61 | sudo yum install rocdecode rocdecode-devel rocdecode-test 62 | 63 | .. tab-item:: SLES 64 | 65 | .. code:: shell 66 | 67 | sudo zypper install rocdecode rocdecode-devel rocdecode-test 68 | -------------------------------------------------------------------------------- /docs/install/rocDecode-prerequisites.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: rocDecode Installation Prerequisites 3 | :keywords: install, rocDecode, AMD, ROCm, prerequisites, dependencies, requirements 4 | 5 | ******************************************************************** 6 | rocDecode prerequisites 7 | ******************************************************************** 8 | 9 | rocDecode requires ROCm 6.1 or later running on `accelerators based on the CDNA architecture `_. 10 | 11 | ROCm must be installed using the [AMDGPU installer](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/amdgpu-install.html) with the ``rocm`` usecase: 12 | 13 | .. code:: shell 14 | 15 | sudo amdgpu-install --usecase=rocm 16 | 17 | rocDecode can be installed on the following Linux environments: 18 | 19 | * Ubuntu 22.04, 24.04 20 | * RHEL 8 or 9 21 | * SLES: 15-SP5 22 | 23 | The following prerequisites are installed by the package installer. If you are building and installing using the source code, use the `rocDecode-setup.py `_ to install these prerequisites. 24 | 25 | .. note:: 26 | 27 | To use the rocDecode samples, the ``rocdecode``, ``rocdecode-dev``, and ``rocdecode-test`` packages need to be installed. 28 | 29 | If you're installing using the rocDecode source code, the ``rocDecode-setup.py`` script must be run with ``--developer`` set to ``ON``. 30 | 31 | * Libva-amdgpu-dev, an AMD implementation for Video Acceleration API (VA-API) 32 | * AMD VA Drivers 33 | * CMake version 3.10 or later 34 | * AMD Clang++ Version 18.0.0 or later 35 | * pkg-config 36 | * FFmpeg runtime and headers 37 | * libstdc++-12-dev for installations on Ubuntu 22.04 38 | -------------------------------------------------------------------------------- /docs/license.md: -------------------------------------------------------------------------------- 1 | # License 2 | 3 | ```{include} ../LICENSE 4 | ``` 5 | -------------------------------------------------------------------------------- /docs/reference/index.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | # API reference 8 | 9 | This section provides technical descriptions and important information about the different rocDecode 10 | APIs and library components. 11 | 12 | * {doc}`Library <../doxygen/html/files>` 13 | * {doc}`Functions <../doxygen/html/globals>` 14 | * {doc}`Data structures <../doxygen/html/annotated>` 15 | -------------------------------------------------------------------------------- /docs/reference/rocDecode-formats-and-architectures.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: rocDecode supported codex and hardware capabilities 3 | :keywords: install, rocDecode, AMD, ROCm, GPU, codec, VCN 4 | 5 | ******************************************************************** 6 | rocDecode supported codecs and hardware capabilities 7 | ******************************************************************** 8 | 9 | rocDecode supports the following codecs: 10 | 11 | * H.265 (HEVC): 8 bit and 10 bit 12 | * H.264 (AVC): 8 bit 13 | * AV1: 8 bit and 10 bit 14 | * VP9: 8 bit and 10 bit 15 | 16 | The following table shows the codec support and capabilities of the VCN for each supported GPU 17 | architecture: 18 | 19 | .. csv-table:: 20 | :header: "GPU Architecture", "VCN Generation", "Number of VCNs", "H.265/HEVC", "Max width, Max height - H.265", "H.264/AVC", "Max width, Max height - H.264", "AV1", "Max width, Max height - AV1", "VP9", "Max width, Max height - VP9" 21 | 22 | "gfx908 - MI1xx", "VCN 2.5.0", "2", "Yes", "7680, 4320", "Yes", "4096, 2160", "No", "N/A, N/A", "Yes", "7680, 4320" 23 | "gfx90a - MI2xx", "VCN 2.6.0", "2", "Yes", "7680, 4320", "Yes", "4096, 2160", "No", "N/A, N/A", "Yes", "7680, 4320" 24 | "gfx942 - MI3xx", "VCN 4.0", "3/4", "Yes", "7680, 4320", "Yes", "4096, 2176", "Yes", "8192, 4352", "Yes", "7680, 4320" 25 | "gfx1030, gfx1031, gfx1032 - Navi2x", "VCN 3.x", "2", "Yes", "7680, 4320", "Yes", "4096, 2176", "Yes", "8192, 4352", "Yes", "7680, 4320" 26 | "gfx1100, gfx1102 - Navi3x", "VCN 4.0", "2", "Yes", "7680, 4320", "Yes", "4096, 2176", "Yes", "8192, 4352", "Yes", "7680, 4320" 27 | "gfx1101 - Navi3x", "VCN 4.0", "1", "Yes", "7680, 4320", "Yes", "4096, 2176", "Yes", "8192, 4352", "Yes", "7680, 4320" -------------------------------------------------------------------------------- /docs/reference/rocDecode-tested-configurations.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: rocDecode tested configurations 3 | :keywords: install, rocDecode, AMD, ROCm, tested configurations, prerequisites, dependencies, requirements 4 | 5 | ******************************************************************** 6 | rocDecode tested configurations 7 | ******************************************************************** 8 | 9 | rocDecode has been tested on the following operating system, software, and library versions: 10 | 11 | * Linux: 12 | 13 | * Ubuntu 20.04, 22.04 14 | * RHEL 8, 9 15 | * SLES 15-SP5 16 | 17 | * ROCm: 18 | 19 | * rocm-core 6.2.0.60200-66 20 | * amdgpu-core 1:6.2.60200-2009582 21 | 22 | * libva-dev 2.7.0-2, 2.14.0-1 23 | * mesa-amdgpu-va-drivers 1:24.2.0.60200-2009582 24 | * FFmpeg 4.2.7, 4.4.2-0 -------------------------------------------------------------------------------- /docs/sphinx/.gitignore: -------------------------------------------------------------------------------- 1 | _toc.yml 2 | -------------------------------------------------------------------------------- /docs/sphinx/_toc.yml.in: -------------------------------------------------------------------------------- 1 | defaults: 2 | numbered: False 3 | root: index 4 | subtrees: 5 | - entries: 6 | - file: what-is-rocDecode.rst 7 | title: What is rocDecode? 8 | 9 | - caption: Install 10 | entries: 11 | - file: install/rocDecode-prerequisites.rst 12 | title: rocDecode prerequisites 13 | - file: install/rocDecode-package-install.rst 14 | title: Installing rocDecode with the package installer 15 | - file: install/rocDecode-build-and-install.rst 16 | title: Installing rocDecode from its source code 17 | - url: https://github.com/ROCm/rocDecode/tree/develop/docker 18 | title: rocDecode Docker containers 19 | 20 | - caption: Conceptual 21 | entries: 22 | - file: conceptual/video-decoding-pipeline.rst 23 | title: Video decoding pipeline 24 | - file: conceptual/rocDecode-memory-types.rst 25 | title: rocDecode surface memory locations 26 | 27 | - caption: Samples 28 | entries: 29 | - file: tutorials/rocDecode-samples.rst 30 | title: rocDecode samples 31 | 32 | - caption: How to 33 | entries: 34 | - file: how-to/using-rocDecode-videodecode-sample.rst 35 | title: Understand the rocDecode videodecode sample 36 | - file: how-to/using-rocDecode-video-decoder.rst 37 | title: Use the rocDecode RocVideoDecoder 38 | - file: how-to/using-rocDecode-ffmpeg.rst 39 | title: Use the rocDecode FFmpeg demultiplexer 40 | - file: how-to/using-rocDecode-bitstream.rst 41 | title: Use the rocDecode bitstream reader APIs 42 | - file: how-to/using-rocdecode.rst 43 | title: Use the rocDecode core APIs 44 | 45 | - caption: Reference 46 | entries: 47 | - file: reference/rocDecode-formats-and-architectures.rst 48 | title: rocDecode supported codecs and architectures 49 | - file: reference/rocDecode-tested-configurations.rst 50 | title: rocDecode tested configurations 51 | - file: doxygen/html/files 52 | title: rocDecode API library 53 | - file: doxygen/html/globals 54 | title: rocDecode functions 55 | - file: doxygen/html/annotated 56 | title: rocDecode data structures 57 | 58 | - caption: About 59 | entries: 60 | - file: license.md 61 | -------------------------------------------------------------------------------- /docs/sphinx/requirements.in: -------------------------------------------------------------------------------- 1 | rocm-docs-core[api_reference]==1.17.0 2 | -------------------------------------------------------------------------------- /docs/tutorials/README.md: -------------------------------------------------------------------------------- 1 | Placeholder to ensure docs/tutorials folder is created. Can remove once tutorial content is provided. 2 | -------------------------------------------------------------------------------- /docs/tutorials/rocDecode-samples.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: rocDecode Sample Prerequisites 3 | :keywords: install, rocDecode, AMD, ROCm, samples, prerequisites, dependencies, requirements 4 | 5 | ******************************************************************** 6 | rocDecode samples 7 | ******************************************************************** 8 | 9 | rocDecode samples are available in the `rocDecode GitHub repository `_. 10 | 11 | You can find a walkthrough of the ``videodecode.cpp`` sample at :doc:`Understanding the videodecode.cpp sample <../how-to/using-rocDecode-videodecode-sample>`. 12 | 13 | All three rocDecode packages, ``rocDecode``, ``rocdecode-dev``, and ``rocdecode-test``, must be installed to use the rocDecode samples. 14 | 15 | If you're using a :doc:`package installer <./install/rocDecode-package-install>`, install ``rocdecode``, ``rocdecode-dev``, and ``rocdecode-test``. 16 | 17 | If you're building and installing rocDecode from its :doc:`source code <../install/rocDecode-build-and-install>`, ``rocDecode-setup.py`` needs to be run with ``--developer`` set to ``ON``: 18 | 19 | .. code:: cpp 20 | 21 | python3 rocDecode-setup.py --developer ON 22 | 23 | The ``rocDecode-test`` package needs to be built and installed as well: 24 | 25 | .. code:: shell 26 | 27 | mkdir rocdecode-test && cd rocdecode-test 28 | cmake /opt/rocm/share/rocdecode/test/ 29 | ctest -VV 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/what-is-rocDecode.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: What is rocDecode? 3 | :keywords: video decoding, rocDecode, AMD, ROCm 4 | 5 | ******************************************************************** 6 | What is rocDecode? 7 | ******************************************************************** 8 | 9 | AMD GPUs contain one or more media engines (VCNs) that provide fully accelerated, hardware-based 10 | video decoding. Hardware decoders consume lower power than CPU-based decoders. Dedicated 11 | hardware decoders offload decoding tasks from the CPU, boosting overall decoding throughput. With 12 | proper power management, decoding on hardware decoders can lower the overall system power 13 | consumption and improve decoding performance. 14 | 15 | Using the rocDecode API, you can decode compressed video streams while keeping the resulting YUV 16 | frames in video memory. With decoded frames in video memory, you can run video post-processing 17 | using ROCm HIP, thereby avoiding unnecessary data copies via the PCIe bus. You can post-process video 18 | frames using scaling or color conversion and augmentation kernels (on a GPU or host) in a format for 19 | GPU/CPU-accelerated inferencing and training. 20 | 21 | In addition, you can use the rocDecode API to create multiple instances of video decoders based on the number of available VCNs on a GPU device. By configuring the decoder for a device, all available VCNs can be used seamlessly to decode a batch of video streams in parallel. 22 | 23 | For more information, refer to the 24 | :doc:`Video decoding pipeline <./conceptual/video-decoding-pipeline>`. 25 | -------------------------------------------------------------------------------- /samples/README.md: -------------------------------------------------------------------------------- 1 | # Samples overview 2 | 3 | rocDecode samples 4 | 5 | ## [Video decode](videoDecode) 6 | 7 | The video decode sample illustrates decoding a single packetized video stream using FFMPEG demuxer, video parser, and rocDecoder to get the individual decoded frames in YUV format. This sample can be configured with a device ID and optionally able to dump the output to a file. This sample uses the high-level RocVideoDecoder class which connects both the video parser and Rocdecoder. This process repeats in a loop until all frames have been decoded. 8 | 9 | ## [Video decode batch sample](videoDecodeBatch) 10 | 11 | This sample decodes multiple files using multiple threads, using the rocDecode library. The input is a directory of files and an input number of threads. The maximum number of threads is capped to 64. 12 | If the number of files is higher than the number of threads requested by the user, the files are distributed to the threads in a round robin fashion. 13 | If the number of files is lesser than the number of threads requested by the user, the number of threads created will be equal to the number of files. 14 | 15 | ## [Video decode memory](videoDecodeMem) 16 | 17 | The video decode memory sample illustrates a way to pass the data chunk-by-chunk sequentially to the FFMPEG demuxer which is then decoded on AMD hardware using rocDecode library. 18 | 19 | The sample provides a user class `FileStreamProvider` derived from the existing `VideoDemuxer::StreamProvider` to read a video file and fill the buffer owned by the demuxer. It then takes frames from this buffer for further parsing and decoding. 20 | 21 | ## [Video decode multi files](videoDecodeMultiFiles) 22 | 23 | The video decodes multiple files sample illustrates the use of providing a list of files as input to showcase the reconfigure option in the rocDecode library. The input video files have to be of the same codec type to use the reconfigure option but can have different resolutions or resize parameters. 24 | 25 | The reconfigure option can be disabled by the user if needed. The input file is parsed line by line and data is stored in a queue. The individual video files are demuxed and decoded one after the other in a loop. Output for each input file can also be stored if needed. 26 | 27 | ## [Video decode performance](videoDecodePerf) 28 | 29 | This sample illustrates the FFMPEG demuxer to get the individual frames which are then decoded on AMD hardware using rocDecode library. 30 | 31 | This sample uses multiple threads to decode the same input video parallelly. 32 | 33 | ## [Video decode RGB](videoDecodeRGB) 34 | 35 | This sample illustrates the FFMPEG demuxer to get the individual frames which are then decoded using rocDecode API and optionally color-converted using custom HIP kernels on AMD hardware. This sample converts decoded YUV output to one of the RGB or BGR formats(24bit, 32bit, 464bit) in a separate thread allowing it to run both VCN hardware and compute engine in parallel. 36 | 37 | This sample uses HIP kernels to showcase the color conversion. Whenever a frame is ready after decoding, the `ColorSpaceConversionThread` is notified and can be used for post-processing. -------------------------------------------------------------------------------- /samples/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "roc_video_dec.h" 26 | #include "md5.h" 27 | 28 | typedef enum ReconfigFlushMode_enum { 29 | RECONFIG_FLUSH_MODE_NONE = 0, /**< Just flush to get the frame count */ 30 | RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 1, /**< The remaining frames will be dumped to file in this mode */ 31 | RECONFIG_FLUSH_MODE_CALCULATE_MD5 = 2, /**< Calculate the MD5 of the flushed frames */ 32 | } ReconfigFlushMode; 33 | 34 | // this struct is used by videodecode and videodecodeMultiFiles to dump last frames to file 35 | typedef struct ReconfigDumpFileStruct_t { 36 | bool b_dump_frames_to_file; 37 | std::string output_file_name; 38 | void *md5_generator_handle; 39 | } ReconfigDumpFileStruct; 40 | 41 | 42 | // callback function to flush last frames and save it to file when reconfigure happens 43 | int ReconfigureFlushCallback(void *p_viddec_obj, uint32_t flush_mode, void *p_user_struct) { 44 | int n_frames_flushed = 0; 45 | if ((p_viddec_obj == nullptr) || (p_user_struct == nullptr)) return n_frames_flushed; 46 | 47 | RocVideoDecoder *viddec = static_cast (p_viddec_obj); 48 | OutputSurfaceInfo *surf_info; 49 | if (!viddec->GetOutputSurfaceInfo(&surf_info)) { 50 | std::cerr << "Error: Failed to get Output Surface Info!" << std::endl; 51 | return n_frames_flushed; 52 | } 53 | 54 | uint8_t *pframe = nullptr; 55 | int64_t pts; 56 | while ((pframe = viddec->GetFrame(&pts))) { 57 | if (flush_mode != RECONFIG_FLUSH_MODE_NONE) { 58 | ReconfigDumpFileStruct *p_dump_file_struct = static_cast(p_user_struct); 59 | if (flush_mode == ReconfigFlushMode::RECONFIG_FLUSH_MODE_DUMP_TO_FILE) { 60 | if (p_dump_file_struct->b_dump_frames_to_file) { 61 | viddec->SaveFrameToFile(p_dump_file_struct->output_file_name, pframe, surf_info); 62 | } 63 | } else if (flush_mode == ReconfigFlushMode::RECONFIG_FLUSH_MODE_CALCULATE_MD5) { 64 | MD5Generator *md5_generator = static_cast(p_dump_file_struct->md5_generator_handle); 65 | md5_generator->UpdateMd5ForFrame(pframe, surf_info); 66 | } 67 | } 68 | // release and flush frame 69 | viddec->ReleaseFrame(pts, true); 70 | n_frames_flushed++; 71 | } 72 | 73 | return n_frames_flushed; 74 | } 75 | 76 | int GetEnvVar(const char *name, int &dev_count) { 77 | char *v = std::getenv(name); 78 | if (v) { 79 | char* p_tkn = std::strtok(v, ","); 80 | while (p_tkn != nullptr) { 81 | dev_count++; 82 | p_tkn = strtok(nullptr, ","); 83 | } 84 | } 85 | return dev_count; 86 | } -------------------------------------------------------------------------------- /samples/videoDecode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | # ROCM Path 26 | if(DEFINED ENV{ROCM_PATH}) 27 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 28 | elseif(ROCM_PATH) 29 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 30 | else() 31 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 32 | endif() 33 | # Set AMD Clang as default compiler 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_CXX_STANDARD_REQUIRED On) 36 | set(CMAKE_CXX_EXTENSIONS ON) 37 | if (NOT DEFINED CMAKE_CXX_COMPILER) 38 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 39 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 40 | endif() 41 | 42 | project(videodecode) 43 | 44 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 45 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 46 | 47 | # rocDecode sample build type 48 | set(DEFAULT_BUILD_TYPE "Release") 49 | if(NOT CMAKE_BUILD_TYPE) 50 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 51 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 52 | endif() 53 | if(CMAKE_BUILD_TYPE MATCHES Debug) 54 | # -O0 -- Don't Optimize output file 55 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 57 | else() 58 | # -O3 -- Optimize output file 59 | # -DNDEBUG -- turn off asserts 60 | # -fPIC -- Generate position-independent code if possible 61 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 62 | endif() 63 | 64 | find_package(HIP QUIET) 65 | find_package(ROCDECODE QUIET) 66 | find_package(rocprofiler-register QUIET) 67 | find_package(FFmpeg QUIET) 68 | find_package(Threads REQUIRED) 69 | 70 | if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND AND Threads_FOUND AND rocprofiler-register_FOUND) 71 | # HIP 72 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 73 | # FFMPEG 74 | include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} 75 | ${AVFORMAT_INCLUDE_DIR}) 76 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) 77 | # rocDecode and utils 78 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/ffmpegvideodecode) 79 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 80 | # threads 81 | set(THREADS_PREFER_PTHREAD_FLAG ON) 82 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} Threads::Threads) 83 | # rocprofiler-register 84 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 85 | # sample app exe 86 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/ffmpegvideodecode/ffmpeg_video_dec.cpp) 87 | add_executable(${PROJECT_NAME} ${SOURCES}) 88 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 89 | # FFMPEG multi-version support 90 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) 91 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) 92 | else() 93 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) 94 | endif() 95 | else() 96 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 97 | if (NOT HIP_FOUND) 98 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 99 | endif() 100 | if (NOT FFMPEG_FOUND) 101 | message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!") 102 | endif() 103 | if (NOT ROCDECODE_FOUND) 104 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 105 | endif() 106 | if (NOT Threads_FOUND) 107 | message(FATAL_ERROR "-- ERROR!: Threads Not Found! - please insatll Threads!") 108 | endif() 109 | if (NOT rocprofiler-register_FOUND) 110 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 111 | endif() 112 | endif() 113 | -------------------------------------------------------------------------------- /samples/videoDecode/README.md: -------------------------------------------------------------------------------- 1 | # Video decode sample 2 | 3 | The video decode sample illustrates decoding a single packetized video stream using FFMPEG demuxer, video parser, and rocDecoder to get the individual decoded frames in YUV format. This sample can be configured with a device ID and optionally able to dump the output to a file. This sample uses the high-level RocVideoDecoder class which connects both the video parser and Rocdecoder. This process repeats in a loop until all frames have been decoded. 4 | 5 | ## Prerequisites: 6 | 7 | * Install [rocDecode](../../README.md#build-and-install-instructions) 8 | 9 | * [FFMPEG](https://ffmpeg.org/about.html) 10 | 11 | * On `Ubuntu` 12 | 13 | ```shell 14 | sudo apt install libavcodec-dev libavformat-dev libavutil-dev 15 | ``` 16 | 17 | * On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script 18 | 19 | ## Build 20 | 21 | ```shell 22 | mkdir video_decode_sample && cd video_decode_sample 23 | cmake ../ 24 | make -j 25 | ``` 26 | 27 | ## Run 28 | 29 | ```shell 30 | ./videodecode -i 31 | -o 32 | -d 33 | -f 34 | -z 35 | -disp_delay 36 | -sei 37 | -md5 38 | -md5_check MD5_File_Path 39 | -crop 40 | -m 41 | -no_ffmpeg_demux 42 | ``` -------------------------------------------------------------------------------- /samples/videoDecodeBatch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | # ROCM Path 26 | if(DEFINED ENV{ROCM_PATH}) 27 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 28 | elseif(ROCM_PATH) 29 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 30 | else() 31 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 32 | endif() 33 | # Set AMD Clang as default compiler 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_CXX_STANDARD_REQUIRED On) 36 | set(CMAKE_CXX_EXTENSIONS ON) 37 | if (NOT DEFINED CMAKE_CXX_COMPILER) 38 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 39 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 40 | endif() 41 | 42 | project(videodecodebatch) 43 | 44 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 45 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 46 | 47 | # rocDecode sample build type 48 | set(DEFAULT_BUILD_TYPE "Release") 49 | if(NOT CMAKE_BUILD_TYPE) 50 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 51 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 52 | endif() 53 | if(CMAKE_BUILD_TYPE MATCHES Debug) 54 | # -O0 -- Don't Optimize output file 55 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 57 | else() 58 | # -O3 -- Optimize output file 59 | # -DNDEBUG -- turn off asserts 60 | # -fPIC -- Generate position-independent code if possible 61 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 62 | endif() 63 | 64 | find_package(HIP QUIET) 65 | find_package(ROCDECODE QUIET) 66 | find_package(rocprofiler-register QUIET) 67 | find_package(FFmpeg QUIET) 68 | 69 | if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND AND rocprofiler-register_FOUND) 70 | # HIP 71 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 72 | # FFMPEG 73 | include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} 74 | ${SWSCALE_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR}) 75 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) 76 | # STD Filesystem 77 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} stdc++fs) 78 | # rocDecode and utils 79 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode) 80 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 81 | #threads 82 | set(THREADS_PREFER_PTHREAD_FLAG ON) 83 | find_package(Threads REQUIRED) 84 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} Threads::Threads) 85 | # rocprofiler-register 86 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 87 | 88 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecodebatch.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp) 89 | add_executable(${PROJECT_NAME} ${SOURCES}) 90 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 91 | # FFMPEG multi-version support 92 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) 93 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) 94 | else() 95 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) 96 | endif() 97 | else() 98 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 99 | if (NOT HIP_FOUND) 100 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 101 | endif() 102 | if (NOT FFMPEG_FOUND) 103 | message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!") 104 | endif() 105 | if (NOT ROCDECODE_FOUND) 106 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 107 | endif() 108 | if (NOT Threads_FOUND) 109 | message(FATAL_ERROR "-- ERROR!: Threads Not Found! - please insatll Threads!") 110 | endif() 111 | if (NOT rocprofiler-register_FOUND) 112 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 113 | endif() 114 | endif() -------------------------------------------------------------------------------- /samples/videoDecodeBatch/README.md: -------------------------------------------------------------------------------- 1 | # Video decode batch sample 2 | 3 | This sample decodes multiple files using multiple threads, using the rocDecode library. The input is a directory of files and an input number of threads. The maximum number of threads is capped to 64. 4 | If the number of files is higher than the number of threads requested by the user, the files are distributed to the threads in a round robin fashion. 5 | If the number of files is lesser than the number of threads requested by the user, the number of threads created will be equal to the number of files. 6 | 7 | ## Prerequisites: 8 | 9 | * Install [rocDecode](../../README.md#build-and-install-instructions) 10 | 11 | * [FFMPEG](https://ffmpeg.org/about.html) 12 | 13 | * On `Ubuntu` 14 | 15 | ```shell 16 | sudo apt install libavcodec-dev libavformat-dev libavutil-dev 17 | ``` 18 | 19 | * On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script 20 | 21 | ## Build 22 | 23 | ```shell 24 | mkdir video_decode_batch && cd video_decode_batch 25 | cmake ../ 26 | make -j 27 | ``` 28 | 29 | ## Run 30 | 31 | ```shell 32 | ./videodecodebatch -i 33 | -t 34 | -d = 0) [optional - default:0]> 35 | -o Directory for output YUV files - optional 36 | -m output_surface_memory_type - decoded surface memory; optional; default - 3 [0 : OUT_SURFACE_MEM_DEV_INTERNAL/ 1 : OUT_SURFACE_MEM_DEV_COPIED/ 2 : OUT_SURFACE_MEM_HOST_COPIED/ 3 : OUT_SURFACE_MEM_NOT_MAPPED] 37 | -disp_delay -specify the number of frames to be delayed for display; optional; default: 1 38 | ``` -------------------------------------------------------------------------------- /samples/videoDecodeMem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | 26 | # ROCM Path 27 | if(DEFINED ENV{ROCM_PATH}) 28 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 29 | elseif(ROCM_PATH) 30 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 31 | else() 32 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 33 | endif() 34 | # Set AMD Clang as default compiler 35 | set(CMAKE_CXX_STANDARD 17) 36 | set(CMAKE_CXX_STANDARD_REQUIRED On) 37 | set(CMAKE_CXX_EXTENSIONS ON) 38 | if (NOT DEFINED CMAKE_CXX_COMPILER) 39 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 40 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 41 | endif() 42 | 43 | project(videodecodemem) 44 | 45 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 46 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 47 | 48 | # rocDecode sample build type 49 | set(DEFAULT_BUILD_TYPE "Release") 50 | if(NOT CMAKE_BUILD_TYPE) 51 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 52 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 53 | endif() 54 | if(CMAKE_BUILD_TYPE MATCHES Debug) 55 | # -O0 -- Don't Optimize output file 56 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 57 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 58 | else() 59 | # -O3 -- Optimize output file 60 | # -DNDEBUG -- turn off asserts 61 | # -fPIC -- Generate position-independent code if possible 62 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 63 | endif() 64 | 65 | find_package(HIP QUIET) 66 | find_package(ROCDECODE QUIET) 67 | find_package(rocprofiler-register QUIET) 68 | find_package(FFmpeg QUIET) 69 | 70 | if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND AND rocprofiler-register_FOUND) 71 | # HIP 72 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 73 | # FFMPEG 74 | include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} 75 | ${AVFORMAT_INCLUDE_DIR}) 76 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) 77 | # rocDecode and utils 78 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode) 79 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 80 | # rocprofiler-register 81 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 82 | # sample app exe 83 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecodemem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp) 84 | add_executable(${PROJECT_NAME} ${SOURCES}) 85 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 86 | # FFMPEG multi-version support 87 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) 88 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) 89 | else() 90 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) 91 | endif() 92 | else() 93 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 94 | if (NOT HIP_FOUND) 95 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 96 | endif() 97 | if (NOT FFMPEG_FOUND) 98 | message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!") 99 | endif() 100 | if (NOT ROCDECODE_FOUND) 101 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 102 | endif() 103 | if (NOT rocprofiler-register_FOUND) 104 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 105 | endif() 106 | endif() -------------------------------------------------------------------------------- /samples/videoDecodeMem/README.md: -------------------------------------------------------------------------------- 1 | # Video decode memory sample 2 | 3 | The video decode memory sample illustrates a way to pass the data chunk-by-chunk sequentially to the FFMPEG demuxer which is then decoded on AMD hardware using rocDecode library. 4 | 5 | The sample provides a user class `FileStreamProvider` derived from the existing `VideoDemuxer::StreamProvider` to read a video file and fill the buffer owned by the demuxer. It then takes frames from this buffer for further parsing and decoding. 6 | 7 | ## Prerequisites: 8 | 9 | * Install [rocDecode](../../README.md#build-and-install-instructions) 10 | 11 | * [FFMPEG](https://ffmpeg.org/about.html) 12 | 13 | * On `Ubuntu` 14 | 15 | ```shell 16 | sudo apt install libavcodec-dev libavformat-dev libavutil-dev 17 | ``` 18 | 19 | * On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script 20 | 21 | ## Build 22 | 23 | ```shell 24 | mkdir video_decode_mem_sample && cd video_decode_mem_sample 25 | cmake ../ 26 | make -j 27 | ``` 28 | 29 | ## Run 30 | 31 | ```shell 32 | ./videodecodemem -i 33 | -o 34 | -d 35 | -z 36 | -sei 37 | -crop 38 | -m 39 | ``` -------------------------------------------------------------------------------- /samples/videoDecodeMultiFiles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | # ROCM Path 26 | if(DEFINED ENV{ROCM_PATH}) 27 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 28 | elseif(ROCM_PATH) 29 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 30 | else() 31 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 32 | endif() 33 | # Set AMD Clang as default compiler 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_CXX_STANDARD_REQUIRED On) 36 | set(CMAKE_CXX_EXTENSIONS ON) 37 | if (NOT DEFINED CMAKE_CXX_COMPILER) 38 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 39 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 40 | endif() 41 | 42 | project(videodecodemultifiles) 43 | 44 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 45 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 46 | 47 | # rocDecode sample build type 48 | set(DEFAULT_BUILD_TYPE "Release") 49 | if(NOT CMAKE_BUILD_TYPE) 50 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 51 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 52 | endif() 53 | if(CMAKE_BUILD_TYPE MATCHES Debug) 54 | # -O0 -- Don't Optimize output file 55 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 57 | else() 58 | # -O3 -- Optimize output file 59 | # -DNDEBUG -- turn off asserts 60 | # -fPIC -- Generate position-independent code if possible 61 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 62 | endif() 63 | 64 | find_package(HIP QUIET) 65 | find_package(ROCDECODE QUIET) 66 | find_package(rocprofiler-register QUIET) 67 | find_package(FFmpeg QUIET) 68 | 69 | if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND AND rocprofiler-register_FOUND) 70 | # HIP 71 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 72 | # FFMPEG 73 | include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} 74 | ${AVFORMAT_INCLUDE_DIR}) 75 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) 76 | # rocDecode and utils 77 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode) 78 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 79 | # rocprofiler-register 80 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 81 | # sample app exe 82 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecodemultifiles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp) 83 | add_executable(${PROJECT_NAME} ${SOURCES}) 84 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 85 | # FFMPEG multi-version support 86 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) 87 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) 88 | else() 89 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) 90 | endif() 91 | else() 92 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 93 | if (NOT HIP_FOUND) 94 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 95 | endif() 96 | if (NOT FFMPEG_FOUND) 97 | message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!") 98 | endif() 99 | if (NOT ROCDECODE_FOUND) 100 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 101 | endif() 102 | if (NOT rocprofiler-register_FOUND) 103 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 104 | endif() 105 | endif() -------------------------------------------------------------------------------- /samples/videoDecodeMultiFiles/README.md: -------------------------------------------------------------------------------- 1 | # Video decode multi files sample 2 | 3 | The video decodes multiple files sample illustrates the use of providing a list of files as input to showcase the reconfigure option in the rocDecode library. The input video files have to be of the same codec type to use the reconfigure option but can have different resolutions or resize parameters. 4 | 5 | The reconfigure option can be disabled by the user if needed. The input file is parsed line by line and data is stored in a queue. The individual video files are demuxed and decoded one after the other in a loop. Output for each input file can also be stored if needed. 6 | 7 | ## Prerequisites: 8 | 9 | * Install [rocDecode](../../README.md#build-and-install-instructions) 10 | 11 | * [FFMPEG](https://ffmpeg.org/about.html) 12 | 13 | * On `Ubuntu` 14 | 15 | ```shell 16 | sudo apt install libavcodec-dev libavformat-dev libavutil-dev 17 | ``` 18 | 19 | * On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script 20 | 21 | ## Build 22 | 23 | ```shell 24 | mkdir video_decode_multi_files_sample && cd video_decode_multi_files_sample 25 | cmake ../ 26 | make -j 27 | ``` 28 | 29 | ## Run 30 | 31 | ```shell 32 | ./videodecodemultifiles -i 33 | -d 34 | -use_reconfigure 35 | ``` 36 | ### Note: Example input file list - example.txt 37 | 38 | ```shell 39 | infile input1.[mp4/mov...] [required] 40 | outfile output1.yuv [optional] 41 | z 0 [optional] 42 | sei 0 [optional] 43 | crop l,t,r,b [optional] 44 | m 0 [optional] [0 : OUT_SURFACE_MEM_DEV_INTERNAL/ 1 : OUT_SURFACE_MEM_DEV_COPIED/ 2 : OUT_SURFACE_MEM_HOST_COPIED/ 3 : OUT_SURFACE_MEM_NOT_MAPPED] 45 | infile input2.[mp4/mov...] [optional] 46 | outfile output2.yuv [optional] 47 | ... 48 | ... 49 | ``` -------------------------------------------------------------------------------- /samples/videoDecodePerf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | # ROCM Path 26 | if(DEFINED ENV{ROCM_PATH}) 27 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 28 | elseif(ROCM_PATH) 29 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 30 | else() 31 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 32 | endif() 33 | # Set AMD Clang as default compiler 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_CXX_STANDARD_REQUIRED On) 36 | set(CMAKE_CXX_EXTENSIONS ON) 37 | if (NOT DEFINED CMAKE_CXX_COMPILER) 38 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 39 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 40 | endif() 41 | 42 | project(videodecodeperf) 43 | 44 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 45 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 46 | 47 | # rocDecode sample build type 48 | set(DEFAULT_BUILD_TYPE "Release") 49 | if(NOT CMAKE_BUILD_TYPE) 50 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 51 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 52 | endif() 53 | if(CMAKE_BUILD_TYPE MATCHES Debug) 54 | # -O0 -- Don't Optimize output file 55 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 57 | else() 58 | # -O3 -- Optimize output file 59 | # -DNDEBUG -- turn off asserts 60 | # -fPIC -- Generate position-independent code if possible 61 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 62 | endif() 63 | 64 | find_package(HIP QUIET) 65 | find_package(ROCDECODE QUIET) 66 | find_package(rocprofiler-register QUIET) 67 | find_package(FFmpeg QUIET) 68 | 69 | if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND AND Threads_FOUND AND rocprofiler-register_FOUND) 70 | # HIP 71 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 72 | # FFMPEG 73 | include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} 74 | ${SWSCALE_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR}) 75 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) 76 | # rocDecode and utils 77 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode ${CMAKE_CURRENT_SOURCE_DIR}/..) 78 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 79 | # threads 80 | set(THREADS_PREFER_PTHREAD_FLAG ON) 81 | find_package(Threads REQUIRED) 82 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} Threads::Threads) 83 | # rocprofiler-register 84 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 85 | # sample app exe 86 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecodeperf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp) 87 | add_executable(${PROJECT_NAME} ${SOURCES}) 88 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 89 | # FFMPEG multi-version support 90 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) 91 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) 92 | else() 93 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) 94 | endif() 95 | else() 96 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 97 | if (NOT HIP_FOUND) 98 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 99 | endif() 100 | if (NOT FFMPEG_FOUND) 101 | message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!") 102 | endif() 103 | if (NOT ROCDECODE_FOUND) 104 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 105 | endif() 106 | if (NOT Threads_FOUND) 107 | message(FATAL_ERROR "-- ERROR!: Threads Not Found! - please insatll Threads!") 108 | endif() 109 | if (NOT rocprofiler-register_FOUND) 110 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 111 | endif() 112 | endif() -------------------------------------------------------------------------------- /samples/videoDecodePerf/README.md: -------------------------------------------------------------------------------- 1 | # Video decode performance sample 2 | 3 | This sample illustrates the FFMPEG demuxer to get the individual frames which are then decoded on AMD hardware using rocDecode library. 4 | 5 | This sample uses multiple threads to decode the same input video parallelly. 6 | 7 | ## Prerequisites: 8 | 9 | * Install [rocDecode](../../README.md#build-and-install-instructions) 10 | 11 | * [FFMPEG](https://ffmpeg.org/about.html) 12 | 13 | * On `Ubuntu` 14 | 15 | ```shell 16 | sudo apt install libavcodec-dev libavformat-dev libavutil-dev 17 | ``` 18 | 19 | * On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script 20 | 21 | ## Build 22 | 23 | ```shell 24 | mkdir video_decode_perf_sample && cd video_decode_perf_sample 25 | cmake ../ 26 | make -j 27 | ``` 28 | 29 | ## Run 30 | 31 | ```shell 32 | ./videodecodeperf -i 33 | -t 34 | -f 35 | -disp_delay 36 | -d = 0) [optional - default:0]> 37 | -z 38 | -m 43 | ``` -------------------------------------------------------------------------------- /samples/videoDecodePicFiles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | # ROCM Path 26 | if(DEFINED ENV{ROCM_PATH}) 27 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 28 | elseif(ROCM_PATH) 29 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 30 | else() 31 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 32 | endif() 33 | # Set AMD Clang as default compiler 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_CXX_STANDARD_REQUIRED On) 36 | set(CMAKE_CXX_EXTENSIONS ON) 37 | if (NOT DEFINED CMAKE_CXX_COMPILER) 38 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 39 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 40 | endif() 41 | 42 | project(videodecodepicfiles) 43 | 44 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 45 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 46 | 47 | # rocDecode sample build type 48 | set(DEFAULT_BUILD_TYPE "Release") 49 | if(NOT CMAKE_BUILD_TYPE) 50 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 51 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 52 | endif() 53 | if(CMAKE_BUILD_TYPE MATCHES Debug) 54 | # -O0 -- Don't Optimize output file 55 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 57 | else() 58 | # -O3 -- Optimize output file 59 | # -DNDEBUG -- turn off asserts 60 | # -fPIC -- Generate position-independent code if possible 61 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 62 | endif() 63 | 64 | find_package(HIP QUIET) 65 | find_package(ROCDECODE QUIET) 66 | find_package(rocprofiler-register QUIET) 67 | find_package(FFmpeg QUIET) 68 | find_package(Threads REQUIRED) 69 | 70 | if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND AND Threads_FOUND AND rocprofiler-register_FOUND) 71 | # HIP 72 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 73 | # FFMPEG 74 | include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} 75 | ${AVFORMAT_INCLUDE_DIR}) 76 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) 77 | # rocDecode and utils 78 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/ffmpegvideodecode) 79 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 80 | # threads 81 | set(THREADS_PREFER_PTHREAD_FLAG ON) 82 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} Threads::Threads) 83 | # rocprofiler-register 84 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 85 | # sample app exe 86 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecodepicfiles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/ffmpegvideodecode/ffmpeg_video_dec.cpp) 87 | add_executable(${PROJECT_NAME} ${SOURCES}) 88 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 89 | # FFMPEG multi-version support 90 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) 91 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) 92 | else() 93 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) 94 | endif() 95 | else() 96 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 97 | if (NOT HIP_FOUND) 98 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 99 | endif() 100 | if (NOT FFMPEG_FOUND) 101 | message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!") 102 | endif() 103 | if (NOT ROCDECODE_FOUND) 104 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 105 | endif() 106 | if (NOT Threads_FOUND) 107 | message(FATAL_ERROR "-- ERROR!: Threads Not Found! - please insatll Threads!") 108 | endif() 109 | if (NOT rocprofiler-register_FOUND) 110 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 111 | endif() 112 | endif() 113 | -------------------------------------------------------------------------------- /samples/videoDecodePicFiles/README.md: -------------------------------------------------------------------------------- 1 | # Video decode picture files sample 2 | 3 | The video decode picture files sample illustrates decoding an elementary video stream which is stored in multiple files with each file containing bitstream data of a coded picutre. This sample can be configured with a device ID and optionally able to dump the output to a file. This sample uses the high-level RocVideoDecoder class which connects both the video parser and Rocdecoder. This process repeats in a loop until all frames have been decoded. 4 | 5 | ## Prerequisites: 6 | 7 | * Install [rocDecode](../../README.md#build-and-install-instructions) 8 | 9 | ## Build 10 | 11 | ```shell 12 | mkdir video_decode_pic_files && cd video_decode_pic_files 13 | cmake ../ 14 | make -j 15 | ``` 16 | 17 | ## Run 18 | 19 | ```shell 20 | ./videodecodepicfiles -i 21 | -codec 22 | -l 23 | -o 24 | -d 25 | -f 26 | -z 27 | -disp_delay 28 | -sei 29 | -md5 30 | -md5_check MD5_File_Path 31 | -crop 32 | -m 33 | ``` -------------------------------------------------------------------------------- /samples/videoDecodeRGB/README.md: -------------------------------------------------------------------------------- 1 | # Video decode RGB sample 2 | 3 | This sample illustrates the FFMPEG demuxer to get the individual frames which are then decoded using rocDecode API and optionally color-converted using custom HIP kernels on AMD hardware. This sample converts decoded YUV output to one of the RGB or BGR formats(24bit, 32bit, 464bit) in a separate thread allowing it to run both VCN hardware and compute engine in parallel. 4 | 5 | This sample uses HIP kernels to showcase the color conversion. Whenever a frame is ready after decoding, the `ColorSpaceConversionThread` is notified and can be used for post-processing. 6 | 7 | ## Prerequisites: 8 | 9 | * Install [rocDecode](../../README.md#build-and-install-instructions) 10 | 11 | * [FFMPEG](https://ffmpeg.org/about.html) 12 | 13 | * On `Ubuntu` 14 | 15 | ```shell 16 | sudo apt install libavcodec-dev libavformat-dev libavutil-dev 17 | ``` 18 | 19 | * On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script 20 | 21 | ## Build 22 | 23 | ```shell 24 | mkdir video_decode_rgb_sample && cd video_decode_rgb_sample 25 | cmake ../ 26 | make -j 27 | ``` 28 | 29 | ## Run 30 | 31 | ```shell 32 | ./videodecodergb -i 33 | -o 34 | -d 35 | -of 36 | ``` -------------------------------------------------------------------------------- /samples/videoDecodeRaw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | # ROCM Path 26 | if(DEFINED ENV{ROCM_PATH}) 27 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 28 | elseif(ROCM_PATH) 29 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 30 | else() 31 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 32 | endif() 33 | # Set AMD Clang as default compiler 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_CXX_STANDARD_REQUIRED On) 36 | set(CMAKE_CXX_EXTENSIONS ON) 37 | if (NOT DEFINED CMAKE_CXX_COMPILER) 38 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 39 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 40 | endif() 41 | 42 | project(videodecoderaw) 43 | 44 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 45 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 46 | 47 | # rocDecode sample build type 48 | set(DEFAULT_BUILD_TYPE "Release") 49 | if(NOT CMAKE_BUILD_TYPE) 50 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 51 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 52 | endif() 53 | if(CMAKE_BUILD_TYPE MATCHES Debug) 54 | # -O0 -- Don't Optimize output file 55 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 57 | else() 58 | # -O3 -- Optimize output file 59 | # -DNDEBUG -- turn off asserts 60 | # -fPIC -- Generate position-independent code if possible 61 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 62 | endif() 63 | 64 | find_package(HIP QUIET) 65 | find_package(ROCDECODE QUIET) 66 | find_package(rocprofiler-register QUIET) 67 | 68 | if(HIP_FOUND AND ROCDECODE_FOUND AND rocprofiler-register_FOUND) 69 | # HIP 70 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 71 | # rocDecode and utils 72 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode) 73 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 74 | # rocprofiler-register 75 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 76 | # sample app exe 77 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecoderaw.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp) 78 | add_executable(${PROJECT_NAME} ${SOURCES}) 79 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 80 | else() 81 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 82 | if (NOT HIP_FOUND) 83 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 84 | endif() 85 | if (NOT ROCDECODE_FOUND) 86 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 87 | endif() 88 | if (NOT rocprofiler-register_FOUND) 89 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 90 | endif() 91 | endif() 92 | -------------------------------------------------------------------------------- /samples/videoDecodeRaw/README.md: -------------------------------------------------------------------------------- 1 | # Video decode sample 2 | 3 | The video decode raw sample illustrates decoding a single packetized video stream using the built-in bitstream reader, video parser, and rocDecoder to get the individual decoded frames in YUV format. This sample can be configured with a device ID and optionally able to dump the output to a file. This sample uses the high-level RocVideoDecoder class which connects both the video parser and Rocdecoder. This process repeats in a loop until all frames have been decoded. 4 | 5 | ## Prerequisites: 6 | 7 | * Install [rocDecode](../../README.md#build-and-install-instructions) 8 | 9 | ## Build 10 | 11 | ```shell 12 | mkdir video_decode_raw_sample && cd video_decode_raw_sample 13 | cmake ../ 14 | make -j 15 | ``` 16 | 17 | ## Run 18 | 19 | ```shell 20 | ./videodecoderaw -i 21 | -o 22 | -d 23 | -f 24 | -z 25 | -disp_delay 26 | -sei 27 | -crop 28 | -m 29 | ``` -------------------------------------------------------------------------------- /samples/videoToSequence/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2024 - 2025 Advanced Micro Devices, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | ################################################################################ 23 | 24 | cmake_minimum_required(VERSION 3.10) 25 | # ROCM Path 26 | if(DEFINED ENV{ROCM_PATH}) 27 | set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path") 28 | elseif(ROCM_PATH) 29 | message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}") 30 | else() 31 | set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path") 32 | endif() 33 | # Set AMD Clang as default compiler 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_CXX_STANDARD_REQUIRED On) 36 | set(CMAKE_CXX_EXTENSIONS ON) 37 | if (NOT DEFINED CMAKE_CXX_COMPILER) 38 | set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang) 39 | set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++) 40 | endif() 41 | 42 | project(videotosequence) 43 | 44 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake) 45 | list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake) 46 | 47 | # rocDecode sample build type 48 | set(DEFAULT_BUILD_TYPE "Release") 49 | if(NOT CMAKE_BUILD_TYPE) 50 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "rocDecode Default Build Type" FORCE) 51 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") 52 | endif() 53 | if(CMAKE_BUILD_TYPE MATCHES Debug) 54 | # -O0 -- Don't Optimize output file 55 | # -gdwarf-4 -- generate debugging information, dwarf-4 for making valgrind work 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -gdwarf-4") 57 | else() 58 | # -O3 -- Optimize output file 59 | # -DNDEBUG -- turn off asserts 60 | # -fPIC -- Generate position-independent code if possible 61 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG -fPIC") 62 | endif() 63 | 64 | find_package(HIP QUIET) 65 | find_package(ROCDECODE QUIET) 66 | find_package(rocprofiler-register QUIET) 67 | find_package(FFmpeg QUIET) 68 | 69 | if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND AND rocprofiler-register_FOUND) 70 | # HIP 71 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host) 72 | # FFMPEG 73 | include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} 74 | ${AVFORMAT_INCLUDE_DIR}) 75 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES}) 76 | # rocDecode and utils 77 | include_directories (${ROCDECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../utils ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode) 78 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY}) 79 | # rocprofiler-register 80 | set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) 81 | # sample app exe 82 | list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videotosequence.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp) 83 | add_executable(${PROJECT_NAME} ${SOURCES}) 84 | target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) 85 | # FFMPEG multi-version support 86 | if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) 87 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) 88 | else() 89 | target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) 90 | endif() 91 | else() 92 | message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") 93 | if (NOT HIP_FOUND) 94 | message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!") 95 | endif() 96 | if (NOT FFMPEG_FOUND) 97 | message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!") 98 | endif() 99 | if (NOT ROCDECODE_FOUND) 100 | message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!") 101 | endif() 102 | if (NOT rocprofiler-register_FOUND) 103 | message(FATAL_ERROR "-- ERROR!: rocprofiler-register Not Found! - please install rocprofiler-register!") 104 | endif() 105 | endif() 106 | -------------------------------------------------------------------------------- /samples/videoToSequence/README.md: -------------------------------------------------------------------------------- 1 | # Video decode sample 2 | 3 | The VideoToSequence sample illustrates decoding a single packetized video stream using FFMPEG demuxer and splitting it into multiple video sequences. This uses seek functionality to seek to a random position and extract a batch of video sequences in YUV format with step and stride. This sample can be configured with a device ID and optionally able to dump the output to a file. This sample uses the high-level RocVideoDecoder class which connects both the video parser and Rocdecoder. This process repeats until a batch of sequences are extracted or EOS is reached. 4 | 5 | ## Prerequisites: 6 | 7 | * Install [rocDecode](../../README.md#build-and-install-instructions) 8 | 9 | * [FFMPEG](https://ffmpeg.org/about.html) 10 | 11 | * On `Ubuntu` 12 | 13 | ```shell 14 | sudo apt install libavcodec-dev libavformat-dev libavutil-dev 15 | ``` 16 | 17 | * On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script 18 | 19 | ## Build 20 | 21 | ```shell 22 | mkdir video_decode_sample && cd video_decode_sample 23 | cmake ../ 24 | make -j 25 | ``` 26 | 27 | ## Run 28 | 29 | ```shell 30 | ./videotosequence -i 31 | -o 32 | -d 33 | -b 34 | -step 35 | -stride 36 | -l 37 | -crop 38 | -seek_mode