Yggdrasil
Posts: 138
Joined: Sun Aug 26, 2012 8:45 pm

HOWTO: Add HEVC-Patches from LibreELEC to mplayer

Tue Jun 14, 2016 4:21 pm

Hello,

the Kodi/LibreELEC developer improved the HECV decoding
capabilities off ffmpeg. I did not investigate the details of
their impressing changes¹, but will describe here how the
changes could be added to mplayer, too :)

The instruction describes the native compiling under Rasbian (on a RPi3).

1) Fetch mplayer
git clone --depth 0 git://git.mplayerhq.hu/mplayer

2) Configure mplayer (this fetches ffmpeg)
cd mplayer; ./configure

3) Patch ffmpeg with files from
https://github.com/LibreELEC/LibreELEC. ... eg/patches

Code: Select all

wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-050-libressl-is-free.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1000-mpeg4video-Signal-unsupported-GMC-with-more-than-one.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1001-hevcdsp_ARM_NEON_optimized_epel_functions.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1002-added_ARM_NEON_optimized_SAO_patches.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1003-pfcd_hevc_optimisations.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1004-0001-Squashed-commit-of-the-following.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1005-0001-avcodec-add-h264_mvc-codec-id-and-profiles.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1006-0001-h264_parser-add-support-for-parsing-h264-mvc-NALUs.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1007-h264_parser_fix_parsing_of_mvc_slices_in_some_corner_cases.patch"
wget "https://raw.githubusercontent.com/LibreELEC/LibreELEC.tv/master/packages/multimedia/ffmpeg/patches/ffmpeg-99.1008-73fde6f9f3d01f7fc0f3ae4b66f6c725f9fb1105.patch"
(The list might be incomplete in the future.)
Copy the patch files into mplayer/ffmpeg and apply them, i. e. with

Code: Select all

cd ffmpeg ; for I in $(ls *.patch); do patch -Np1 --ignore-whitespace < "$I" ; echo "$I finished. Continue?" ; read WAIT ; done
Edit (Aug 2016): Currently ffmpeg-99.1006-0001-h264_parser-add-support-for-parsing-h264-mvc-NALUs.patch
throw a few errors during the patching because some ffmpeg variables was prefixed with 'H264_'.
Resolve the errors in libavcodec/h264.h and libavcodec/h264_parser.c manually use new patch file, a few posts later.

4) Extract the attachment (omx.configure.sh) into the mplayer folder and (re-)setup ffmpeg.

Code: Select all

cd mplayer ; ./omx.configure
The config assumed that the dependenices of the omxplayer are resolved. For unmeet dependecies on your RPi, 'configure' throws an error like 'ERROR: smbclient not found'.
You could try to disable the library in omx.confgure (i.e. change enable-smbclient to disable-smbclient or remove argument) or install the depdencies (sudo apt-get install libsmbclient-dev).
The third variant would be the call of 'prepare-native-raspbian.sh' from the omxplayer repo. The script automates the depedency resolving of omxplayer and should work in our case, too.

5) Edit config.mak and append the following flags to EXTRALIBS

Code: Select all

 -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -lvcsm 
6) Compile
make -j4


=====

To compare the decoding speed with the default ffhevc decoder, do the following:
1. Open omx.configure and set the environment variable RPI to 0 (second line).
2. ./omx.configure
3. make clean; make

====

If everything works the following 720p example video should be playable:
http://trailers.divx.com/hevc/TearsOfSt ... _7subs.mkv

===

Benchmarks on RPi3 without overclocking (=> [email protected] MHz):

I'v used the following command to test the decoder:
./mplayer -frames 400 -vo null -nosound -benchmark TearsOfSteel_720p_24fps_27qp_831kbps_720p_GPSNR_41.65_HM11_2aud_7subs.mk

Without patches:
BENCHMARKs: VC: 26.493s VO: 0.002s A: 0.000s Sys: 0.113s = 26.607s
BENCHMARK%: VC: 99.5702% VO: 0.0063% A: 0.0000% Sys: 0.4236% = 100.0000%

With patches:
BENCHMARKs: VC: 12.134s VO: 0.002s A: 0.000s Sys: 0.125s = 12.260s
BENCHMARK%: VC: 98.9681% VO: 0.0137% A: 0.0000% Sys: 1.0182% = 100.0000%

The improvement ist really impressing, but note: The decoding still not reached realtime. Without any overclocking, the complete decoding of the example video (12:XX min) last approx 16 Min.


Regards Yggdrasil

______________________
¹) According to the patch notes, all work was done by
Peter de Rivaz, popcornmix, Ben Avison, and John Cox!
Attachments
omx.configure.sh.zip
FFMPEG configuration from omxplayer.
(1.4 KiB) Downloaded 87 times
Last edited by Yggdrasil on Tue Aug 16, 2016 2:41 pm, edited 10 times in total.

tvjon
Posts: 715
Joined: Mon Jan 07, 2013 9:11 am

Re: HOWTO: Add HEVC-Patches from LibreELEC to mplayer

Tue Jun 14, 2016 6:06 pm

As I was reading your interesting post, I remembered I built mpv on this card recently, so downloaded the clip, & mpv does play it, but not real time either. When I get a spare moment I shall apply the patches to mplayer & compare the results.

Here is what mpv says about the clip whilst it is playing:


