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
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ find_package(rocjpeg 1.0.0 QUIET)
find_package(pybind11 REQUIRED)
find_package(DLPACK REQUIRED)
find_package(FFmpeg QUIET)
set(ROCPYDECODE_USE_FFMPEG ${FFMPEG_FOUND})
set(ROCPYDECODE_USE_FFMPEG FALSE)

set(ROCPYDECODE_DEPENDENCY_READY FALSE)
set(ROCPYJPEG_DEPENDENCY_READY FALSE)
Expand Down Expand Up @@ -220,14 +220,25 @@ if(rocdecode_FOUND)
set(include ${include_base})
set(sources ${sources_base})

set(ROCDECODE_FFMPEG_UTILS_DIR "${ROCM_PATH}/share/rocdecode/utils/ffmpegvideodecode")
file(GLOB ROCDECODE_FFMPEG_UTILS_SOURCES "${ROCDECODE_FFMPEG_UTILS_DIR}/*.cpp")
if(FFMPEG_FOUND
AND EXISTS "${ROCDECODE_FFMPEG_UTILS_DIR}/ffmpeg_video_dec.h"
AND ROCDECODE_FFMPEG_UTILS_SOURCES)
set(ROCPYDECODE_USE_FFMPEG TRUE)
endif()

if(ROCPYDECODE_USE_FFMPEG)
# Demux + CPU backend (FFmpeg-dependent)
file(GLOB sources_ffmpeg src/rocdecode/roc_pyvideodemuxer.cpp src/rocdecode/roc_pyvideodecodecpu.cpp src/rocdecode/roc_pydecode_test.cpp ${ROCM_PATH}/share/rocdecode/utils/ffmpegvideodecode/*.cpp)
file(GLOB include_ffmpeg ${ROCM_PATH}/share/rocdecode/utils/ffmpegvideodecode/*.h)
file(GLOB sources_ffmpeg src/rocdecode/roc_pyvideodemuxer.cpp src/rocdecode/roc_pyvideodecodecpu.cpp src/rocdecode/roc_pydecode_test.cpp ${ROCDECODE_FFMPEG_UTILS_SOURCES})
file(GLOB include_ffmpeg ${ROCDECODE_FFMPEG_UTILS_DIR}/*.h)
list(APPEND include ${include_ffmpeg})
list(APPEND sources ${sources_ffmpeg})
include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR})
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES})
elseif(FFMPEG_FOUND)
message(STATUS "FFmpeg found, but rocDecode FFmpeg utilities were not found under ${ROCDECODE_FFMPEG_UTILS_DIR}; building rocPyDecode without demux/CPU backend (GPU decode only).")
set(ROCPYDECODE_HOST_LIBRARY_FOUND FALSE)
else()
message(STATUS "FFmpeg not found; building rocPyDecode without demux/CPU backend (GPU decode only).")
set(ROCPYDECODE_HOST_LIBRARY_FOUND FALSE)
Expand Down Expand Up @@ -435,16 +446,16 @@ endif()
if(ROCPYDECODE_DEPENDENCY_READY)
set(ROCDECODE_VIDEO_DIR "${ROCM_PATH}/share/rocdecode/video")
if(IS_DIRECTORY "${ROCDECODE_VIDEO_DIR}")
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/data/videos")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/data/videos")
file(GLOB ROCDECODE_VIDEO_FILES "${ROCDECODE_VIDEO_DIR}/*")
foreach(VID_FILE IN LISTS ROCDECODE_VIDEO_FILES)
get_filename_component(VID_NAME "${VID_FILE}" NAME)
set(VID_LINK "${CMAKE_SOURCE_DIR}/data/videos/${VID_NAME}")
set(VID_LINK "${CMAKE_BINARY_DIR}/data/videos/${VID_NAME}")
if(NOT EXISTS "${VID_LINK}")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${VID_FILE}" "${VID_LINK}")
endif()
endforeach()
message("-- ${BoldBlue}Ensured rocdecode sample videos are linked into ${CMAKE_SOURCE_DIR}/data/videos${ColourReset}")
message("-- ${BoldBlue}Ensured rocdecode sample videos are linked into ${CMAKE_BINARY_DIR}/data/videos${ColourReset}")
endif()
endif()

Expand Down
72 changes: 72 additions & 0 deletions docker/rocpydecode-with-therock.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive
ARG ROCM_SERIES=10.1
ARG GPU_TARGET=gfx1250
ARG ROCM_BUILD=20260821-32431166035
ARG ROCM_PACKAGE_VERSION=10.1.0~20260821-32431166035
ARG ALLOW_UNSIGNED_ROCM_REPOSITORY=false

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
gnupg \
wget \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /etc/apt/keyrings \
&& wget -qO- https://repo.amd.com/rocm/packages-multi-arch/gpg/rocm.gpg \
| gpg --dearmor -o /etc/apt/keyrings/amdrocm.gpg

RUN if [ "${ALLOW_UNSIGNED_ROCM_REPOSITORY}" = "true" ]; then \
repository_options="trusted=yes"; \
elif [ "${ALLOW_UNSIGNED_ROCM_REPOSITORY}" = "false" ]; then \
repository_options="signed-by=/etc/apt/keyrings/amdrocm.gpg"; \
else \
echo "ALLOW_UNSIGNED_ROCM_REPOSITORY must be true or false" >&2; \
exit 2; \
fi \
&& echo "deb [${repository_options}] https://rocm.nightlies.amd.com/packages-multi-arch/deb/${ROCM_BUILD} stable main" \
> /etc/apt/sources.list.d/rocm-nightly.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
"amdrocm-core-sdk${ROCM_SERIES}-${GPU_TARGET}=${ROCM_PACKAGE_VERSION}" \
"amdrocm-decode-dev${ROCM_SERIES}=${ROCM_PACKAGE_VERSION}" \
"amdrocm-decode-test${ROCM_SERIES}=${ROCM_PACKAGE_VERSION}" \
Comment thread
essamROCm marked this conversation as resolved.
"amdrocm-jpeg-dev${ROCM_SERIES}=${ROCM_PACKAGE_VERSION}" \
"amdrocm-jpeg-test${ROCM_SERIES}=${ROCM_PACKAGE_VERSION}" \
build-essential \
cmake \
git \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libdlpack-dev \
libnuma-dev \
libswscale-dev \
ninja-build \
pkg-config \
python3.12 \
python3.12-dev \
python3.12-venv \
&& rm -rf /var/lib/apt/lists/*

RUN python3.12 -m venv /opt/venv \
&& /opt/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel \
&& /opt/venv/bin/python -m pip install --no-cache-dir numpy pybind11 pytest

ENV VIRTUAL_ENV=/opt/venv
ENV ROCM_PATH=/opt/rocm
ENV ROCM_HOME=/opt/rocm
ENV PATH=/opt/venv/bin:/opt/rocm/bin:/opt/rocm/lib/llvm/bin:${PATH}
ENV CMAKE_PREFIX_PATH=/opt/rocm/lib/cmake:/opt/venv/lib/python3.12/site-packages/pybind11/share/cmake/pybind11
ENV LD_LIBRARY_PATH=/opt/rocm/lib

RUN hipconfig --full \
&& test -d /opt/rocm/share/rocdecode/utils \
&& test -d /opt/rocm/share/rocdecode/test \
&& test -d /opt/rocm/share/rocdecode/video \
&& test -d /opt/rocm/share/rocjpeg/images

WORKDIR /workspace/EssamWork/ROCPYDECODE

CMD ["bash"]
39 changes: 28 additions & 11 deletions samples/rocdecode/videodecoderaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,37 @@ def feed_packet(buf, is_eos=False):
return False

data = memoryview(Path(input_path).read_bytes())
sps = pps = None
vps = sps = pps = None
for nal in _annexb_slices(data):
# nal header byte after start code
sc_len = 4 if nal[:4] == b"\x00\x00\x00\x01" else 3
nal_type = nal[sc_len] & 0x1F
if nal_type == 7: # SPS
sps = bytes(nal)
continue
if nal_type == 8: # PPS
pps = bytes(nal)
continue
if nal_type in (1, 5): # non-IDR / IDR slice -> frame
# prepend latest SPS/PPS so each frame is self-contained
if codec == dectypes.rocDecVideoCodec_HEVC:
nal_type = (nal[sc_len] >> 1) & 0x3F
if nal_type == 32: # VPS
vps = bytes(nal)
continue
if nal_type == 33: # SPS
sps = bytes(nal)
continue
if nal_type == 34: # PPS
pps = bytes(nal)
continue
is_slice = nal_type <= 31
else:
nal_type = nal[sc_len] & 0x1F
if nal_type == 7: # SPS
sps = bytes(nal)
continue
if nal_type == 8: # PPS
pps = bytes(nal)
continue
is_slice = nal_type in (1, 5) # non-IDR / IDR slice

if is_slice:
# Prepend the latest parameter sets so each frame is self-contained.
parts = []
if vps:
parts.append(vps)
if sps:
parts.append(sps)
if pps:
Expand All @@ -173,7 +190,7 @@ def feed_packet(buf, is_eos=False):
f"({fps:.2f} fps)."
)
else:
print("info: No frames decoded.")
raise RuntimeError("No frames decoded.")


def main():
Expand Down
3 changes: 2 additions & 1 deletion src/common/roc_pybuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ const DLTensor &BufferInterface::dlTensor() const {
}

void BufferInterface::ExportToPython(py::module &m) {
py::class_<BufferInterface, std::shared_ptr<BufferInterface>>(m, "BufferInterface", py::dynamic_attr())
py::class_<BufferInterface, std::shared_ptr<BufferInterface>>(
m, "BufferInterface", py::module_local(), py::dynamic_attr())
.def_property_readonly("shape", &BufferInterface::shape, "Get the shape of the buffer as an array")
.def_property_readonly("strides", &BufferInterface::strides, "Get the strides of the buffer")
.def_property_readonly("dtype", &BufferInterface::dtype, "Get the data type of the buffer")
Expand Down
Loading