Content

Encode HEVC/H.265 stream

Encode H264/AVC

Decode HEVC and H.264 streams

Transcode from H.264/AVC to HEVC/H.265

Appendix: What’s a gain of HEVC over H.264/AVC?

 

 

First of all pls. check that your Intel GPU supports HEVC/H.265 encoding and decoding by visiting the following site:

       https://software.intel.com/en-us/articles/encode-and-decode-capabilities-for-7th-generation-intel-core-processors-and-newer

Check whether your ffmpeg supports QSV with ‘-hwaccels’ option (if not try to reconfigure and re-compile it), i get the following print :

ffmpeg -hwaccels
ffmpeg version N-91655-g7e0df5910e Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180813
configuration: –enable-gpl –enable-version3 –enable-sdl2 –enable-fontconfig –enable-gnutls –enable-iconv –enable-libass –enable-libbluray –enable-libfreetype –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libopenjpeg –enable-libopus –enable-libshine –enable-libsnappy –enable-libsoxr –enable-libtheora –enable-libtwolame –enable-libvpx –enable-libwavpack –enable-libwebp –enable-libx264 –enable-libx265 –enable-libxml2 –enable-libzimg –enable-lzma –enable-zlib –enable-gmp –enable-libvidstab –enable-libvorbis –enable-libvo-amrwbenc –enable-libmysofa –enable-libspeex –enable-libxvid –enable-libaom –enable-libmfx –enable-amf –enable-ffnvcodec –enable-cuvid –enable-d3d11va –enable-nvenc –enable-nvdec –enable-dxva2 –enable-avisynth
libavutil      56. 19.100 / 56. 19.100
libavcodec     58. 24.101 / 58. 24.101
libavformat    58. 17.103 / 58. 17.103
libavdevice    58.  4.101 / 58.  4.101
libavfilter     7. 26.100 /  7. 26.100
libswscale      5.  2.100 /  5.  2.100
libswresample   3.  2.100 /  3.  2.100
libpostproc    55.  2.100 / 55.  2.100
Hardware acceleration methods:
cuda
dxva2
qsv
d3d11va
qsv
cuvid

 

By the way you can disable printing ffmpeg banner by -hide_banner:

ffmpeg -hide_banner -hwaccels


Hardware acceleration methods:
cuda
dxva2
qsv
d3d11va
qsv
cuvid

 

 

Encode HEVC/H.265 stream

To encode HEVC/H.265 by QSV hw-encoder you need instruct ffmpeg to use hw-accelerator ‘qsv’ by ‘-hwaccel qsv’, apply HEVC hw-encoder by ‘c:v hevc_qsv’, in addition you need load  hevc plugin (see the example command line).

Input:  raw video in the format yuv420p

Target bitrate:  10 Mbps

ffmpeg  -hwaccel qsv  -s 1920×1080 -pix_fmt yuv420p  -i test420p.yuv -c:v hevc_qsv -load_plugin hevc_hw  -b 10M  -y test.h265

If encoding stuck or the following weird messages printed:

[hevc_qsv @ 000001ff451d40c0] Selected ratecontrol mode is not supported by the QSV runtime. Choose a different mode.
Error initializing output stream 0:0 — Error while opening encoder for output stream #0:0 – maybe incorrect parameters such as bit_rate, rate, width or height

try ‘ -init_hw_device qsv=hw -filter_hw_device hw ‘ , e.g.

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -v verbose -f rawvideo -video_size 1920×1080 -pix_fmt yuv420p  -i test420.yuv  -c:v hevc_qsv -load_plugin hevc_hw  -preset veryfast output.h265

Note:

  • HEVC encoding rate of 1080p on Intel Iris Plus Graphics GPU is about 100 fps

 

Encode H264/AVC

Use -c:v h264_qsv

ffmpeg -hwaccel qsv -s 1920×1080 -pix_fmt yuv420p -i  crowdrun1080p50fps.yuv -c:v h264_qsv -b 10M -y test_qsv.h264

         …

        frame= 500 fps=147 q=30.0 Lsize= 25930kB time=00:00:19.92 bitrate=10663.5kbits/s speed=5.86x

 

