Skip to content
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

[YoutubeDL] Make bestvideo+bestaudio/best default format when merger is available #5456

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"forcethumbnail": false,
"forcetitle": false,
"forceurl": false,
"format": null,
"format": "best",
"format_limit": null,
"ignoreerrors": false,
"listformats": null,
Expand Down
30 changes: 28 additions & 2 deletions youtube_dl/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,11 @@ def process_video_result(self, info_dict, download=True):

req_format = self.params.get('format')
if req_format is None:
req_format = 'best'
req_format_list = []
if info_dict['extractor'] == 'youtube' and FFmpegMergerPP(self).available:
req_format_list.append('bestvideo+bestaudio')
req_format_list.append('best')
req_format = '/'.join(req_format_list)
formats_to_download = []
if req_format == 'all':
formats_to_download = formats
Expand Down Expand Up @@ -1369,7 +1373,29 @@ def dl(name, info):
' The formats won\'t be merged')
else:
postprocessors = [merger]
for f in info_dict['requested_formats']:

def compatible_formats(formats):
video, audio = formats
# Check extension
video_ext, audio_ext = audio.get('ext'), video.get('ext')
if video_ext and audio_ext:
COMPATIBLE_EXTS = (
('mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v'),
('webm')
)
for exts in COMPATIBLE_EXTS:
if video_ext in exts and audio_ext in exts:
return True
# TODO: Check acodec/vcodec
return False

requested_formats = info_dict['requested_formats']
# Merge incompatible formats into mkv
if not compatible_formats(requested_formats):
filename = os.path.splitext(filename)[0] + '.mkv'
self.report_warning('You have requested formats uncompatible for merge. '
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since bestvideo+bestaudio/best will be the default, maybe it's better to use to_screen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Uncompatible formats scenario is still expected to happen less often that compatible and can be treated as reasonable-to-warn-about.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it's fine.

'The formats will be merged into mkv')
for f in requested_formats:
new_info = dict(info_dict)
new_info.update(f)
fname = self.prepare_filename(new_info)
Expand Down