Video Compression

VideoNerd

Content

Sanity Checks

Encoding

HEVC Encode

                     H264 Encode

Transcoding

           Decoding

 

 

Sanity Checks

First of all you need check that ffmpeg supports nvenc (access to nvidia hw encoder), you merely type ‘ffmpeg’ in the command line and check --enable-nvenc is present in the configuration list:

ffmpeg

ffmpeg version git-2020-07-21-b5f1e05 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3.1 (GCC) 20200621
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --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-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf

 

Encoding

HEVC Encode

Run ffmpeg hevc hw-encoding, here ‘-preset 6’ means ultra-fast mode (the encoding speed is above 200 fps for 1080p), for veryslow mode use ‘-preset 1’ (the encoding speed is around 100fps for 1080p)

ffmpeg -hide_banner -y -vsync 0 -s 1920×1080 -i test1080p.yuv  -c:v hevc_nvenc -preset 6 -b:v 2M output.h265

[rawvideo @ 00000280fac1e580] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from ‘.\yuv\Fifa20_1.yuv’:
Duration: 00:00:26.24, start: 0.000000, bitrate: 622080 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920×1080, 622080 kb/s, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (hevc_nvenc))
Press [q] to stop, [?] for help
Output #0, hevc, to ‘output.h265’:
Metadata:
encoder         : Lavf58.49.100
Stream #0:0: Video: hevc (hevc_nvenc) (Main), yuv420p, 1920×1080, q=-1–1, 2000 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder         : Lavc58.97.100 hevc_nvenc
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: N/A
frame=  656 fps=212 q=30.0 Lsize=    5963kB time=00:00:26.24 bitrate=1861.5kbits/s speed=8.47x

video:5963kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

 

 

If you get the following error, don’t panic, simply your ffmpeg is ahead of your nvidia driver, you need install recent nvidia driver:

[h264_nvenc @ 00000203f3b50980] Driver does not support the required nvenc API version. Required: 11.1 Found: 11.0
[h264_nvenc @ 00000203f3b50980] The minimum required Nvidia driver for nvenc is 471.41 or newer
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

 

Note: for low-latency encoding set ‘-bf 0’ (no B frames, IPPP GOP structure) and ‘-rc-lookahead 0′ (i.e. no look-ahead analysis):

ffmpeg -y -vsync 0 -i crowd_run_1080p50.y4m -c:v hevc_nvenc -preset 6 -profile:v main -b:v 5M -bufsize 5M -maxrate 10M -qmin 0 -g 50 -bf 0 -temporal-aq 1 -rc-lookahead 0 -i_qfactor 0.75 -b_qfactor 1.1 crowd_run_1080p5Mbps.h265

 

 

 

H264 Encoding

use h264_nvenc to instruct ffmpeg to activate hw nvidia encoder

ffmpeg -y -vsync 0 -i .\yuv\crowd_run_1080p50.y4m -c:v h264_nvenc -preset slow -profile:v high -b:v 5M -bufsize 5M -maxrate 10M -qmin 0 -g 50 -bf 2 -temporal-aq 1 -rc-lookahead 5 -i_qfactor 0.75 -b_qfactor 1.1 crowd_run_1080p5Mbps.mp4

 

Notes:

  • encoding rate is reported 122 fps for 1080p for preset ‘slow’

 

  • ‘bf 2’ two B frames between I/P frames

 

  • ‘i_qfactor 0.75’ means QPs of I frames are by 0.75 factor less than those of previous P frame, i.e. QP_i = 0.75 * QP_p, finer quantization of I-frames relative to P frames.

 

  • ‘b_qfactor 1.1’ means QPs of B frames are by 1.1 factor greater than that of previous P frame, i.e. QP_b = 1.1 * QP_p, coarser quantization of B frames relative to P frames

 

  •  for low-latency encoding set ‘-bf 0’ (no B frames, IPPP GOP structure) and ‘-rc-lookahead 0′ (i.e. no look-ahead analysis):

ffmpeg -y -vsync 0 -i crowd_run_1080p50.y4m -c:v h264_nvenc -preset slow -profile:v high -b:v 5M -bufsize 5M -maxrate 10M -qmin 0 -g 50 -bf 0 -temporal-aq 1 -rc-lookahead 0 -i_qfactor 0.75 -b_qfactor 1.1 crowd_run_1080p5Mbps.mp4

 

