Add support for extra output args to ffmpeg
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 21 Oct 2025 22:30:59 +0000 (00:30 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 21 Oct 2025 22:30:59 +0000 (00:30 +0200)
music_assistant/helpers/ffmpeg.py

index 8d33a7851a0441680ae7a3883fae0ba84ebdceb3..822ef157f7876add7ce8ad0baee991acd70bcadc 100644 (file)
@@ -38,6 +38,7 @@ class FFMpeg(AsyncProcess):
         filter_params: list[str] | None = None,
         extra_args: list[str] | None = None,
         extra_input_args: list[str] | None = None,
+        extra_output_args: list[str] | None = None,
         audio_output: str | int = "-",
         collect_log_history: bool = False,
         loglevel: str = "info",
@@ -51,6 +52,7 @@ class FFMpeg(AsyncProcess):
             input_path=audio_input if isinstance(audio_input, str) else "-",
             output_path=audio_output if isinstance(audio_output, str) else "-",
             extra_input_args=extra_input_args or [],
+            extra_output_args=extra_output_args or [],
             loglevel=loglevel,
         )
         self.audio_input = audio_input
@@ -200,6 +202,7 @@ async def get_ffmpeg_stream(
     extra_args: list[str] | None = None,
     chunk_size: int | None = None,
     extra_input_args: list[str] | None = None,
+    extra_output_args: list[str] | None = None,
     raise_ffmpeg_exception: bool = False,
 ) -> AsyncGenerator[bytes, None]:
     """
@@ -215,6 +218,7 @@ async def get_ffmpeg_stream(
         filter_params=filter_params,
         extra_args=extra_args,
         extra_input_args=extra_input_args,
+        extra_output_args=extra_output_args,
         collect_log_history=True,
     ) as ffmpeg_proc:
         # read final chunks from stdout
@@ -238,6 +242,7 @@ def get_ffmpeg_args(  # noqa: PLR0915
     input_path: str = "-",
     output_path: str = "-",
     extra_input_args: list[str] | None = None,
+    extra_output_args: list[str] | None = None,
     loglevel: str = "error",
 ) -> list[str]:
     """Collect all args to send to the ffmpeg process."""
@@ -245,6 +250,8 @@ def get_ffmpeg_args(  # noqa: PLR0915
         extra_args = []
     if extra_input_args is None:
         extra_input_args = []
+    if extra_output_args is None:
+        extra_output_args = []
     # generic args
     generic_args = [
         "ffmpeg",
@@ -367,6 +374,7 @@ def get_ffmpeg_args(  # noqa: PLR0915
     else:
         raise RuntimeError("Invalid/unsupported output format specified")
 
+    output_args += extra_output_args  # append the extra output args
     # append (final) output path at the end of the args
     output_args.append(output_path)