mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-11-13 13:05:13 +00:00
[fd/ffmpeg] Apply ffmpeg_args for each format (#14886)
Also remove support for the deprecated format fields `_ffmpeg_args` and `_seekable` Closes #14877 Authored by: bashonly
This commit is contained in:
@@ -488,20 +488,6 @@ class FFmpegFD(ExternalFD):
|
|||||||
if not self.params.get('verbose'):
|
if not self.params.get('verbose'):
|
||||||
args += ['-hide_banner']
|
args += ['-hide_banner']
|
||||||
|
|
||||||
args += traverse_obj(info_dict, ('downloader_options', 'ffmpeg_args', ...))
|
|
||||||
|
|
||||||
# These exists only for compatibility. Extractors should use
|
|
||||||
# info_dict['downloader_options']['ffmpeg_args'] instead
|
|
||||||
args += info_dict.get('_ffmpeg_args') or []
|
|
||||||
seekable = info_dict.get('_seekable')
|
|
||||||
if seekable is not None:
|
|
||||||
# setting -seekable prevents ffmpeg from guessing if the server
|
|
||||||
# supports seeking(by adding the header `Range: bytes=0-`), which
|
|
||||||
# can cause problems in some cases
|
|
||||||
# https://github.com/ytdl-org/youtube-dl/issues/11800#issuecomment-275037127
|
|
||||||
# http://trac.ffmpeg.org/ticket/6125#comment:10
|
|
||||||
args += ['-seekable', '1' if seekable else '0']
|
|
||||||
|
|
||||||
env = None
|
env = None
|
||||||
proxy = self.params.get('proxy')
|
proxy = self.params.get('proxy')
|
||||||
if proxy:
|
if proxy:
|
||||||
@@ -521,17 +507,39 @@ class FFmpegFD(ExternalFD):
|
|||||||
env['HTTP_PROXY'] = proxy
|
env['HTTP_PROXY'] = proxy
|
||||||
env['http_proxy'] = proxy
|
env['http_proxy'] = proxy
|
||||||
|
|
||||||
protocol = info_dict.get('protocol')
|
start_time, end_time = info_dict.get('section_start') or 0, info_dict.get('section_end')
|
||||||
|
|
||||||
|
fallback_input_args = traverse_obj(info_dict, ('downloader_options', 'ffmpeg_args', ...))
|
||||||
|
|
||||||
|
selected_formats = info_dict.get('requested_formats') or [info_dict]
|
||||||
|
for i, fmt in enumerate(selected_formats):
|
||||||
|
is_http = re.match(r'https?://', fmt['url'])
|
||||||
|
cookies = self.ydl.cookiejar.get_cookies_for_url(fmt['url']) if is_http else []
|
||||||
|
if cookies:
|
||||||
|
args.extend(['-cookies', ''.join(
|
||||||
|
f'{cookie.name}={cookie.value}; path={cookie.path}; domain={cookie.domain};\r\n'
|
||||||
|
for cookie in cookies)])
|
||||||
|
if fmt.get('http_headers') and is_http:
|
||||||
|
# Trailing \r\n after each HTTP header is important to prevent warning from ffmpeg:
|
||||||
|
# [http @ 00000000003d2fa0] No trailing CRLF found in HTTP header.
|
||||||
|
args.extend(['-headers', ''.join(f'{key}: {val}\r\n' for key, val in fmt['http_headers'].items())])
|
||||||
|
|
||||||
|
if start_time:
|
||||||
|
args += ['-ss', str(start_time)]
|
||||||
|
if end_time:
|
||||||
|
args += ['-t', str(end_time - start_time)]
|
||||||
|
|
||||||
|
protocol = fmt.get('protocol')
|
||||||
|
|
||||||
if protocol == 'rtmp':
|
if protocol == 'rtmp':
|
||||||
player_url = info_dict.get('player_url')
|
player_url = fmt.get('player_url')
|
||||||
page_url = info_dict.get('page_url')
|
page_url = fmt.get('page_url')
|
||||||
app = info_dict.get('app')
|
app = fmt.get('app')
|
||||||
play_path = info_dict.get('play_path')
|
play_path = fmt.get('play_path')
|
||||||
tc_url = info_dict.get('tc_url')
|
tc_url = fmt.get('tc_url')
|
||||||
flash_version = info_dict.get('flash_version')
|
flash_version = fmt.get('flash_version')
|
||||||
live = info_dict.get('rtmp_live', False)
|
live = fmt.get('rtmp_live', False)
|
||||||
conn = info_dict.get('rtmp_conn')
|
conn = fmt.get('rtmp_conn')
|
||||||
if player_url is not None:
|
if player_url is not None:
|
||||||
args += ['-rtmp_swfverify', player_url]
|
args += ['-rtmp_swfverify', player_url]
|
||||||
if page_url is not None:
|
if page_url is not None:
|
||||||
@@ -552,26 +560,6 @@ class FFmpegFD(ExternalFD):
|
|||||||
elif isinstance(conn, str):
|
elif isinstance(conn, str):
|
||||||
args += ['-rtmp_conn', conn]
|
args += ['-rtmp_conn', conn]
|
||||||
|
|
||||||
start_time, end_time = info_dict.get('section_start') or 0, info_dict.get('section_end')
|
|
||||||
|
|
||||||
selected_formats = info_dict.get('requested_formats') or [info_dict]
|
|
||||||
for i, fmt in enumerate(selected_formats):
|
|
||||||
is_http = re.match(r'https?://', fmt['url'])
|
|
||||||
cookies = self.ydl.cookiejar.get_cookies_for_url(fmt['url']) if is_http else []
|
|
||||||
if cookies:
|
|
||||||
args.extend(['-cookies', ''.join(
|
|
||||||
f'{cookie.name}={cookie.value}; path={cookie.path}; domain={cookie.domain};\r\n'
|
|
||||||
for cookie in cookies)])
|
|
||||||
if fmt.get('http_headers') and is_http:
|
|
||||||
# Trailing \r\n after each HTTP header is important to prevent warning from ffmpeg:
|
|
||||||
# [http @ 00000000003d2fa0] No trailing CRLF found in HTTP header.
|
|
||||||
args.extend(['-headers', ''.join(f'{key}: {val}\r\n' for key, val in fmt['http_headers'].items())])
|
|
||||||
|
|
||||||
if start_time:
|
|
||||||
args += ['-ss', str(start_time)]
|
|
||||||
if end_time:
|
|
||||||
args += ['-t', str(end_time - start_time)]
|
|
||||||
|
|
||||||
url = fmt['url']
|
url = fmt['url']
|
||||||
if self.params.get('enable_file_urls') and url.startswith('file:'):
|
if self.params.get('enable_file_urls') and url.startswith('file:'):
|
||||||
# The default protocol_whitelist is 'file,crypto,data' when reading local m3u8 URLs,
|
# The default protocol_whitelist is 'file,crypto,data' when reading local m3u8 URLs,
|
||||||
@@ -586,6 +574,7 @@ class FFmpegFD(ExternalFD):
|
|||||||
# https://trac.ffmpeg.org/ticket/2702
|
# https://trac.ffmpeg.org/ticket/2702
|
||||||
url = re.sub(r'^file://(?:localhost)?/', 'file:' if os.name == 'nt' else 'file:/', url)
|
url = re.sub(r'^file://(?:localhost)?/', 'file:' if os.name == 'nt' else 'file:/', url)
|
||||||
|
|
||||||
|
args += traverse_obj(fmt, ('downloader_options', 'ffmpeg_args', ...)) or fallback_input_args
|
||||||
args += [*self._configuration_args((f'_i{i + 1}', '_i')), '-i', url]
|
args += [*self._configuration_args((f'_i{i + 1}', '_i')), '-i', url]
|
||||||
|
|
||||||
if not (start_time or end_time) or not self.params.get('force_keyframes_at_cuts'):
|
if not (start_time or end_time) or not self.params.get('force_keyframes_at_cuts'):
|
||||||
|
|||||||
Reference in New Issue
Block a user