mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-30 03:33:02 +00:00
[ffmpeg] Cache version data
Related: https://github.com/dasl-/pifi/issues/9
This commit is contained in:
parent
9139d2fae0
commit
8a7f68d0b1
2 changed files with 20 additions and 24 deletions
|
@ -86,13 +86,18 @@ def get_versions_and_features(downloader=None):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_versions(downloader=None):
|
def get_versions(downloader=None):
|
||||||
return FFmpegPostProcessor.get_version_and_features(downloader)[0]
|
return FFmpegPostProcessor.get_versions_and_features(downloader)[0]
|
||||||
|
|
||||||
|
_version_cache, _features_cache = {}, {}
|
||||||
|
|
||||||
def _determine_executables(self):
|
def _determine_executables(self):
|
||||||
programs = ['avprobe', 'avconv', 'ffmpeg', 'ffprobe']
|
programs = ['avprobe', 'avconv', 'ffmpeg', 'ffprobe']
|
||||||
|
|
||||||
def get_ffmpeg_version(path, prog):
|
def get_ffmpeg_version(path, prog):
|
||||||
out = _get_exe_version_output(path, ['-bsfs'])
|
if path in self._version_cache:
|
||||||
|
self._versions[path], self._features = self._version_cache[path], self._features_cache.get(path, {})
|
||||||
|
return
|
||||||
|
out = _get_exe_version_output(path, ['-bsfs'], to_screen=self.write_debug)
|
||||||
ver = detect_exe_version(out) if out else False
|
ver = detect_exe_version(out) if out else False
|
||||||
if ver:
|
if ver:
|
||||||
regexs = [
|
regexs = [
|
||||||
|
@ -104,13 +109,13 @@ def get_ffmpeg_version(path, prog):
|
||||||
mobj = re.match(regex, ver)
|
mobj = re.match(regex, ver)
|
||||||
if mobj:
|
if mobj:
|
||||||
ver = mobj.group(1)
|
ver = mobj.group(1)
|
||||||
self._versions[prog] = ver
|
self._versions[prog] = self._version_cache[path] = ver
|
||||||
if prog != 'ffmpeg' or not out:
|
if prog != 'ffmpeg' or not out:
|
||||||
return
|
return
|
||||||
|
|
||||||
mobj = re.search(r'(?m)^\s+libavformat\s+(?:[0-9. ]+)\s+/\s+(?P<runtime>[0-9. ]+)', out)
|
mobj = re.search(r'(?m)^\s+libavformat\s+(?:[0-9. ]+)\s+/\s+(?P<runtime>[0-9. ]+)', out)
|
||||||
lavf_runtime_version = mobj.group('runtime').replace(' ', '') if mobj else None
|
lavf_runtime_version = mobj.group('runtime').replace(' ', '') if mobj else None
|
||||||
self._features = {
|
self._features = self._features_cache[path] = {
|
||||||
'fdk': '--enable-libfdk-aac' in out,
|
'fdk': '--enable-libfdk-aac' in out,
|
||||||
'setts': 'setts' in out.splitlines(),
|
'setts': 'setts' in out.splitlines(),
|
||||||
'needs_adtstoasc': is_outdated_version(lavf_runtime_version, '57.56.100', False),
|
'needs_adtstoasc': is_outdated_version(lavf_runtime_version, '57.56.100', False),
|
||||||
|
@ -148,25 +153,14 @@ def get_ffmpeg_version(path, prog):
|
||||||
self._paths[basename] = location
|
self._paths[basename] = location
|
||||||
|
|
||||||
self._versions = {}
|
self._versions = {}
|
||||||
for p in programs:
|
executables = {'basename': ('ffmpeg', 'avconv'), 'probe_basename': ('ffprobe', 'avprobe')}
|
||||||
|
if prefer_ffmpeg is False:
|
||||||
|
executables = {k: v[::-1] for k, v in executables.items()}
|
||||||
|
for var, prefs in executables.items():
|
||||||
|
for p in prefs:
|
||||||
get_ffmpeg_version(self._paths[p], p)
|
get_ffmpeg_version(self._paths[p], p)
|
||||||
|
|
||||||
if prefer_ffmpeg is False:
|
|
||||||
prefs = ('avconv', 'ffmpeg')
|
|
||||||
else:
|
|
||||||
prefs = ('ffmpeg', 'avconv')
|
|
||||||
for p in prefs:
|
|
||||||
if self._versions[p]:
|
if self._versions[p]:
|
||||||
self.basename = p
|
setattr(self, var, p)
|
||||||
break
|
|
||||||
|
|
||||||
if prefer_ffmpeg is False:
|
|
||||||
prefs = ('avprobe', 'ffprobe')
|
|
||||||
else:
|
|
||||||
prefs = ('ffprobe', 'avprobe')
|
|
||||||
for p in prefs:
|
|
||||||
if self._versions[p]:
|
|
||||||
self.probe_basename = p
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.basename == 'avconv':
|
if self.basename == 'avconv':
|
||||||
|
|
|
@ -2713,7 +2713,9 @@ def check_executable(exe, args=[]):
|
||||||
return exe
|
return exe
|
||||||
|
|
||||||
|
|
||||||
def _get_exe_version_output(exe, args):
|
def _get_exe_version_output(exe, args, *, to_screen=None):
|
||||||
|
if to_screen:
|
||||||
|
to_screen(f'Checking exe version: {shell_quote([exe] + args)}')
|
||||||
try:
|
try:
|
||||||
# STDIN should be redirected too. On UNIX-like systems, ffmpeg triggers
|
# STDIN should be redirected too. On UNIX-like systems, ffmpeg triggers
|
||||||
# SIGTTOU if yt-dlp is run in the background.
|
# SIGTTOU if yt-dlp is run in the background.
|
||||||
|
|
Loading…
Reference in a new issue