-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort formats [720p codec, viewing bitrate ~2 Mbit/s] #60
base: master
Are you sure you want to change the base?
Conversation
--prefer-free-formats: Prefer video formats with free containers over non-free ones of same quality --format: Video format code --format-sort: Sort the formats by the fields given, see https://github.com/yt-dlp/yt-dlp#sorting-formats for more details
Thanks, @chapmanjacobd, for recommending sorting formats! Would appreciate your thoughts – do you think I'm on the right track? |
Looks amazing! Building on:
FYI @deldesir recommends merging this first: |
Yes, on Ubuntu 24.04 (10.8.0.26)
Perform two separate downloads: one without incorporating this pull request and another with it. Conduct a thorough comparison of the results and repeat the process with various other video URLs to effectively battle test it. |
Prefers means... what exactly in this situation: Will it occasionally download 480p or 1080p possibly?
If a video on YouTube/Vimeo offers only 2001+ kbit/s just above 2000 kbit/s — what will be downloaded? (Nothing at all?) |
Yeah I agree with holta, I think But I do know that using It would be helpful to have a couple different test videos across multiple video platforms which are most likely to be used in your use cases. Because, for example, YouTube offers many different video/audio formats but the formats are not uniform across all videos. Some data that you should track:
I think this part is the key :-) Currently, I'm using I'm interested in upstreaming any insights learned here into I don't think this will be required, but this MCDA library is quite good if you need to shave some yaks: https://gitlab.com/shekhand/mcda What I would do is create an spreadsheet with different options that you think are important and write a script that makes it easy to do a cartesian product over all the combinations and test across 3+ different video links per platform. Collectively go through the list of available formats (yt-dlp -F) and decide which one is ideal, then see which combination of options make the ideal format chosen the most number of times. |
Thank you, @chapmanjacobd, for your detailed insights and recommendations. I'll follow your suggestion to experiment with @holta, I guess I'll need to come back to you with solid answers considering all of this. Thanks for your thoughtful questions. |
@chapmanjacobd your work (xklb) is an Absolute Godsend: We will ask those using this in schools in Haiti & Beyond to recognize you for all of their lives, Thank You 🙏 |
I struggled with matching desired video format to audio format in https://github.com/tim-moody/scraper-tools/blob/master/generic/basicspider/sp_lib.py. Not sure if any of it is useful to you. I think I tried to drive off of the size resolution that I wanted. see select_480p_format, select_audio_format, select_vid_format_by_res, and select_vid_format_by_width |
4 quick excerpts from the output of
|
@tim-moody can you say a bit more about (@deldesir asked me if we're possibly looking in the wrong place! e.g. is there another link we should be looking at, alongside |
A couple more suggestions — thanks to @deldesir:
|
The functions I mentioned are all in the library I mentioned, but of course are called elsewhere. I went down the road of trying to find a syntax that gave me the right format, but I found it always had some problem with mixing video and audio. So my strategy was to get info on the video in question and then try to compute a good combination and ask for it specifically by format number. You have selected 720p, wherease I was searching for 480p, but the approach could be the same. |
The trick is to scan the available formats for the one that comes closest to the width or resolution you want, with rules to decide whether to go bigger or smaller if not found, and then find a good audio format that is also available and fits in the video container. |
Which library? Are I and @deldesir misunderstanding and looking in the wrong place? Thanks @tim-moody if you can clarify. ( |
If possible, can you clarify what line numbers on the above page are relevant to (Apologies I and @deldesir are not quite yet understanding what you are saying.) |
I guess I should mention that I import youtube_dl rather than using a cli tool. |
start reading at line 268 |
sorry. I just realized I am not talking about the main branch, but 0.2.1-wip |
It's been awhile since I worked on this. And there's code you write for yourself and code you write for others; this is the former. |
Got it! Here's a better link for @deldesir to look over if he can! |
CLARIF/RECAP:
|
This is based on this discussion and designed to download the best available format that is free (i.e webm), has a resolution of 720p, and has an average bitrate of audio and video up to 2000 kbps. It allows for flexibility by considering various formats but still prioritizes quality aspects like resolution and bitrate.
--prefer-free-formats
: Prefer video formats with free containers over non-free ones of same quality--format='best'
: This option specifies the initial format to consider. In this case, it's set to 'best', which tells yt-dlp to initially consider the best available quality for both video and audio.--format-sort='res:720,tbr~2000'
: This option instructs yt-dlp to sort the available formats based on a 720p resolution (res:720) and the average of audio and video bitrate up to 2000 kbps (tbr~2000).