Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/build_libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
apt-get update -qq &&
apt-get install -y build-essential g++ glslang-tools \
python3 python3-pip libglfw3-dev libvulkan-dev locales wget pkg-config \
protobuf-compiler libprotoc-dev libopencv-dev
protobuf-compiler libprotoc-dev libopencv-dev \
libavcodec-dev libavformat-dev libavutil-dev
python3 -m pip install --upgrade pip
python3 -m pip install cmake future==1.0.0 pytz==2022.1 numpy==1.23.0 \
google==3.0.0 protobuf==3.12.4
Expand All @@ -48,6 +49,7 @@ jobs:
rocsolver-dev hipsolver-dev \
rocfft-dev hipfft-dev \
rocalution-dev \
rocdecode-dev \
rocjpeg-dev \
rocsparse-dev \
rocthrust-dev \
Expand Down
110 changes: 110 additions & 0 deletions Common/rocdecode_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright (c) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#ifndef COMMON_ROCDECODE_UTILS_HPP
#define COMMON_ROCDECODE_UTILS_HPP

#include "example_utils.hpp"

#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>

// Include rocDecode headers for type definitions
#include "rocvideodecode/roc_video_dec.h"
#include "md5.h"

typedef enum reconfigure_flush_mode_enum {
RECONFIG_FLUSH_MODE_NONE = 0x0, /**< Just flush to get the frame count */
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 0x1, /**< The remaining frames will be dumped to file in this mode */
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = (0x1 << 1), /**< Calculate the MD5 of the flushed frames */
} reconfigure_flush_mode;

// This struct is used by sample apps to dump last frames to file
typedef struct reconfig_dump_file_struct_t {
bool b_dump_frames_to_file;
std::string output_file_name;
void *md5_generator_handle;
} reconfig_dump_file_struct;

// Callback function to flush last frames and save it to file when reconfigure happens
inline int reconfigure_flush_callback(void *p_viddec_obj, uint32_t flush_mode, void *p_user_struct)
{
int n_frames_flushed = 0;
if ((p_viddec_obj == nullptr) || (p_user_struct == nullptr))
{
return n_frames_flushed;
}

RocVideoDecoder *viddec = static_cast<RocVideoDecoder *>(p_viddec_obj);
OutputSurfaceInfo *surf_info;
if (!viddec->GetOutputSurfaceInfo(&surf_info))
{
std::cerr << "Error: Failed to get Output Surface Info!" << std::endl;
return n_frames_flushed;
}

uint8_t *pframe = nullptr;
int64_t pts;
while ((pframe = viddec->GetFrame(&pts)))
{
if (flush_mode != RECONFIG_FLUSH_MODE_NONE)
{
reconfig_dump_file_struct *p_dump_file_struct = static_cast<reconfig_dump_file_struct *>(p_user_struct);
if (flush_mode & reconfigure_flush_mode::RECONFIG_FLUSH_MODE_DUMP_TO_FILE)
{
if (p_dump_file_struct->b_dump_frames_to_file)
{
viddec->SaveFrameToFile(p_dump_file_struct->output_file_name, pframe, surf_info);
}
}
if (flush_mode & reconfigure_flush_mode::RECONFIG_FLUSH_MODE_CALCULATE_MD5)
{
MD5Generator *md5_generator = static_cast<MD5Generator*>(p_dump_file_struct->md5_generator_handle);
md5_generator->UpdateMd5ForFrame(pframe, surf_info);
}
}
// release and flush frame
viddec->ReleaseFrame(pts, true);
n_frames_flushed++;
}

return n_frames_flushed;
}

inline int get_env_var(const char *name, int &dev_count)
{
char *v = std::getenv(name);
if (v)
{
char* p_tkn = std::strtok(v, ",");
while (p_tkn != nullptr)
{
dev_count++;
p_tkn = strtok(nullptr, ",");
}
}
return dev_count;
}

