Linux hardware video encoding on Amlogic A311D2 processor
I’ve spent a bit more time with Ubuntu 22.04 on Khadas VIM4 Amogic A311D2 SBC, and while the performance is generally good features like 3D graphics acceleration and hardware video decoding are missing. But I was pleased to see a Linux hardware video encoding section in the Wiki, as it’s not something we often see supported early on. So I’ve given it a try… First, we need to make a video in NV12 pixel format that’s commonly outputted from cameras. I downloaded a 45-second 1080p H.264 sample video from Linaro, and converted it with ffmpeg:
1 |
ffmpeg -i big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4 -pix_fmt nv12 big_buck_bunny_1080p_H264_AAC_25fps_7200K-nv12.yuv |
I did this on my laptop. As a raw video, it’s pretty big with 3.3GB of storage used for a 45-second video:
1 2 3 4 |
ls -lh total 3.3G -rw-rw-r-- 1 jaufranc jaufranc 40M Aug 5 2011 big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4 -rw-rw-r-- 1 jaufranc jaufranc 3.3G May 21 15:03 big_buck_bunny_1080p_H264_AAC_25fps_7200K-nv12.yuv |
Now let’s try to encode the video to H.264 on Khadas VIM4 board using aml_enc_test hardware video encoding sample:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
khadas@Khadas:~$ time aml_enc_test 1080p.nv12 dump.h264 1920 1080 30 25 6000000 1125 1 0 2 4 src_url is : 1080p.nv12 ; out_url is : dump.h264 ; width is : 1920 ; height is : 1080 ; gop is : 30 ; frmrate is : 25 ; bitrate is : 6000000 ; frm_num is : 1125 ; fmt is : 1 ; buf_type is : 0 ; num_planes is : 2 ; codec is : 4 ; codec is H264 Set log level to 4 [initEncParams:177] enc_feature_opts is 0x0 , GopPresetis 0x0 [SetupEncoderOpenParam:513] GopPreset GOP format (2) period 30 LongTermRef 0 [vdi_sys_sync_inst_param:618] [VDI] fail to deliver sync instance param inst_idx=0 [AML_MultiEncInitialize:1378] VPU instance param sync with open param failed [SetSequenceInfo:979] Required buffer fb_num=3, src_num=1, actual src=3 1920x1080 Encode End!width:1920 real 0m26.074s user 0m1.832s sys 0m4.883s |
The output explains the parameters used. There are some error messages, […]