Python package for media codecs available for Rockchip
rkdecoder-python is a Python package built on top of Rockchip MPP, Rockchip RGA, FFmpeg, and pybind11.
It provides a Python-friendly interface for:
- decoding RTSP video streams with Rockchip hardware decoding
- optional image resize with RGA
- optional color conversion to formats such as
rgb,bgr,rgba,bgra, ornv12 - optional zero-copy output through DMA-backed buffers
The package is designed for Rockchip Linux systems where MPP and RGA are available.
- Hardware-accelerated RTSP decoding using Rockchip MPP
- Optional resize using Rockchip RGA
- Optional color conversion with RGA
- Optional zero-copy output as a DMA-backed Python object
- Python API via
pybind11 - Multiple decoder instances supported
- Suitable for integration with downstream inference or vision pipelines
You need the following components installed on your Rockchip device:
-
Rockchip MPP development headers and library
-
Rockchip RGA development headers and library
-
FFmpeg development headers and libraries:
libavformatlibavcodeclibavutil
-
Python 3
-
pybind11
-
CMake
-
a C++17 compiler
- MPP and RGA installation paths vary between devices and SDKs.
- This project is intentionally configurable through CMake
-D...options so users can point to their local installation paths. - On some boards there may be multiple FFmpeg header trees installed. In that case, you may need to force the FFmpeg include/library paths explicitly.
mkdir -p build
cmake -S . -B build
cmake --build build -jAfter building, the Python package will be available under:
build/python
You can then import it by adding build/python to PYTHONPATH, or by passing that directory in your test scripts.
The build is designed to be path-configurable.
Python3_EXECUTABLEpybind11_DIR
MPP_ROOTMPP_INCLUDE_HINTSMPP_LIB_HINTS
RGA_ROOTRGA_INCLUDE_HINTSRGA_LIB_HINTS
FFMPEG_ROOTFFMPEG_INCLUDE_HINTSFFMPEG_LIB_HINTS
RKDECODER_PYTHON_PACKAGE_SUBDIR
cmake -S . -B build \
-DPython3_EXECUTABLE=$(which python)
cmake --build build -jcmake -S . -B build \
-DPython3_EXECUTABLE=$(which python) \
-DMPP_INCLUDE_HINTS=/usr/local/include \
-DMPP_LIB_HINTS=/usr/local/lib \
-DRGA_INCLUDE_HINTS="/path/to/rkrga/include;/path/to/rkrga/im2d_api" \
-DRGA_LIB_HINTS=/path/to/rkrga_build
cmake --build build -jcmake -S . -B build \
-DPython3_EXECUTABLE=$(which python) \
-DFFMPEG_INCLUDE_HINTS="/opt/ffmpeg/include;/opt/ffmpeg/include/aarch64-linux-gnu" \
-DFFMPEG_LIB_HINTS="/opt/ffmpeg/lib;/opt/ffmpeg/lib/aarch64-linux-gnu" \
-DMPP_INCLUDE_HINTS=/usr/local/include \
-DMPP_LIB_HINTS=/usr/local/lib \
-DRGA_INCLUDE_HINTS="/path/to/rkrga/include;/path/to/rkrga/im2d_api" \
-DRGA_LIB_HINTS=/path/to/rkrga_build
cmake --build build -jcmake -S . -B build \
-DPython3_EXECUTABLE=$(which python) \
-Dpybind11_DIR=$(python -m pybind11 --cmakedir)
cmake --build build -jIf you built the project locally, the package is typically located under:
build/python
Use it like this:
PYTHONPATH=build/python pythonThen in Python:
import rkdecoderimport rkdecoder
decoder = rkdecoder.rkdecoder(
"rtsp://127.0.0.1:8554/mystream",
output_format="rgb",
size=(640, 640),
zero_copy=False,
)-
url: RTSP URL -
output_format: one of:"rgb""bgr""rgba""bgra""nv12"
-
size: optional output size as(width, height)- use
Noneto disable resize
- use
-
zero_copy: whether to return DMA-backed output instead of a NumPy array
frame = decoder.get(timeout_ms=1000)import rkdecoder
decoder = rkdecoder.rkdecoder(
"rtsp://127.0.0.1:8554/mystream",
output_format="rgb",
size=None,
zero_copy=False,
)
while True:
frame = decoder.get(timeout_ms=1000)
print(frame.shape)import rkdecoder
decoder = rkdecoder.rkdecoder(
"rtsp://127.0.0.1:8554/mystream",
output_format="rgb",
size=(640, 640),
zero_copy=False,
)
frame = decoder.get(timeout_ms=1000)
print(frame.shape)import rkdecoder
decoder = rkdecoder.rkdecoder(
"rtsp://127.0.0.1:8554/mystream",
output_format="rgb",
size=(640, 640),
zero_copy=True,
)
frame = decoder.get(timeout_ms=1000)
print(frame.fd, frame.width, frame.height)A Python benchmark script can be placed under test/, for example:
python test/benchmark.py \
"rtsp://127.0.0.1:8554/mystream" \
--python-package-dir build/python \
--size 640x640 \
--output-format rgbExample with zero-copy:
python test/benchmark.py \
"rtsp://127.0.0.1:8554/mystream" \
--python-package-dir build/python \
--size 640x640 \
--output-format rgb \
--zero-copyInstall pybind11 in the Python environment used for build:
python -m pip install pybind11Or pass:
-Dpybind11_DIR=$(python -m pybind11 --cmakedir)Some older CMake versions behave differently. Use a CMake version that properly supports your Python toolchain, or ensure Python development headers are installed.
If your system contains both:
/usr/include/libavcodec/usr/include/<triplet>/libavcodec
you may need to force a single FFmpeg tree:
-DFFMPEG_INCLUDE_HINTS=...
-DFFMPEG_LIB_HINTS=...Your RGA installation may split headers across multiple directories, commonly:
includeim2d_api
Pass both:
-DRGA_INCLUDE_HINTS="/path/to/rkrga/include;/path/to/rkrga/im2d_api"Check:
/dev/dma_heap/*/dev/dri/renderD*
This may be caused by:
- missing allocator devices
- permission problems
- environment-specific DMA allocation differences
If the built module name contains a Python ABI tag that does not match your runtime Python, rebuild using the exact Python interpreter you plan to run with:
-DPython3_EXECUTABLE=$(which python)- This project targets Rockchip Linux systems
- MPP / RGA behavior may vary between SoCs, SDK versions, and distro packaging
- Zero-copy output depends on allocator/device availability
- Some performance characteristics depend on stream format, driver versions, and memory path