一、環境檢測與前置依賴
確認內核與 HDMI-RX 節點:
uname -a
# 輸出:6.1.0-1025-rockchip ...dmesg | grep -i hdmirx
# 應能看到 hdmirx-controller 節點:
# fdee0000.hdmirx-controller driver probe ok!
如果僅出現:
rockchip-dmc dmc: hdmirx_rate = 2112000000
說明設備樹已識別 hdmirx,但沒有加載 Overlay (rk3588-hdmirx.dtbo)。
更新系統依賴:
sudo apt update
sudo apt install -y \gstreamer1.0-plugins-base gstreamer1.0-plugins-good \gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-tools v4l-utils
二、啟用 HDMI-RX Overlay
-
獲取或編譯 Overlay 文件
從 Joshua-Riek Rockchip Ubuntu 倉庫 下載rk3588-hdmirx.dtbo
,拷貝到固件路徑:
sudo cp rk3588-hdmirx.dtbo \/lib/firmware/6.1.0-1025-rockchip/device-tree/rockchip/overlay/
-
編輯 u-boot 配置
sudo vim /etc/default/u-boot
取消注釋并加入:
U_BOOT_FDT_OVERLAYS="device-tree/rockchip/overlay/rk3588-hdmirx.dtbo"
-
更新并重啟
sudo u-boot-update
sudo reboot
-
驗證驅動加載
dmesg | grep -i hdmirx
v4l2-ctl --list-devices
ls /dev/video*
# 應看到 /dev/video0 (hdmirx)
三、安裝 RGA 硬件加速支持
-
安裝 librga 并生成 pkg-config
git clone https://github.com/airockchip/librga.git
cd librgasudo mkdir -p /usr/local/lib/pkgconfig
sudo tee /usr/local/lib/pkgconfig/librga.pc > /dev/null <<'EOF'
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/includeName: librga
Description: Rockchip Raster Graphic Acceleration library
Version: 2.2
Libs: -L${libdir} -lrga
Cflags: -I${includedir}
EOF
-
復制頭文件和庫文件
sudo cp -r include/* /usr/local/include/
sudo cp libs/Linux/gcc-aarch64/* /usr/local/lib/
sudo ldconfig
-
配置環境變量
echo 'export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH' >> ~/.bashrc
source ~/.bashrc
-
測試
pkg-config --modversion librga
# 輸出 2.2(或實際版本)
四、構建 gstreamer-rgaconvert 插件
git clone https://github.com/higithubhi/gstreamer-rgaconvert.git
cd gstreamer-rgaconvert
meson setup build --wipe
ninja -C build
sudo ninja -C build install
安裝完成后,將插件放到 GStreamer 搜索路徑:
sudo cp build/libgstrgaconvert.so /usr/lib/aarch64-linux-gnu/gstreamer-1.0/
測試插件:
gst-inspect-1.0 rgaconvert
五、重建支持 GStreamer 的 OpenCV 5.x
-
準備源碼
git clone https://github.com/opencv/opencv.git
cd opencv && git checkout 5.x && cd ..
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib && git checkout 5.x && cd ..
-
構建 OpenCV
mkdir build_opencv && cd build_opencvcmake ../opencv \-D CMAKE_BUILD_TYPE=Release \-D CMAKE_INSTALL_PREFIX=~/opencv-gst-install \-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \-D WITH_GSTREAMER=ON \-D WITH_GTK=ON \-D WITH_FFMPEG=ON \-D WITH_V4L=ON \-D BUILD_opencv_highgui=ON \-D OPENCV_ENABLE_NONFREE=ON \-D BUILD_EXAMPLES=OFF \-D PYTHON3_EXECUTABLE=$(which python) \-D PYTHON3_INCLUDE_DIR=$(python -c "from sysconfig import get_paths; print(get_paths()['include'])") \-D PYTHON3_LIBRARY=$(python -c "import sysconfig, sys; print(sysconfig.get_config_var('LIBDIR') + '/libpython' + sys.version[:3] + '.so')") \-D PYTHON3_PACKAGES_PATH=$(python -c "import site; print(site.getsitepackages()[0])")
如果 CMake 輸出:
-- GStreamer: YES
-- Found librga: /usr/local/lib/librga.so
表示 RGA 與 GStreamer 支持已啟用。
六、測試 HDMI 輸入 + RGA 加速
-
直接用 GStreamer 測試
DEVICE=/dev/video0
gst-launch-1.0 v4l2src device=$DEVICE io-mode=4 ! \rgaconvert ! \video/x-raw,width=1280,height=720,format=NV12 ! \autovideosink
-
OpenCV + GStreamer
import cv2pipeline = ("v4l2src device=/dev/video0 io-mode=4 ! ""video/x-raw,format=NV12,width=1920,height=1080 ! ""rgaconvert ! ""video/x-raw,width=1280,height=720,format=NV12 ! ""appsink"
)cap = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER)while cap.isOpened():ret, frame = cap.read()if not ret:breakcv2.imshow("HDMI-IN with RGA", frame)if cv2.waitKey(1) & 0xFF == 27: # ESC 退出breakcap.release()
cv2.destroyAllWindows()