]> jfr.im git - yt-dlp.git/commitdiff
[ffmpeg] Set `ffmpeg_location` in a contextvar
authorpukkandan <redacted>
Sat, 30 Jul 2022 18:17:14 +0000 (23:47 +0530)
committerpukkandan <redacted>
Sat, 30 Jul 2022 20:50:12 +0000 (02:20 +0530)
Fixes #2191 for the CLI, but not when used through the API

yt_dlp/__init__.py
yt_dlp/postprocessor/ffmpeg.py

index 5b9b3541cdbfea846723b7edbc67248974308d03..24f6153e056858f4cc8101555f144b2b3560a2be 100644 (file)
@@ -19,6 +19,7 @@
 from .extractor.common import InfoExtractor
 from .options import parseOpts
 from .postprocessor import (
+    FFmpegPostProcessor,
     FFmpegExtractAudioPP,
     FFmpegSubtitlesConvertorPP,
     FFmpegThumbnailsConvertorPP,
@@ -899,6 +900,11 @@ def _real_main(argv=None):
     if print_extractor_information(opts, all_urls):
         return
 
+    # We may need ffmpeg_location without having access to the YoutubeDL instance
+    # See https://github.com/yt-dlp/yt-dlp/issues/2191
+    if opts.ffmpeg_location:
+        FFmpegPostProcessor._ffmpeg_location.set(opts.ffmpeg_location)
+
     with YoutubeDL(ydl_opts) as ydl:
         pre_process = opts.update_self or opts.rm_cachedir
         actual_use = all_urls or opts.load_info_filename
index c3b9ac7faf8f6f7ef4b035e18c05d4a58b497937..f77ca427e315ce7b6640f6cf4ac73dcb68c42c46 100644 (file)
@@ -1,4 +1,5 @@
 import collections
+import contextvars
 import itertools
 import json
 import os
@@ -81,6 +82,8 @@ class FFmpegPostProcessorError(PostProcessingError):
 
 
 class FFmpegPostProcessor(PostProcessor):
+    _ffmpeg_location = contextvars.ContextVar('ffmpeg_location', default=None)
+
     def __init__(self, downloader=None):
         PostProcessor.__init__(self, downloader)
         self._prefer_ffmpeg = self.get_param('prefer_ffmpeg', True)
@@ -100,7 +103,7 @@ def get_versions(downloader=None):
     def _determine_executables(self):
         programs = [*self._ffmpeg_to_avconv.keys(), *self._ffmpeg_to_avconv.values()]
 
-        location = self.get_param('ffmpeg_location')
+        location = self.get_param('ffmpeg_location', self._ffmpeg_location.get())
         if location is None:
             return {p: p for p in programs}