To get closed-gops, e.g. each gop is 50 frames use ‘-g 50 -idr_interval 0’:

ffmpeg -hwaccel qsv -s 1920×1080 -pix_fmt yuv420p -i crowd_1920x1080_50fps.yuv -c:v h264_qsv  -b:v 10M -maxrate 15M -g 50 -idr_interval 0 -y crowd_qsv.h264

Note:

  • H264 encoding rate of 1080p on Intel Iris Plus Graphics GPU is about 150 fps

 

 

Decode HEVC and H.264 streams

Example to decode 100 frames:

ffmpeg -hwaccel qsv -i test_3840×2160.h265   -pix_fmt yuv420p -vframes 100     test_3840x2160.yuv

if you get the following error (apparently you use recent version of ffmpeg):

Impossible to convert between the formats supported by the filter

Don’t panic, use ‘-vf hwdownload,format=nv12’,  bear in mind that in NV12 pixel format each frame consists of two planes: Y plane and UV plane where U and V values are interleaved, nv12 is equal in size with yuv420p. 

hevc case:  in the following  example input hevc is encapsulated in mpegts format:

ffmpeg -hwaccel qsv -i test.ts   -vf hwdownload,format=nv12    -pix_fmt yuv420p -vframes 100 -y test_384x320.yuv

 

h264 case: use ‘-vf hwdownload,format=nv12’:

ffmpeg -hwaccel qsv -i crowd.h264 -vf hwdownload,format=nv12 -pix_fmt yuv420p -vframes 400 -y crowd_1920x1080.yuv

GPU usage:

 

 

 

Transcode from H.264/AVC to HEVC/H.265

Example [transcode from h264/avc to h265/hevc with lowering the bitrate to 5Mbps]:

ffmpeg -hwaccel qsv -c:v h264_qsv -i test.h264 -c:v hevc_qsv -load_plugin hevc_hw -b 5M -y test.h265

Notice that ‘-c:v h264_qsv‘ is necessary (despite the input h264 stream is not re-encoded, it’s decoded), otherwise ffmpeg is stuck.

 

 

 

Appendix: What’s a gain of HEVC over H.264/AVC?

I often hear or read that HEVC/H.265 provides 50% (the magic number) improvement in bitrate over AVC/H.264. Perhaps, on specific scenes HEVC is better in bitrate by 50% against H264.

However, according to the technical paper written by respected researchers T. Wiegand, W.-J. Han, B. Bross, J.-R. Ohm, and G.J. Sullivan,

“High efficiency video coding (HEVC) text specification draft 7” JCTVC-I1003, improvement of HEVC against H264/AVC are more modest:

33% improvement in bit-rate without compromising video quality for random-access configuration

22% improvement in bit-rate for All-Intra configuration.

17 Responses

  1. I absolutely love your website.. Pleasant colors & theme. Did you make this web site yourself?
    Please reply back as I’m planning to create
    my own personal website and would like to know where you got this from or exactly what the theme
    is named. Thank you!

  2. After looking into a number of the blog posts on your blog, I really like your way of blogging. I added it to my bookmark site list and will be checking back in the near future. Take a look at my website too and let me know how you feel.

  3. You really make it seem really easy along with your presentation but I in finding this matter to be actually something that I think I might by no means understand. It sort of feels too complex and very huge for me. I’m having a look forward on your next put up, I will attempt to get the grasp of it!

  4. Thanx for the effort, keep up the good work Great work, I am going to start a small Blog Engine course work using your site I hope you enjoy blogging with the popular BlogEngine.net.Thethoughts you express are really awesome. Hope you will right some more posts.

  5. I haven’t checked in here for a while because I thought it was getting boring, but the last few posts are great quality so I guess I will add you back to my daily bloglist. You deserve it my friend 🙂

  6. Nice post. I study something more challenging on different blogs everyday. It should all the time be stimulating to learn content from other writers and practice just a little one thing from their store. I’d want to use some with the content material on my weblog whether or not you don’t mind. Natually I’ll give you a link in your net blog. Thanks for sharing.

  7. It?s really a cool and useful piece of info. I?m satisfied that you shared this useful information with us. Please keep us up to date like this. Thanks for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *