Home > Linux, Testing, Ubuntu, Video > Play HEVC/H.265 Videos and Embed HEVC Streams into MP4 and TS Files with openHEVC and GPAC

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

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

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:

and played them with hevc test application in the build directory:

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:

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:

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:

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

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

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.

  1. Ernesto
    March 25th, 2014 at 06:42 | #1

    Thanks a lot for this detailed tutorial!!! Nice job!!!

  2. taheni
    April 2nd, 2014 at 23:09 | #2

    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
    [email protected]:/home/pfet/openHEVC/build#

    please if you can help me

  3. taheni
    April 3rd, 2014 at 21:23 | #3

    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

  4. April 19th, 2014 at 17:59 | #4

    Will this work in raspberry pi model b? I have installed rasbian OS. Help me, thanks in advance.

  5. April 19th, 2014 at 19:58 | #5

    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.

  6. April 20th, 2014 at 14:42 | #6

    Thank u friend 🙂 @cnxsoft

  7. waqas
    April 23rd, 2014 at 18:39 | #7

    I am also getting the same error…. How to resolve this issue ??? kindly need help

  8. misouu
    June 27th, 2014 at 19:48 | #8

    please how can i use sdl ???

  1. No trackbacks yet.