Notes:

    for low-latency it’s recommended to set ‘-bufsize  BITRATE/FRAME_RATE’, if the bitrate is 5Mbps and the frame is 60fps then ‘-bufsize 83K’ , i.e. 83 Kbits.

    for high quality it’s recommended to ‘-bufsize  2xBitrate’

 

Transcoding

Note: using ‘-hwaccel cuvid’ does not activate 3D, rather hw video encoder and hw decoder:

Transcoding input h264 file to hevc mp4:

Configuration

  • near constant bitrate 5Mbps (-b:v 5M  -maxrate 5M)
  • GOP size = 60 frames (-g 60)
  • two B frames between I/P frames (-bf 2)
  • lookahead 20 frames (not for low latency, -rc-lookahead 20)

 

Results of transcoding rate for 1080p is about 286 fps:

ffmpeg -y -hide_banner -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i crowd.h264 -c:v hevc_nvenc -preset medium -b:v 5M -bufsize 5M -maxrate 5M -qmin 0 -g 60 -bf 2 -temporal-aq 1 -rc-lookahead 20 -i_qfactor 0.75 -b_qfactor 1.1 crowd_hw.mp4

Input #0, h264, from ‘crowd.h264‘:
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920×1080 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 1200k tbn
Stream mapping:
Stream #0:0 -> #0:0 (h264 (h264_cuvid) -> hevc (hevc_nvenc))
Press [q] to stop, [?] for help
Output #0, mp4, to ‘crowd_hw.mp4’:
Metadata:
encoder : Lavf59.8.100
Stream #0:0: Video: hevc (Main) (hev1 / 0x31766568), cuda(tv, progressive), 1920×1080 [SAR 1:1 DAR 16:9], q=2-31, 5000 kb/s, 50 fps, 12800 tbn
Metadata:
encoder : Lavc59.12.100 hevc_nvenc
Side data:
cpb: bitrate max/min/avg: 5000000/0/5000000 buffer size: 5000000 vbv_delay: N/A
frame= 500 fps=286 q=38.0 Lsize= 6317kB time=00:00:09.94 bitrate=5205.7kbits/s speed=5.68x
video:6311kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.089999%

 

Notes:

  • -hwaccel cuvid -c:v h264_cuvid  :  activate hw decoder
  • -c:v hevc_nvenc  : activate hw hevc encoder (to activate h264 hw encoder use h264_nvenc)

 

 

Decoding

To decode hevc stream to yuv420p format use ‘-c:v hevc_cuvid‘ and ‘-pix_fmt yuv420p‘ as in the following example:

ffmpeg -y -hide_banner -vsync 0 -c:v hevc_cuvid -i crowd_run_1080p5Mbps.h265 -pix_fmt yuv420p   crowd1080p.yuv

 

for verification run the output yuv-sequence with ffplay (by default the pixel format of ‘ffplay’ is yuv420p):

ffplay -video_size 1920×1080 -i crowd1080p.yuv

 

Notes:

  •        to decode h264 use ‘-c:v h264_cuvid’ , example  – decoding 200 frames from h264 file:

ffmpeg -y -hide_banner -vsync 0 -c:v h264_cuvid -i test.h264 -frames 200 -pix_fmt yuv420p test.yuv

 

  • ‘-vsync 0’ is essential, otherwise some frame might be discarded

