Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Unread 11th April 2022, 13:06   #1  |  Link
ZeB
The man
 
Join Date: Oct 2001
Location: Sweden
Posts: 25
Quote:
Originally Posted by FranceBB View Post
What's important here is not just the keyint = framerate and the reference frame set to 4, but also the --aud, so the unit access delimiters which might play a role.
I did some testing and the number of ref frames seems to be the problem. Default is 16.

My command line:
ffmpeg.exe -i "input.avs" -c:v libx264 -profile:v high -bf 2 -g 25 -refs X -preset veryslow -crf 18 -pix_fmt yuv420p -movflags faststart "output.mp4"

I just changed the number of ref frames.

15 ref frames, corruption:
https://youtu.be/ul4BkEtCtps

14 ref frames, corruption:
https://youtu.be/QLBlqoV6KxY

13 ref frames, corruption:
https://youtu.be/JarNcaMm5n0

12 ref frames, no corruption:
https://youtu.be/kHEHzIIWQ2g

So it seems like the h264 decoder that Youtube uses has problems with a higher number of ref frames. Isn't that weird, I would guess that they would use I high "quality" decoder? Can it be because of performance? I lower quality decoder can be faster?

Thank you for your help!
ZeB is offline   Reply With Quote
Unread 11th April 2022, 15:01   #2  |  Link
rwill
Registered User
 
Join Date: Dec 2013
Posts: 148
Quote:
Originally Posted by ZeB View Post
I did some testing and the number of ref frames seems to be the problem.
------
13 ref frames, corruption:
------
12 ref frames, no corruption:
------
So it seems like the h264 decoder that Youtube uses has problems with a higher number of ref frames. Isn't that weird, I would guess that they would use I high "quality" decoder? Can it be because of performance? I lower quality decoder can be faster?
Well, 2560x1440 has 14400 Macroblocks.

H.264 Level 5.2 supports a decoded picture buffer size of up to 184320 Macroblocks, so at your resolution 12.8 ref pictures.

The next level (6.0) supports a DPB of 696320 ( so 48.35 ref pictures of your resolution ).

Maybe your stream does not have the correct level set ? Or youtubes H.264 decoder initializes at Level 5.2 for whatever reason ? I don't know if they are using hardware or software decode - a hardware decoder could explain such behavior.
rwill is offline   Reply With Quote
Unread 12th April 2022, 09:01   #3  |  Link
ZeB
The man
 
Join Date: Oct 2001
Location: Sweden
Posts: 25
Quote:
Originally Posted by rwill View Post
Well, 2560x1440 has 14400 Macroblocks.

H.264 Level 5.2 supports a decoded picture buffer size of up to 184320 Macroblocks, so at your resolution 12.8 ref pictures.

The next level (6.0) supports a DPB of 696320 ( so 48.35 ref pictures of your resolution ).

Maybe your stream does not have the correct level set ? Or youtubes H.264 decoder initializes at Level 5.2 for whatever reason ? I don't know if they are using hardware or software decode - a hardware decoder could explain such behavior.
That makes a lot of sense. The encode reports as "High@L6" in Mediainfo. So the stream is correct, right?

I guess that level 5.2 (12 ref frames) is the maximum recommended when encoding for Youtube.

Command line:
ffmpeg.exe -i "input.avs" -c:v libx264 -profile:v high -level:v 5.2 -bf 2 -g 25 -preset veryslow -crf 18 -pix_fmt yuv420p -movflags faststart "output.mp4"

This works without any corruption.

No mentions of levels in their own guide, just profile "high":
https://support.google.com/youtube/answer/1722171

Quote:
Originally Posted by benwaggoner View Post
You don't want to exceed the number of reference frames for your profile, level, and frame size listed here: https://en.wikipedia.org/wiki/Advanc..._Coding#Levels. Level 4.2 is generally quite safe to use these days. As said, if you want to go above 1080p, I'd suggest using x265 and HEVC.
If using x265, what settings is recommended? When searching information everyone just seems to recommend h264 instead. Youtube also recommends h264 in the "official" guide. It just mentions that h265 is supported.
ZeB is offline   Reply With Quote
Unread 12th April 2022, 10:29   #4  |  Link
rwill
Registered User
 
Join Date: Dec 2013
Posts: 148
Quote:
Originally Posted by ZeB View Post
That makes a lot of sense. The encode reports as "High@L6" in Mediainfo. So the stream is correct, right?

I guess that level 5.2 (12 ref frames) is the maximum recommended when encoding for Youtube.

Command line:
ffmpeg.exe -i "input.avs" -c:v libx264 -profile:v high -level:v 5.2 -bf 2 -g 25 -preset veryslow -crf 18 -pix_fmt yuv420p -movflags faststart "output.mp4"

This works without any corruption.

No mentions of levels in their own guide, just profile "high":
https://support.google.com/youtube/answer/1722171



If using x265, what settings is recommended? When searching information everyone just seems to recommend h264 instead. Youtube also recommends h264 in the "official" guide. It just mentions that h265 is supported.

Regarding the level the stream is correct then.

However if you look at the evolution of the H.264 standard here:

https://www.itu.int/itu-t/recommenda...aspx?rec=14659

in appendix A, Table A-1, the level limits...

H.264 (V10) (02/2016) does not list a level higher than 5.2, like, there is no level 6.0 or higher.
H.264 (V11) (10/2016) does list level 6 and higher.

So higher resolutions and higher DPB sizes got first added in October 2016.

So maybe decoders done before ~10/2016 are somewhat untested with Levels limits above 5.2, who knows.

I wonder what would happen if one uploads some crafted 1440p video which uses 16 ref frames and then only references ref frames whose size exceed the level 5.2 limits to youtube. Maybe one would be able to dump some hardware reserved memory of the youtube server ? maybe the job crashes the youtube decoder and breaks something ? I am eager to find out but at the same time am somewhat scared that Youtube might get grumpy when messing with their setup.

For x265 I'd just use "-preset slow" or slower and "-tune ssim" with some nice high bitrate or low crf. Oh and I'd specify a level. Maybe Level 5 High Tier like some UHD Bluray ?
rwill is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:21.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.