I wrote an introduction to H.265 (aka HEVC) at the end of last year, including instructions showing how to encode videos to HEVC using the reference implementation. It worked but since it was not optimized for speed, it was extremely slow. Today I’ve stumbled across openHEVC, a open source compliant HEVC video decoder written in C, created as a fork of Libav. This is supposed to work pretty well as the implementation was used at Roland Garros Tennis tournament to playback an 720p50 HEVC stream transmitted over DVB-T2, IPTV, and MPEG DASH.
Today I’ll mainly tried out the instructions provided on openHEVC github repo including:
- Build the source and playing a raw HEVC stream with hevc utility
- Build GPAC (open source multimedia framework), to get MP4Box, mp42ts, and MP4Client utilities.
- Import a raw HEVC stream into MP4 and TS containers, and play it back with GPAC tools.
I’ve performed the tests below on a machine running Ubuntu 12.04 LTS.
Build and test openHEVC
I had to install one required packages on my machine, but depending on your own installation you may need more:
1 |
sudo apt-get install yasm |
The source code is available on github, let’s build it:
1 2 3 4 5 6 7 8 |
git clone git://github.com/OpenHEVC/openHEVC.git cd openHEVC git checkout hm10.0 mkdir build cd build cmake -DCMAKE_BUILD_TYPE=RELEASE .. make -j8 sudo make install |
Make install won’t install the test apps, just the libraries and header files required to build applications using openHEVC.
Before we can test openHEVC, we need to download some raw hevc streams. There are many samples in i_main, lp_main, ld_main or ra_main directory at http://ftp.kw.bbc.co.uk/hevc/hm-10.0-anchors/bitstreams/.
I’ve downloaded three with different resolutions and framerate:
1 2 3 |
wget http://ftp.kw.bbc.co.uk/hevc/hm-10.0-anchors/bitstreams/i_main/BQMall_832x480_60_qp22.bin wget http://ftp.kw.bbc.co.uk/hevc/hm-10.0-anchors/bitstreams/i_main/Cactus_1920x1080_50_qp32.bin wget http://ftp.kw.bbc.co.uk/hevc/hm-10.0-anchors/bitstreams/i_main/ChinaSpeed_1024x768_30_qp22.bin |
and played them with hevc test application in the build directory:
1 |
./hevc -i BQMall_832x480_60_qp22.bin |
This will start an SDL window, and decode the video there. All three videos could play smoothly on my system.
If you’ve built openHEVC against libSDL2 on your system, the command line would be:
1 |
./hevc_sdl2 -i BQMall_832x480_60_qp22.bin |
Build GPAC
You’ll achieve the same thing with GPAC framework, but we still need to compile it in order to generate the tools required to create MP4 and TS files with H.265 video codec.
First install the dependencies:
sudo apt-get install make pkg-config g++ zlib1g-dev firefox-dev libfreetype6-dev libjpeg62-dev libpng12-dev libopenjpeg-dev libmad0-dev libfaad-dev libogg-dev libvorbis-dev libtheora-dev liba52-0.7.4-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libxv-dev x11proto-video-dev libgl1-mesa-dev x11proto-gl-dev linux-sound-base libxvidcore-dev libssl-dev libjack-dev libasound2-dev libpulse-dev libsdl1.2-dev dvb-apps libavcodec-extra-53 libavdevice-dev libmozjs185-dev
The README instructs use to retrieve revision 4556 of GPAC, but the build failed, so I build SVN head instead:
1 2 3 4 5 |
svn checkout https://gpac.svn.sourceforge.net/svnroot/gpac/trunk gpachead cd gpachead/gpac ./configure make -j8 sudo make install |
Create MP4 and TS files with HEVC / H.265 Codec
The tools are in ./gpachead/gpac/bin/gcc/, so let’s move there, and create an MP4 video with HEVC codec:
1 2 |
cd bin/gcc ./MP4Box -v -add Cactus_1920x1080_50_qp32.bin:FMT=HEVC -fps 50 -new output.mp4 |
If the file extension is .hevc FMT=HEVC argument is not needed, in all other case you need to add this argument or MP4Box will detect the input file is corrupt. You also need to indicate the fps, which is conveniently the number right after the resolution in the filenames of BCC samples.
Now let’s play the video
1 |
./MP4Client output.mp4 |
It works. Perfect! The last step is to convert the MPE$ video into a transport stream, and play it back:
1 2 |
./mp42ts -prog=output.mp4 -dst-file=hevc.ts ./MP4Client hevc.ts |
Success as well! My CPU usage is currently quite high (150%) when playing the “cactus” video, but the code may not be fully optimized yet, although I can see files with SSE/SSE4 instructions for x86 HEVC implementation, and there are some development branches called hm10.1_simd and hm10.1_simd2. There’s no directory for arm support just yet in openHEVC, and no reference either to HEVC or H.265 in libavcodec arm directory, so for HEVC on ARM (ARMv7 with NEON and/or possibly GPGPU), you may be limited to commercial solutions for now, unless you implement your own HEVC decoder.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
Thanks a lot for this detailed tutorial!!! Nice job!!!
hello
I followed the steps when I executed make -j8 i got this error:
/home/pfet/openHEVC/libavcodec/x86/dsputil_x86.c: In function ‘ff_add_hfyu_median_prediction_cmov’:
/home/pfet/openHEVC/libavcodec/x86/dsputil_x86.c:37:5: error: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
/home/pfet/openHEVC/libavcodec/x86/dsputil_x86.c:37:5: error: ‘asm’ operand has impossible constraints
make[2]: *** [CMakeFiles/LibOpenHevcWrapper.dir/libavcodec/x86/dsputil_x86.c.o] Error 1
make[2]: *** Waiting for unfinished jobs….
make[1]: *** [CMakeFiles/LibOpenHevcWrapper.dir/all] Error 2
make: *** [all] Error 2
root@ubuntu:/home/pfet/openHEVC/build#
please if you can help me
please i have this error:
./MP4Client output.mp4
Using config file in /root directory
System info: 494 MB RAM – 1 cores
Modules Found : 35
Loading GPAC Terminal
[Thread MediaManager] Couldn’t set priority(2) for thread ID 0x00000000
[Thread MediaManager] Couldn’t set priority(2) for thread ID 0xb0b65b40
Terminal Loaded in 2153 ms
Opening URL output.mp4
Service Connected
[Codec] ODM1 ES1: Cannot find decoder for stream type MPEG-H HEVC Video
Stream Setup Failure: Media Codec not found
can you help me please
Will this work in raspberry pi model b? I have installed rasbian OS. Help me, thanks in advance.
@Vivekanandhan
No this won’t work, and it won’t build if there’s still no ARM optimization.
If ARM support has been added, you may be able to play some videos with a low resolution like 320×240 or maybe lower, and the frame rate will also be low. This needs to be tested for accurate numbers.
Thank u friend 🙂 @cnxsoft
@taheni
I am also getting the same error…. How to resolve this issue ??? kindly need help
please how can i use sdl ???