Play HEVC/H.265 Videos and Embed HEVC Streams into MP4 and TS Files with openHEVC and GPAC

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 an720p50 HEVC stream transmitted over DVB-T2 , IPTV, and MPEG DASH.

Today I’ll mainly tried out the instructions provided on openHEVC github repoincluding:

  • 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:

sudo apt-get install yasm

The source code is available on github, let’s build it:

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 athttp://ftp.kw.bbc.co.uk/hevc/hm-10.0-anchors/bitstreams/ .

I’ve downloaded three with different resolutions and framerate:

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:

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

If you’ve built openHEVC against libSDL2 on your system, the command line would be:

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

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:

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

./MP4Client output.mp4

It works. Perfect! The last step is to convert the MPE$ video into a transport stream, and play it back:

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章