Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(audio): align float decode with first stream rate

agammann396f3d6c4211
diff --git a/invokeai/app/util/video_audio.py b/invokeai/app/util/video_audio.py
index 94f3c04075..074546c539 100644
--- a/invokeai/app/util/video_audio.py
+++ b/invokeai/app/util/video_audio.py
@@ -64,6 +64,7 @@ def extract_audio_pcm(video_path: Path, *, float_pcm: bool = False) -> tuple[np.
"error",
"-i",
str(video_path),
+ *(["-map", "0:a:0?"] if float_pcm else []),
"-vn",
"-ac",
"2",
diff --git a/tests/app/util/test_video_audio_float.py b/tests/app/util/test_video_audio_float.py
index b824dca05b..c5052ac0a5 100644
--- a/tests/app/util/test_video_audio_float.py
+++ b/tests/app/util/test_video_audio_float.py
@@ -50,7 +50,11 @@ def _make_video(tmp_dir: Path, wavs: list[tuple[np.ndarray, int]]) -> Path:
args += ["-map", "0:v:0"]
for index in range(len(wav_paths)):
args += ["-map", f"{index + 1}:a:0"]
- args += ["-c:v", "copy", "-c:a", "aac", str(out)]
+ args += ["-c:v", "copy", "-c:a", "aac"]
+ if len(wav_paths) > 1:
+ # Default stream 1 forces ffmpeg's automatic selection away from stream 0.
+ args += ["-disposition:a:0", "0", "-disposition:a:1", "default"]
+ args += [str(out)]
subprocess.run(args, check=True, capture_output=True, timeout=120)
return out