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:

$ git checkout HEAD~1 && git describe --tags --match N
Previous HEAD position was 948b54763b... avcodec/lagarith: Fix runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
HEAD is now at 620b452a11... avcodec/aacdec_fixed: Fix multiple runtime error: shift exponent 127 is too large for 32-bit type 'int'

Until I found this version:

HEAD is now at 8495c6086d... vidstabutils: improve documentation

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
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
> 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.

You can get updated sources in my repo: (Don’t forget to switch to branch cedrus264).

Looking forward to your comments.

10 thoughts on “OrangePI: H264 HW encoding with ffmpeg”

  1. konecne nejaky progress pre hw akceleraciu pre tie sproste proprietary chipy… len sa smejem kam takym sposobom dosli intel, amd, arm, … vsetci su vulnerable to meltdown/spectre… zatialco risc-v, co je open-source, sa na tom vsetkom moze dobre zabavat…

  2. 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?


    1. simple test command I’m trying is
      sudo ./ffmpeg -i “udp://” -pix_fmt nv12 -c:v cedrus264 -acodec libmp3lame -ar 44100 -rtmp_live live -f null –

Leave a Reply

Your email address will not be published. Required fields are marked *