Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Format selection should not prefer unreliable 'tbr' metadata on YouTube #14143
Comments
|
Though perhaps I should have written it all here, I have outlined further thoughts on this in a comment to #6018. However, the point i make there is most forcefully relevant to this issue, so I'm providing a direct link to that comment here. |
|
Responding to what you said in #14010:
Well, what about using the resolution instead of the bitrate? Is it ever the case that a larger stream has a lower quality? Within the same format, at least? Doesn't seem likely to me.
Not sure that's a good idea. There are actual streams with such high bitrates, and much higher. Actually, I went looking for high bitrate videos. I found IZJ48x7LsHg, which has a " |
|
Agreed (as I mentioned before: #6018 (comment)) that at least for YouTube, we should use resolution as the first indicator or metric for quality. AFAIK, YouTube never upscales video, so no concern on that the higher resolution ones could be less pristine; also, the resolution information from API is also very accurate and more reliable (compared to bitrate or filesize). But from what I gathered these years (correct me if I'm wrong), the developers acknowledged this problem and were not against the change, just lack of manpower. With that said, I think we should have at least one open issue (like this one) for this very problem, instead of keeping closing relevant issues from uninformed people or hijacking other issue (like #6018 :D). |
|
@ddawson Yes, I'm aware that my issue above isn't clear on proposing a definitive solution. First of all, as I explained here (including some 5th-grade math), bitrate should be summarily disqualified from the But besides that, referring to those tables I linked (135, 136), I had started to suspect that any "bitrate" value where the rightmost column is blank must be considered unreliable. Taken together, this means we always ignore bitrate altogether, and it's the latter signal--a blank value for the file size--that would raise the alarm bells. So from there options start to emerge. Basically, always ignore bitrate, and use reported filesize (from the rightmost column) instead, for the following two reasons:
--- or ---
I favor the latter, and it's actually quite hard to debunk. Note that this formula takes advantage of the like-duration property of the I challenge anyone to present a And do note that this proposal (and points in the footnote as well) is only proposed for the YouTube platform, as a workaround to address serious and known metadata discrepencies (as discussed) that are specific to that site. n.b. A prior argument has suggested that the current behavior won't be changed because people will never "reach a consensus... [on] quality." To this, I respectfully point out that the luxury of consensus only applies when based on reliable choice. In this case, the YouTube bug of failing to produce reliable bitrate information--nay worse, covertly providing it with falsified values--has a tangible, calamtous effect on the Nobody's personal desire when using |
|
In case anyone wants a temporary workaround for the YouTube-specific bug under discussion here, where specifying youtube_dl\extractor\common.py (1074)
Before: (current behavior)
After: (with 3-line hack shown above)
Notice that now, not only is the worst-to-best ordering is more in line with expectations, but those grossly unreliable bitrate values are also totally gone from the table listing. [edit:] But as I've tried to stress, these "close calls" in the lower-quality formats are not what the issue is about, and the way we know that is because we're discussing them with certain and reliable knowledge of the tradeoffs. Taking actual stream size as arbiter, the fact that the current code got the 133/134 order "right" (the former is 6.0% bigger) should, in truth, be considered dumb luck, since that decision was solely based on data that claimed it would be 107% bigger. In billiards, pocketing a shot doesn't count if you didn't call it. So sure, those truly ambiguous cases are the ones that would then start to get into, as I stated earlier, "the regime of fair and legitimate opinion." But the focus instead here for this issue should very clearly remain on the bug which robs us of informed choice, and what we can actually do to mitigate or remediate its effects. It may turn out that it's actually not be possible to derive any 100%-reliable predictor of anything, based on the vagaries of YouTube metadata. If that's the case then YouTubeDL's format selection policy, in order to provide maximum added value its user, should consider adopting a deliberately hostile posture towards that provider's metadata. It would be important to acknowledge this stance because the design decision calculus turn out different. For example, if one admits that neither the (133/134) nor (135/136) ranking intention will ever be corroborated with 100% reliability after download, it becomes easier to justify the informed sacrifice of the more marginal case in favor of gaining at least some degree of certainty in the case with the more visible or serious consequences. This largely matches the drastic--but not unreasonable--philosophy of fully ignoring all YouTube Most importantly, by subjugating the spurious external corruption under a conservatively re-imagined, and thus reliably predictable--albeit now necessarily probabilistic--format selection ethos, YouTubeDL can mask the long-standing problem behavior of the provider, earning for itself the added value of restoring bug-free control and predictability for its own users. |
|
Agreed.
Yes, I concur. And true to the old adage "more pixels, more better".. But one issue remains here: MP4/AVC vs. WEBM/VP9x |
|
^
WEBM tends to have worse quality than MP4, but it varies: sometimes WEBM's quality at same or even higher resolution is much worse than MP4 and the file size could be anything, other times not much worse but the file size could be anything; I've had many WEBM files where WEBM was superior in the sense the quality wasn't that much lower it would make a real difference, but the file size was smaller, but also the same happened where the file is much bigger. |
I think it's more likely that YouTube computes the reported This would explain the clustering of false/invalid |
You might be right about that. But how do you explain this one (from aforementioned IZJ48x7LsHg):
Has a stated (and accurate) filesize, but given
That's okay, I suppose. Or rather, per my example, maybe it should just be completely ignored? |
I agree 100%. |
|
As you can see in #25925, even when the actual tbr is higher, it doesn't mean the video quality is better: the codec may be more efficient. From video 'https://www.youtube.com/watch?v=iygjJ8M7jnM', format 22 tbr reportedly at 362k and 367 kb/s by ffprobe, is better than format 18 tbr reportedly at 373k and 377 kb/s by ffprobe. The former is much clearer. (just view it fullscreen!) I suggest sorting prefer dimensions than tbr / filesize, because video sites provide videos of better quality with higher (or equal) dimensions. |
Unfortunately, this might not be a solution either. Videos with larger pixel dimensions can have much lower |
|
Videos with larger pixel dimensions by definition have higher resolution, I have no idea what you're saying. Can these higher resolution versions be upscaled? Of course. But they're still "higher resolution" (and I don't think YT do up-scaling.) |
|
@fireattack Thanks, I clarified my post. And a follow-up question: Is it possible on YT for the uploading user to explicitly supply multiple source video files (corresponding to different YT formats), or does YT always generate those various available formats itself? If the former, then the uploading user might have provided up-scaled videos. But if it's the latter case, and that automatic process never up-scales, then it's true my original comment would not apply. |
Uploading multiple sources is not something YouTube provides for. If it were, then people could just upload completely different videos for different resolutions, which would be a mess for a variety of reasons. And even setting this aside, YouTube's policy is to transcode everything you upload to it, so it has control of the bitrate that viewers get (otherwise, it might be too high to be watchable on some connections), so they can be sure they're delivering satisfactory streams, even if there's something wrong with the uploaded video, etc. |
|
@ddawson thanks for that useful info. |
The "tbr" value in the YouTube JSON information, also reported in the
YouTubeDL -Foption, contains the boilerplate values 1155 (for format 135) or 2200 and 2310 (for format 136) when the bitrate is actually unknown. These special sentinal values are thus unrelated to the actual bitrate of the video and should not be interpreted as such, especially when comparing to other formats with valid bitrate values.This pattern can be seen by scrolling in the following files. which aggregate f135/f136 reports for 60,134 YouTube items. The lines are sorted by reported bitrate, and you can note the very large gaps in the rightmost "filesize" column which are sections corresponding to the singular suspicious values mentioned above. The number of files in these gap areas is too large for the corresponding value to always be exactly "1155", "2200", or "2310" by coincidence.
http://www.blobule.com/webshare/ytf-135.txt
http://www.blobule.com/webshare/ytf-136.txt
Furthermore, many of the items advertising the aforementioned values have been spot-checked after download, and thier bitrates found to be unrelated to the values shown.
YouTubeDL currently does not detect and ignore these special case values. This often causes the
-f bestvideoselection, which prioritizes higher bitrate, to erroneously choose the wrong format.Please adjust the
bestvideoformat selection heuristic so that it ignores the bitrate when these special numeric values are seen, and defers instead to a secondary mechanism, such as pixel dimension, for thebestvideodetermination.At a minimum,
bestvideoshould corroborate that its final selection is credible vis-a-vis the other candidates. For example, consider YouTube video Ot5jszj_ny8, for which youtube-dl reports the following formats:Here
-f bestvideowill download format 135, which, at 854×480, has an actual video bitrate of only 145 kb/s (according to MediaInfo), instead of format 136, which is indeed 1280×720 with a considerably better rate of 169 kb/s. Even with different compression levels, it is simply not credible that a format with 55% fewer pixels could have a bitrate 3x higher for the exact same source content.Another case, YouTube MUMlwUe-BCo was reported in #14010:
Again here, format 136 was dis-preferred by
-f bestvideo, but after downloading, the true bitrates were found to be:-f 135-f 136