[email protected]:~/Videos $ mpv TearsOfSteel_720p_24fps_27qp_831kbps_720p_GPSNR_41.65_HM11_2aud_7subs.mkv

Compiled without libass.
There will be no OSD and no text subtitles.

Playing: TearsOfSteel_720p_24fps_27qp_831kbps_720p_GPSNR_41.65_HM11_2aud_7subs.mkv
(+) Video --vid=1 (*) (hevc)
Audio --aid=1 (aac)
(+) Audio --aid=2 (*) (ac3)
(+) Subs --sid=1 --slang=ger (*) 'German' (subrip)
Subs --sid=2 --slang=eng 'English' (subrip)
Subs --sid=3 --slang=spa 'Spanish' (subrip)
Subs --sid=4 --slang=fre 'French' (subrip)
Subs --sid=5 --slang=jpn 'Japanese' (subrip)
Subs --sid=6 --slang=dut 'Dutch' (subrip)
Subs --sid=7 --slang=rus 'Russian' (subrip)
[sub] Could not find subtitle decoder for format 'subrip'.
AO: [alsa] 48000Hz stereo 2ch s16
Using software decoding.

VO: [rpi] 1280x720 yuv420p
AV: 00:00:14 / 00:12:14 (1%) A-V: 0.442 Dropped: 64

Audio/Video desynchronisation detected! Possible reasons include too slow
hardware, temporary CPU spikes, broken drivers, and broken files. Audio
position will not match to the video (see A-V status field).

AV: 00:12:13 / 00:12:14 (99%) A-V: 0.000 Dropped: 8508


Exiting... (End of file)
[email protected]:~/Videos $

Yggdrasil
Posts: 138
Joined: Sun Aug 26, 2012 8:45 pm

Re: HOWTO: Add HEVC-Patches from LibreELEC to mplayer

Tue Jun 14, 2016 8:10 pm

Oh, I did not expect that mpv could play HEVC because the mplayer of Rasbian was not compiled with this option.
I've tried it out now, but use the default Raspian variant. This has 'no -vo fbdev'-support. I've started X11 and use this command to compare it with the both values above.
time DISPLAY=:0.0 mpv --no-audio -frames=400 -untimed TearsOfSteel_720p_24fps_27qp_831kbps_720p_GPSNR_41.65_HM11_2aud_7subs.mkv

The decoding of the first 400 frames required over 150 seconds and all four cores was fully loaded...

Yggdrasil
Posts: 138
Joined: Sun Aug 26, 2012 8:45 pm

Re: HOWTO: Add HEVC-Patches from LibreELEC to mplayer

Thu Jun 16, 2016 5:55 pm

As I could not know if the patches of Kodi at all support RPi 1, I've compiled it on an older system (4.1.19+ kernel; RPi1).
On this system the GPU-sided code hangs up and neither mplayer could not be terminated nor the system could be restared.

A sobering result, but at least I could share the solution for the following compiling error.
stream/tvi_v4l.c:95:33: error: field 'capability' has incomplete type
struct video_capability capability;
Solution: For unknown reason the configure script set #define CONFIG_TV_V4L1
to 1 even if TV_V4L1 is 'no' in config.mak.
=> Change the flag in config.h or configure with --disable-tv-v4l1.

Yggdrasil
Posts: 138
Joined: Sun Aug 26, 2012 8:45 pm

Re: HOWTO: Add HEVC-Patches from LibreELEC to mplayer

Tue Aug 16, 2016 2:56 pm

The ffmpeg sources changed a bit and the above patches need a few changes. I packed all steps into a new patch file. The changed compiling instructions (testet on Raspbian+RPi3 ) are:

1) Fetch mplayer
git clone --depth 0 git://git.mplayerhq.hu/mplayer

(Or update, i.e with 'git pull origin master')

2) Configure mplayer (Just to fetch ffmpeg. The makefile clone the current ffmpeg sources if the folder ffmpeg not exists.)
cd mplayer; ./configure --disable-tv --extra-libs="-L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -lvcsm"

(Or update ffmpeg similar to mplayer.)
At this moment the commit c3c4c72665b9fbb06d8e84e6350c1148b3c55498 is the newest and was used as base.

3) Patch ffmpeg with bundle of HEVC patches

Code: Select all

cd ffmpeg
wget "https://gist.github.com/YggdrasiI/968221f97fe674a1e1adb9c21c37e69f/raw/c0fd3f2cc1689509539bd9d22004fbeb2a0cf5b1/RPI_HEVC.aug2016.patch"
patch -Np1 < RPI_HEVC.aug2016.patch
4) Extract the attachment of the first post (omx.configure) into the mplayer folder and (re-)setup ffmpeg.

Code: Select all

cd mplayer ; ./omx.configure
The config assumed that the dependenices of the omxplayer are resolved. For unmeet dependecies on your RPi, 'configure' throws an error like 'ERROR: smbclient not found'.
You could try to disable the library in omx.confgure (i.e. change enable-smbclient to disable-smbclient or remove argument) or install the depdencies (sudo apt-get install libsmbclient-dev).
The third variant would be the call of 'prepare-native-raspbian.sh' from the omxplayer repo. The script automates the depedency resolving of omxplayer and should work in our case, too.

5) — (Merged with step 2.)

6) Compile mplayer

Code: Select all

make -j4

Return to “Graphics, sound and multimedia”