196 Responses

  1. Pretty section of content. I just stumbled upon your site and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently rapidly.

  2. Great V I should definitely pronounce, impressed with your site. I had no trouble navigating through all tabs and related info ended up being truly simple to do to access. I recently found what I hoped for before you know it in the least. Quite unusual. Is likely to appreciate it for those who add forums or anything, website theme . a tones way for your client to communicate. Excellent task..

  3. I’ve been absent for some time, but now I remember why I used to love this blog. Thank you, I will try and check back more often. How frequently you update your site?

  4. Wow, fantastic blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is magnificent, let alone the content!

  5. It’s appropriate time to make some plans for the future and it’s time to be happy. I have read this post and if I could I wish to suggest you some interesting things or advice. Maybe you can write next articles referring to this article. I want to read even more things about it!

  6. Hiya, I am really glad I’ve found this information. Nowadays bloggers publish just about gossips and web and this is really annoying. A good web site with exciting content, this is what I need. Thanks for keeping this website, I’ll be visiting it. Do you do newsletters? Cant find it.

    1. Specialists are not motivated to share technical information, only few enthusiasts like me invest time and money to share info FREE for a wider audience

  7. Thanks for these guidelines. One thing I also believe is credit cards providing a 0 apr often lure consumers with zero rate, instant approval and easy over-the-internet balance transfers, nevertheless beware of the main factor that can void that 0 easy neighborhood annual percentage rate and also throw one out into the very poor house rapidly.

  8. Simply wish to say your article is as amazing. The clarity in your publish is just nice and that i can assume you are an expert in this subject. Well with your permission let me to take hold of your feed to keep up to date with imminent post. Thank you a million and please keep up the rewarding work.

  9. Thanks for sharing superb informations. Your website is so cool. I am impressed by the details that you have on this site. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for extra articles. You, my friend, ROCK! I found just the information I already searched everywhere and simply could not come across. What an ideal web-site.

  10. Thanks for your post on this blog site. From my personal experience, many times softening upwards a photograph could possibly provide the photography with a dose of an creative flare. Often however, this soft blur isn’t precisely what you had under consideration and can usually spoil an otherwise good photo, especially if you intend on enlarging it.

  11. Nice read, I just passed this onto a colleague who was doing some research on that. And he actually bought me lunch since I found it for him smile Thus let me rephrase that: Thanks for lunch!

  12. Hiya, I am really glad I’ve found this information. Nowadays bloggers publish just about gossips and web and this is actually frustrating. A good blog with exciting content, this is what I need. Thanks for keeping this website, I will be visiting it. Do you do newsletters? Can’t find it.

  13. There are some attention-grabbing deadlines on this article but I don?t know if I see all of them center to heart. There may be some validity but I will take maintain opinion till I look into it further. Good article , thanks and we want extra! Added to FeedBurner as nicely

  14. I cherished as much as you will receive carried out proper here. The comic strip is attractive, your authored material stylish. nevertheless, you command get got an shakiness over that you wish be delivering the following. sick definitely come further formerly once more since exactly the similar nearly a lot often within case you defend this hike.

  15. Youre so cool! I dont suppose Ive learn anything like this before. So nice to search out any individual with some authentic thoughts on this subject. realy thank you for starting this up. this web site is one thing that is needed on the net, someone with just a little originality. useful job for bringing one thing new to the web!

  16. Hey there, You’ve done an incredible job. I will certainly digg it and personally recommend to my friends. I am sure they will be benefited from this site.

  17. Wow, marvelous blog layout! How long have you been blogging for? you make running a blog look easy. The full glance of your web site is great, as well as the content material!

  18. Wow! This could be one particular of the most helpful blogs We’ve ever arrive across on this subject. Basically Excellent. I’m also a specialist in this topic so I can understand your effort.

  19. This is really interesting, You are a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your wonderful post. Also, I’ve shared your website in my social networks!

  20. Normally I do not read article on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very nice post.

  21. Simply desire to say your article is as astonishing. The clarity for your publish is simply cool and i can assume you’re an expert in this subject. Fine with your permission allow me to take hold of your RSS feed to keep up to date with drawing close post. Thank you a million and please carry on the enjoyable work.

  22. What?s Happening i am new to this, I stumbled upon this I’ve found It positively useful and it has helped me out loads. I hope to contribute & assist other users like its aided me. Great job.

  23. Thank you for another informative website. The place else may just I am getting that type of info written in such an ideal approach? I’ve a mission that I’m just now running on, and I have been at the glance out for such info.

  24. The following time I learn a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my option to learn, but I really thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

  25. It’s the best time to make some plans for the future and it’s time to be happy. I have read this post and if I could I want to suggest you some interesting things or advice. Perhaps you can write next articles referring to this article. I want to read even more things about it!

  26. Wow! This could be one particular of the most helpful blogs We have ever arrive across on this subject. Actually Magnificent. I’m also an expert in this topic therefore I can understand your hard work.

  27. I do agree with all the ideas you’ve presented in your post. They are really convincing and will definitely work. Still, the posts are very short for novices. Could you please extend them a little from next time? Thanks for the post.

  28. One more issue is really that video gaming has become one of the all-time most important forms of fun for people of every age group. Kids participate in video games, and also adults do, too. The actual XBox 360 has become the favorite gaming systems for individuals that love to have hundreds of activities available to them, as well as who like to play live with others all over the world. Many thanks for sharing your notions.

  29. magnificent publish, very informative. I ponder why the opposite specialists of this sector don’t notice this. You must proceed your writing. I’m sure, you’ve a huge readers’ base already!

  30. I will right away grab your rss feed as I can not find your e-mail subscription link or newsletter service. Do you have any? Kindly allow me recognise so that I may just subscribe. Thanks.

  31. I believe this is among the so much significant information for me. And i am happy reading your article. But want to commentary on few common issues, The web site style is great, the articles is in reality nice : D. Excellent job, cheers

  32. I have mastered some considerations through your blog post post. One other point I would like to convey is that there are many games that you can buy which are designed particularly for toddler age small children. They consist of pattern identification, colors, animals, and shapes. These typically focus on familiarization in lieu of memorization. This helps to keep a child occupied without having the experience like they are learning. Thanks

  33. I will immediately take hold of your rss as I can not to find your e-mail subscription link or newsletter service. Do you’ve any? Kindly let me recognize so that I may just subscribe. Thanks.

  34. Thank you for another informative blog. The place else may just I am getting that kind of info written in such a perfect method? I have a venture that I’m simply now running on, and I’ve been at the glance out for such info.

  35. Good post. I study one thing tougher on completely different blogs everyday. It will at all times be stimulating to learn content from different writers and apply just a little something from their store. I?d favor to make use of some with the content on my weblog whether you don?t mind. Natually I?ll provide you with a link in your internet blog. Thanks for sharing.

  36. Very great post. I just stumbled upon your blog and wanted to say that I’ve really enjoyed surfing around your blog posts. After all I?ll be subscribing in your feed and I’m hoping you write again very soon!

  37. I have seen loads of useful elements on your web page about pc’s. However, I have the judgment that laptops are still more or less not powerful adequately to be a good choice if you frequently do tasks that require a great deal of power, for instance video editing and enhancing. But for world wide web surfing, microsoft word processing, and a lot other prevalent computer work they are okay, provided you don’t mind small screen size. Thank you sharing your ideas.

  38. I am extremely impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, it is rare to see a nice blog like this one these days..

  39. Its like you read my mind! You appear to grasp so much approximately this, such as you wrote the ebook in it or something. I feel that you simply can do with some percent to drive the message house a little bit, but instead of that, that is great blog. A great read. I’ll definitely be back.

  40. I do accept as true with all the concepts you’ve introduced on your post. They’re really convincing and can definitely work. Still, the posts are very short for novices. May you please lengthen them a little from subsequent time? Thank you for the post.

  41. whoah this blog is excellent i really like studying your posts. Stay up the great work! You recognize, a lot of persons are hunting round for this info, you could aid them greatly.

  42. Great blog right here! Additionally your site so much up fast! What web host are you the use of? Can I am getting your affiliate hyperlink for your host? I want my web site loaded up as fast as yours lol

  43. Great post. I was checking continuously this blog and I am impressed! Extremely helpful information particularly the last part 🙂 I care for such info a lot. I was looking for this certain information for a long time. Thank you and best of luck.

  44. I’m really inspired along with your writing abilities and also with the format for your weblog. Is this a paid topic or did you customize it yourself? Anyway stay up the excellent high quality writing, it?s uncommon to peer a nice blog like this one today..

  45. Thanks for sharing superb informations. Your web site is so cool. I am impressed by the details that you have on this blog. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my pal, ROCK! I found just the info I already searched all over the place and simply could not come across. What a great web site.

  46. Excellent goods from you, man. I’ve remember your stuff previous to and you are simply too wonderful. I really like what you have got right here, really like what you are saying and the best way during which you are saying it. You are making it entertaining and you still care for to stay it smart. I cant wait to learn much more from you. This is actually a tremendous site.

  47. I would also like to add when you do not currently have an insurance policy or else you do not belong to any group insurance, chances are you’ll well gain from seeking assistance from a health insurance broker. Self-employed or people having medical conditions typically seek the help of one health insurance brokerage service. Thanks for your short article.

  48. I have realized that online education is getting preferred because accomplishing your college degree online has changed into a popular solution for many people. Quite a few people have not necessarily had a possible opportunity to attend a conventional college or university nevertheless seek the elevated earning possibilities and career advancement that a Bachelor Degree provides. Still other people might have a qualification in one field but would want to pursue another thing they now have an interest in.

  49. Someone essentially help to make seriously posts I would state. This is the first time I frequented your web page and thus far? I amazed with the research you made to create this particular publish incredible. Excellent job!

  50. Hey there, You’ve done a great job. I?ll certainly digg it and personally recommend to my friends. I am confident they’ll be benefited from this site.

  51. We are a gaggle of volunteers and opening a new scheme in our community. Your website offered us with helpful info to work on. You have done a formidable task and our entire community will likely be grateful to you.

  52. I do not even understand how I stopped up right here, but I believed this submit was great. I do not recognise who you might be but definitely you are going to a well-known blogger if you happen to aren’t already 😉 Cheers!

  53. Hello very nice site!! Guy .. Excellent .. Wonderful .. I’ll bookmark your site and take the feeds additionally?I’m happy to seek out a lot of helpful info right here in the put up, we need develop more techniques on this regard, thanks for sharing. . . . . .

  54. I?m impressed, I have to say. Actually rarely do I encounter a weblog that?s each educative and entertaining, and let me inform you, you’ve gotten hit the nail on the head. Your idea is excellent; the issue is something that not sufficient persons are talking intelligently about. I’m very completely satisfied that I stumbled across this in my seek for one thing referring to this.

  55. Hello, you used to write great, but the last few posts have been kinda boring? I miss your tremendous writings. Past few posts are just a little bit out of track! come on!

  56. Its like you learn my mind! You seem to grasp so much approximately this, such as you wrote the book in it or something. I feel that you simply can do with some percent to force the message home a little bit, but other than that, that is wonderful blog. A great read. I will definitely be back.

  57. I have seen loads of useful things on your web site about desktops. However, I’ve got the thoughts and opinions that laptops are still more or less not powerful more than enough to be a good choice if you normally do jobs that require lots of power, just like video modifying. But for website surfing, word processing, and most other prevalent computer work they are perfectly, provided you can’t mind the little screen size. Many thanks sharing your opinions.

  58. Hi there, just became alert to your blog through Google, and found that it’s truly informative. I am going to watch out for brussels. I?ll be grateful if you continue this in future. A lot of people will be benefited from your writing. Cheers!

  59. Great post. I was checking continuously this blog and I am inspired! Extremely helpful information specifically the final section 🙂 I care for such info much. I used to be seeking this particular information for a very long time. Thank you and good luck.

  60. whoah this weblog is wonderful i like reading your articles. Keep up the good work! You understand, lots of persons are looking around for this info, you could aid them greatly.

  61. Attractive part of content. I just stumbled upon your weblog and in accession capital to say that I get in fact loved account your weblog posts. Anyway I will be subscribing for your augment and even I success you get right of entry to consistently quickly.

  62. Thanks for revealing your ideas. Another thing is that individuals have a selection between government student loan and a private education loan where it’s easier to opt for student loan consolidating debts than with the federal student loan.

  63. Oh my goodness! a tremendous article dude. Thank you However I am experiencing concern with ur rss . Don?t know why Unable to subscribe to it. Is there anybody getting an identical rss problem? Anybody who knows kindly respond. Thnkx

  64. Great post. I was checking continuously this blog and I am impressed! Very useful info specifically the last part 🙂 I care for such info a lot. I was looking for this certain information for a very long time. Thank you and good luck.

  65. As I site possessor I believe the content matter here is rattling magnificent , appreciate it for your hard work. You should keep it up forever! Good Luck.

  66. I?ve been exploring for a little bit for any high-quality articles or weblog posts on this sort of space . Exploring in Yahoo I at last stumbled upon this web site. Studying this info So i am happy to show that I have a very good uncanny feeling I found out just what I needed. I such a lot unquestionably will make sure to don?t disregard this web site and give it a look on a relentless basis.

  67. Hiya! I just wish to give an enormous thumbs up for the good data you will have here on this post. I will probably be coming back to your blog for more soon.

  68. I cherished as much as you will receive carried out proper here. The caricature is attractive, your authored subject matter stylish. nevertheless, you command get bought an edginess over that you want be delivering the following. sick indubitably come further previously once more as exactly the same just about very ceaselessly within case you shield this increase.

  69. I used to be very happy to find this internet-site.I wished to thanks in your time for this excellent learn!! I undoubtedly having fun with each little little bit of it and I’ve you bookmarked to check out new stuff you blog post.

Leave a Reply

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