Skip to main content

Video Hardware Ecoding

Requirements

Make sure dma_heap, dri, mpp_service and rga exist in /dev. Otherwise switch to BSP kernel 5.10 LTS

ls -l /dev | grep -E "mpp|rga|dri|dma_heap"

should return

drwxr-xr-x  2 root       root          80 Jan  1  1970 dma_heap
drwxr-xr-x 3 root root 140 Jan 18 18:50 dri
crw-rw---- 1 root root 241, 0 Jan 18 18:50 mpp_service
crw-rw---- 1 root root 10, 122 Jan 18 18:50 rga

1. Install librockchip-mpp-dev

Download and install latest release of librockchip-mpp-dev_vesrion_arm64.deb from this link - https://github.com/tsukumijima/mpp-rockchip /releases/ Use wget to download and sudo apt install ./lib.... to install

2. Install librga

Download and install latest release of librga-dev_version_arm64.deb from this link - https://github.com/tsukumijima/librga-rockchip/releases/ Use wget to download and sudo apt install ./lib.... to install

3. Install build dependencies

sudo apt-get update
sudo apt-get install build-essential cmake git libdrm-dev librga-dev librockchip-mpp-dev libsdl2*-dev libx264-dev libx265-dev pkg-config

4. Compile and install ffmpeg-rockchip

git clone https://github.com/nyanmisaka/ffmpeg-rockchip
pushd ffmpeg-rockchip/
./configure --prefix=/usr --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga --enable-libx264 --enable-libx265 --enable-ffplay
make -j$(nproc)
sudo make install
popd

5. Proper permission to mmp_service

Create a permission file and paste below permissions - /etc/udev/rules.d/99-rk-device-permissions.rules

Restart to make it take effect.

KERNEL=="mpp_service", MODE="0660", GROUP="video"
KERNEL=="rga", MODE="0660", GROUP="video"
KERNEL=="system", MODE="0666", GROUP="video"
KERNEL=="system-dma32", MODE="0666", GROUP="video"
KERNEL=="system-uncached", MODE="0666", GROUP="video"
KERNEL=="system-uncached-dma32", MODE="0666", GROUP="video" RUN+="/usr/bin/chmod a+rw /dev/dma_heap"
  1. https://jellyfin.org/docs/general/post-install/transcoding/hardware-acceleration/rockchip/
  2. https://docs.radxa.com/en/rock5/rock5b/app-development/rtsp
  3. https://github.com/rigaya/rkmppenc/blob/master/Install.en.md

Adjusting Webcam parameters

Use v4l2 for controlling webcam

Install

sudo apt install v4l-utils

List Devices

v4l2-ctl --list-devices

Device Details

v4l2-ctl --device /dev/video0 --all

Device video details

v4l2-ctl --device /dev/video0 --list-formats-ext

List Prameters

v4l2-ctl -d /dev/video0 --list-ctrls

Set Brightness

v4l2-ctl -d /dev/video0 --set-ctrl=brightness=30

Set Saturation

v4l2-ctl -d /dev/video0 --set-ctrl=saturation=80

Test RTSP

Using mediamtx

Start Mediamtx

nohup ~/mediamtx/mediamtx &

Encode & Stream

Then run ffmped encoder and rtsp stream hevc_rkmpp or h264_rkmpp - encoders available

~/ffmpeg-rockchip/ffmpeg -f v4l2 -input_format yuyv422 -video_size 640x480 -framerate 30 -i /dev/video0 -c:v hevc_rkmpp -b:v 1M -profile:v main -level 4.1 -f rtsp rtsp://0.0.0.0:8554/stream