Content
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:
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.
23+ years’ programming and theoretical experience in the computer science fields such as video compression, media streaming and artificial intelligence (co-author of several papers and patents).
the author is looking for new job, my resume
I consider something really special in this website .
You made certain nice points there. I did a search on the matter and found most persons will agree with your blog.
This is a topic that’s near to my heart… Best wishes! Exactly where are your contact details though?
You are my intake, I have few blogs and rarely run out from to post : (.
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!
i am responsible for the content, Ivan Lukin is our web-designer and you are welcome to speak to him: vanyalukin007@gmail.com
Hey, thanks for the blog post.Really thank you! Really Great.
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.
Dear Isidra Gabor
Sorry for a silly question, maybe you a relative to Dennis Gabor (an inventor of Gabor Filters)?
It’s in reality a nice and useful piece of info. I am glad that you simply shared this useful information with us. Please stay us informed like this. Thank you for sharing.
I couldn’t resist commenting
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!
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.
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 🙂
I have been absent for a while, but now I remember why I used to love this web site. Thanks , I¦ll try and check back more frequently. How frequently you update your website?
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.
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.