[FFmpeg] Introduce FFmpeg-Rockchip for hyper fast video transcoding via CLI

its works, thanks nayanmisaka!

here is my setup fully command.

# using Ubuntu 24.04 (Noble) 

sudo apt update -y
sudo apt upgrade -y
sudo apt install git meson cmake pkg-config gcc libasound2-dev -y
sudo aptitude install libdrm-dev
# n
# y
# y

build package

Build MPP

mkdir -p ~/dev && cd ~/dev
git clone -b jellyfin-mpp --depth=1 https://github.com/nyanmisaka/mpp.git rkmpp
pushd rkmpp
mkdir rkmpp_build
pushd rkmpp_build
cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TEST=OFF \
    ..
sudo make -j $(nproc)
sudo make install

Build RGA

mkdir -p ~/dev && cd ~/dev
git clone -b jellyfin-rga --depth=1 https://github.com/nyanmisaka/rk-mirrors.git rkrga
meson setup rkrga rkrga_build \
    --prefix=/usr \
    --libdir=lib \
    --buildtype=release \
    --default-library=shared \
    -Dcpp_args=-fpermissive \
    -Dlibdrm=false \
    -Dlibrga_demo=false
meson configure rkrga_build
ninja -C rkrga_build install
# q
# y

Build the FFmpeg with alsa audio

mkdir -p ~/dev && cd ~/dev
git clone --depth=1 https://github.com/nyanmisaka/ffmpeg-rockchip.git ffmpeg
cd ffmpeg
./configure --prefix=/usr --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga --enable-alsa
sudo make -j $(nproc)

Install FFmpeg

# Try the compiled FFmpeg without installation
./ffmpeg -decoders | grep rkmpp
./ffmpeg -encoders | grep rkmpp
./ffmpeg -filters | grep rkrga
# Install FFmpeg to the prefix path
sudo make install

BTW, has anyone successfully recorded video and audio via HDMI-in?

Iā€™m using the following command. It works, but I always get warnings and experience some audio skipping:

arecord -D hw:0,0 -f cd | ffmpeg -re -i /dev/video0 -f wav -i pipe:0 -c:v h264_rkmpp -maxrate 1900k -bufsize 3968k -vf "scale=1920:1080" -c:a aac -b:a 128k -af "volume=7.0" -f flv "rtmp://your_url

The response I get is:

overrun!!! (at least 12.465 ms long)57250kB time=00:51:43.34 bitrate=1471.0kbits/s speed=   1x    
overrun!!! (at least 134.581 ms long)8560kB time=00:51:50.38 bitrate=1471.1kbits/s speed=   1x    
overrun!!! (at least 42.422 ms long)59810kB time=00:51:56.95 bitrate=1471.3kbits/s speed=   1x    
overrun!!! (at least 29.663 ms long)60949kB time=00:52:02.99 bitrate=1471.4kbits/s speed=   1x    
overrun!!! (at least 108.499 ms long)2188kB time=00:52:09.53 bitrate=1471.6kbits/s speed=   1x    
overrun!!! (at least 28.869 ms long)63422kB time=00:52:16.13 bitrate=1471.7kbits/s speed=   1x  

Thanks again nyanmisaka! Iā€™ve been using non-RPi SBCs for about a decade and this is the best SW implementation of a HW video encoder Iā€™ve seen.

I often use markus-perlā€™s ffmpeg-build-script https://github.com/markus-perl/ffmpeg-build-script to build ffmpeg with the latest versions of all the libs (svt-av1, x265 etc.)

I made a fork of his script so that it builds ffmpeg-rockchip and itā€™s dependencies (libdrm, rkmpp, rkrgaā€¦), as well as all the usual ffmpeg included codecs, instead of the minimal build.

Iā€™ll share the repo here if in case itā€™s of use to anyone (Iā€™m aware that x264, x265 and probably svt-av1 might not be of much use on RK35xx devices in terms of encoding speed)

Use:
./build-ffmpeg --enable-gpl-and-non-free --build

I installed the repository above
(git clone https://github.com/nyanmisaka/ffmpeg-rockchip.git)
Then when I ran the code to build it:
./build-ffmpeg --enable-gpl-and-non-free --build
But I received this message:
./build-ffmpeg: No such file or directory
It didnā€™t find the builder.
So I installed the original BUILDER that is in the GITHUB description:
git clone https://github.com/markus-perl/ffmpeg-build-script.git
Then, run the ./build-ffmpeg --enable-gpl-and-non-free --build
But after 4 hours of compiling it did not show the hardware acceleration libraries.
Firstly, it didnā€™t move the binaries to the root directory. I had to do it manually. After installed and running in PATH, when listing the encoders there is no encoder with hardware acceleration.
$ ffmpeg -hwaccels
Returns no acceleration methods!
What did I do wrong? Could you help me?

It seems that youā€™ve used a script that builds mainline ffmpeg.

Yes. I did it wrong.

Now I could do all the process as told here:

Finally I could get a FFMPEG that really uses h264_rkmpp:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_rkmpp))

YEY :partying_face:

But I had a problem. I dont know why the APP uses a wrong time stamp. I did a small 3 min video and it marks as 33min. The time counter never gets reseted.

See below a video with 10 seconds marks 40min:

rock@rock-3c:~/cinebaby$ ffmpeg -f v4l2 -video_size 1920x1080 -framerate 20 -i /dev/video0 -c:v h264_rkmpp -pix_fmt yuv420p -b:v 4M -f mp4 gravadoRK8.mp4
ffmpeg version 27443ed Copyright Ā© 2000-2023 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
libpostproc 57. 3.100 / 57. 3.100
[video4linux2,v4l2 @ 0xaaaadfb6f130] Dequeued v4l2 buffer contains corrupted data (0 bytes).
Input #0, video4linux2,v4l2, from ā€˜/dev/video0ā€™:
Duration: N/A, start: 0.000000, bitrate: 663552 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 663552 kb/s, 20 fps, 20 tbr, 1000k tbn
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_rkmpp))
Press [q] to stop, [?] for help
[video4linux2,v4l2 @ 0xaaaadfb6f130] Dequeued v4l2 buffer contains corrupted data (0 bytes).
Last message repeated 62 times
Output #0, mp4, to ā€˜gravadoRK8.mp4ā€™:
Metadata:
encoder : Lavf60.16.100
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, progressive), 1920x1080, q=2-31, 4000 kb/s, 20 fps, 10240 tbn
Metadata:
encoder : Lavc60.31.102 h264_rkmpp
frame= 505 fps= 20 q=-0.0 size= 0kB time=00:40:01.05 bitrate= 0.0kbits/s speed= 95x

[q] command received. Exiting.

[out#0/mp4 @ 0xaaaadfb71b70] video:42kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 6.889319%
frame= 507 fps= 20 q=-0.0 Lsize= 45kB time=00:40:01.15 bitrate= 0.2kbits/s speed=94.5x

I have noted that ffmpeg has problems terminating the process.
The first recording goes ok.
The second recording shows this message:
[video4linux2,v4l2 @ 0xaaaadfb6f130] Dequeued v4l2 buffer contains corrupted data (0 bytes).
And becomes ā€œunkilleableā€ i cant process.kill() it.

Changin the USB port frm 3.0 to 2.0 USB this corrupted data message vanishes, it forces low FR and the process is still unkileable. I cant terminate it.