OrangePI: H264 HW encoding with ffmpeg

Last days I’ve been experimenting with various features of OPI. One thing I’ve always been interested in is HW encoding. There is some information on linux sunxi wiki on this topic ([1][2]), which say that it’s not something straightforward and opensource.

Fortunately, there is one page which shortly mentions ffmpeg implementation which interested me. In this repo I’ve found another fork which states compatibility with Allwinner H3. After compilation, I found it works.

Next I wanted to port it to recent ffmpeg but the first repo was just commited files without proper git history. So I needed to find out, what is changed compared to mainline ffmpeg. For this I needed to find out the version it was forked from. The compiled binary from that repo showed “N-65839-g156858b” but commit 156858b doesn’t exist in ffmpeg main tree. So I started to traverse back from master by following command:

HEAD is now at 8495c6086d... vidstabutils: improve documentation
N-65837-g8495c6086d

Diff showed only some differences – this is the base version:

$ diff -r -x *.pc -x .git FFmpeg FFmpeg-Cedrus
Only in FFmpeg: .config
Only in FFmpeg: config.asm
Only in FFmpeg: config.fate
Only in FFmpeg: config.h
Only in FFmpeg: config.log
Only in FFmpeg: config.mak
Only in FFmpeg-Cedrus: description-pak
Only in FFmpeg/doc: config.texi
Only in FFmpeg-Cedrus: doc-pak
Only in FFmpeg-Cedrus: ffmpeg_2-1_armhf.deb
Only in FFmpeg: .gitignore
diff -r -x '*.pc' -x .git FFmpeg/libavcodec/allcodecs.c FFmpeg-Cedrus/libavcodec/allcodecs.c
533a534
> REGISTER_ENCODER(CEDRUS264, cedrus264);
Only in FFmpeg-Cedrus/libavcodec/arm/sunxi: h264enc.c
Only in FFmpeg-Cedrus/libavcodec/arm/sunxi: h264enc.h
Only in FFmpeg-Cedrus/libavcodec/arm/sunxi: ve.c
Only in FFmpeg-Cedrus/libavcodec/arm/sunxi: ve.c-ORG
Only in FFmpeg-Cedrus/libavcodec/arm/sunxi: ve.h
Only in FFmpeg-Cedrus/libavcodec/arm/sunxi: ve.h-ORG
Only in FFmpeg-Cedrus/libavcodec: cedrus264.c
Only in FFmpeg-Cedrus/libavcodec: cedrus264.c-ORG
diff -r -x '*.pc' -x .git FFmpeg/libavcodec/Makefile FFmpeg-Cedrus/libavcodec/Makefile
765a766
> OBJS-$(CONFIG_CEDRUS264_ENCODER) += cedrus264.o arm/sunxi/ve.o
Only in FFmpeg/libavutil: avconfig.h
Only in FFmpeg-Cedrus: README2

I copied relevant files which were only in FFmpeg-Cedrus, updated different files and created a new branch cedrus264 in mainline ffmpeg. Then I needed to apply patches from second repo to make it work on H3. After compilation, I’ve had working binary from mainline sources. Then I rebased that branch to recent ffmpeg, fixed some issue and the result is here:I tested it on my OPI and OPI Zero and it works on both. Now I’m considering to buy some CSI camera to test real world encoding performance.

Hi,
I bought a bpi-zero and I’d like to use it to transcode my LKV373A 3.0 (still thanks for awesome work about it) using hw acceleration. I compiled from your source cedrus264 branch but when I try to use it I receive this error:
cedrus264 @ 0x14c0270] VE Open error.
Error initializing output stream 0:0 — Error while opening encoder for output stream #0:0 – maybe incorrect parameters such as bit_rate, rate, width or height
It’s like it wants to start a custom *video engine* but systematically fails.
Any advice? maybe bpi-zero hw is not suitable?

Thanks for fast replay.
Unfortunately it seems you’re right (I didnt even know they were needed). Iì’m using this images kindly provided by avaf, a community member.https://github.com/avafinger/bananapi-zero-ubuntu-base-minimal
root@bpi:~/src/FFmpeg# ls /dev/mali
ls: cannot access ‘/dev/mali’: No such file or directory