Parse ffmpeg version information and choose best

While I have previously shied away from using imageio-ffmpeg as the
default version because the included version is 4 years old and
specifically does not work with the av1 format, there have been specific
issues from people with a system version of ffmpeg that is even older.

There has been a longstanding desire to create a system for determining
the best version of ffmpeg, but this has proved a reasonably involved
task. Some version information uses git commit hashes instead of a
potentially sortable semvar and there are a large number of compile time
flags that could result in a newer binary having less functionality.

Thus a sysstem has been added that parses compile flags for desired
encoders as well as the copyright year to determine which ffmpeg version
is more feature full.
This commit is contained in:
Austin Mroz
2023-12-19 11:40:42 -06:00
parent 4b2c72d483
commit 75fc10e0ff
+38 -5
View File
@@ -6,15 +6,48 @@ import subprocess
from .logger import logger
ffmpeg_path = shutil.which("ffmpeg")
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ or ffmpeg_path is None:
def ffmpeg_suitability(path):
try:
version = subprocess.run([path, "-version"], check=True,
capture_output=True).stdout.decode("utf-8")
except:
return 0
score = 0
#rough layout of the importance of various features
simple_criterion = [("libvpx", 20),("264",10), ("265",3),
("svtav1",5),("libopus", 1)]
for criterion in simple_criterion:
if version.find(criterion[0]) >= 0:
score += criterion[1]
#obtain rough compile year from copyright information
copyright_index = version.find('2000-2')
if copyright_index >= 0:
copyright_year = version[copyright_index+6:copyright_index+9]
if copyright_year.isnumeric():
score += int(copyright_year)
return score
if "VHS_FORCE_FFMPEG_PATH" in os.environ:
ffmpeg_path = os.env["VHS_FORCE_FFMPEG_PATH"]
else:
ffmpeg_paths = []
try:
from imageio_ffmpeg import get_ffmpeg_exe
ffmpeg_path = get_ffmpeg_exe()
imageio_ffmpeg_path = get_ffmpeg_exe()
ffmpeg_paths.append(imageio_ffmpeg_path)
except:
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
raise
logger.warn("Failed to import imageio_ffmpeg")
if ffmpeg_path is None:
logger.warning("ffmpeg could not be found. Outputs that require it have been disabled")
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
ffmpeg_path = imageio_ffmpeg_path
else:
system_ffmpeg = shutil.which("ffmpeg")
if system_ffmpeg is not None:
ffmpeg_paths.append(system_ffmpeg)
if len(ffmpeg_paths) == 0:
logger.error("No valid ffmpeg found.")
ffmpeg_path = max(ffmpeg_paths, key=ffmpeg_suitability)
def get_sorted_dir_files_from_directory(directory: str, skip_first_images: int=0, select_every_nth: int=1, extensions: Iterable=None):
directory = directory.strip()