#endif // COMMON_ROCDECODE_UTILS_HPP
1 change: 1 addition & 0 deletions Libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if(
add_subdirectory(rocALUTION)
add_subdirectory(rocBLAS)
add_subdirectory(rocCV)
add_subdirectory(rocDecode)
add_subdirectory(rocJPEG)
add_subdirectory(rocFFT)
add_subdirectory(rocPRIM)
Expand Down
1 change: 1 addition & 0 deletions Libraries/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ LIBRARIES += \
rocALUTION \
rocBLAS \
rocCV \
rocDecode \
rocFFT \
rocJPEG \
rocPRIM \
Expand Down
58 changes: 58 additions & 0 deletions Libraries/rocDecode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# MIT License
#
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
project(rocDecode_examples LANGUAGES CXX)
include(CTest)

file(RELATIVE_PATH folder_bin ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${folder_bin})

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
message(STATUS "rocDecode examples are only available on Linux")
return()
else()
set(ROCM_ROOT
"/opt/rocm"
CACHE PATH
"Root directory of the ROCm installation"
)
endif()

list(APPEND CMAKE_PREFIX_PATH "${ROCM_ROOT}")

find_package(rocdecode REQUIRED)
if(NOT rocdecode_FOUND)
message(STATUS "rocDecode could not be found, not building rocDecode examples")
return()
endif()

add_subdirectory(rocdec_decode)
add_subdirectory(video_decode)
add_subdirectory(video_decode_batch)
add_subdirectory(video_decode_mem)
add_subdirectory(video_decode_multi_files)
add_subdirectory(video_decode_perf)
add_subdirectory(video_decode_pic_files)
add_subdirectory(video_decode_raw)
add_subdirectory(video_decode_rgb)
add_subdirectory(video_to_sequence)
43 changes: 43 additions & 0 deletions Libraries/rocDecode/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# MIT License
#
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

EXAMPLES := \
rocdec_decode \
video_decode \
video_decode_batch \
video_decode_mem \
video_decode_multi_files \
video_decode_perf \
video_decode_pic_files \
video_decode_raw \
video_decode_rgb \
video_to_sequence

all: $(EXAMPLES)

clean: TARGET=clean
clean: all

$(EXAMPLES):
$(MAKE) -C $@ $(TARGET)

.PHONY: all clean $(EXAMPLES)
42 changes: 42 additions & 0 deletions Libraries/rocDecode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# rocDecode Examples

## Summary

The examples in this subdirectory showcase the functionality of the [rocDecode](https://github.com/ROCm/rocDecode) library. rocDecode is AMD's high-performance video decode SDK for AMD GPUs, providing hardware-accelerated video decoding capabilities. The examples demonstrate various use cases including basic video decoding, batch processing, color space conversion, and performance optimization. The examples build only on Linux for the ROCm (AMD GPU) backend.

## Prerequisites

### Linux

- [CMake](https://cmake.org/download/) (at least version 3.21)
- Or GNU Make - available via the distribution's package manager
- [ROCm](https://rocm.docs.amd.com/projects/HIP/en/latest/install/install.html) (at least version 6.0)
- [rocDecode](https://github.com/ROCm/rocDecode): `rocdecode` and `rocdecode-dev` packages available from [repo.radeon.com](https://repo.radeon.com/rocm/). The repository is added during the standard ROCm [install procedure](https://rocm.docs.amd.com/projects/HIP/en/latest/install/install.html)
- [FFMPEG](https://ffmpeg.org/about.html) development libraries:
- On Ubuntu: `sudo apt install libavcodec-dev libavformat-dev libavutil-dev`
- On RHEL/SLES: Install FFMPEG development packages manually or use the [rocDecode-setup.py](https://github.com/ROCm/rocDecode/blob/develop/rocDecode-setup.py) script

### Windows

Support for Windows will be included in the future.

## Building

### Linux

Ensure the dependencies are installed, or use the [provided Dockerfiles](../../Dockerfiles/) to build and run the examples in a containerized environment that has all prerequisites installed.

#### Using CMake

All examples in the `rocDecode` subdirectory can either be built by a single CMake project or be built independently.

- `$ cd Libraries/rocDecode`
- `$ cmake -S . -B build`
- `$ cmake --build build`

#### Using Make

All examples can be built by a single invocation to Make or be built independently.

- `$ cd Libraries/rocDecode`
- `$ make`
1 change: 1 addition & 0 deletions Libraries/rocDecode/rocdec_decode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rocdecode_rocdec_decode
79 changes: 79 additions & 0 deletions Libraries/rocDecode/rocdec_decode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# MIT License
#
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set(example_name rocdecode_rocdec_decode)

cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
project(${example_name} LANGUAGES CXX)

include("../../../Common/HipPlatform.cmake")
select_gpu_language()

enable_language(${ROCM_EXAMPLES_GPU_LANGUAGE})
set(CMAKE_${ROCM_EXAMPLES_GPU_LANGUAGE}_STANDARD 17)
set(CMAKE_${ROCM_EXAMPLES_GPU_LANGUAGE}_EXTENSIONS OFF)
set(CMAKE_${ROCM_EXAMPLES_GPU_LANGUAGE}_STANDARD_REQUIRED ON)
select_hip_platform()
verify_hip_platform(PLATFORMS "amd")

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
message(STATUS "rocDecode examples are only available on Linux")
return()
else()
set(ROCM_ROOT
"/opt/rocm"
CACHE PATH
"Root directory of the ROCm installation"
)
endif()

list(APPEND CMAKE_PREFIX_PATH "${ROCM_ROOT}")

find_package(rocdecode REQUIRED)

# Try to find the host library directly (handles both naming conventions)
find_library(ROCDECODE_HOST_LIB
NAMES rocdecode-host rocdecodehost
PATHS ${ROCM_ROOT}/lib
NO_DEFAULT_PATH
)

add_executable(${example_name} main.cpp)

target_link_libraries(${example_name} PRIVATE rocdecode::rocdecode)

# Link host library if found
if(ROCDECODE_HOST_LIB)
target_link_libraries(${example_name} PRIVATE ${ROCDECODE_HOST_LIB})
target_compile_definitions(${example_name} PRIVATE ENABLE_HOST_DECODE=1)
else()
target_compile_definitions(${example_name} PRIVATE ENABLE_HOST_DECODE=0)
endif()

target_include_directories(
${example_name}
PRIVATE "../../../Common" "../../../External"
)

set_source_files_properties(main.cpp PROPERTIES LANGUAGE ${ROCM_EXAMPLES_GPU_LANGUAGE})

install(TARGETS ${example_name})
Loading
Loading