From 0d4a478853af5051cba5fee1ebf3ccd8c1d1b675 Mon Sep 17 00:00:00 2001 From: Scott Breyfogle Date: Wed, 23 Oct 2024 13:31:48 -0700 Subject: [PATCH] Add aresample flag to ffmpeg conversion command --- audiotools/core/ffmpeg.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/audiotools/core/ffmpeg.py b/audiotools/core/ffmpeg.py index baf27ccc..83f9cd19 100644 --- a/audiotools/core/ffmpeg.py +++ b/audiotools/core/ffmpeg.py @@ -176,7 +176,14 @@ def load_from_file_with_ffmpeg(cls, audio_path: str, quiet: bool = True, **kwarg ff = ffmpy.FFmpeg( inputs={audio_path: None}, - outputs={wav_file: None}, + # For inputs that are m4a (and others?), the input audio can + # have samples that don't match the sample rate. This aresample + # option forces ffmpeg to read timing information in the source + # file instead of assuming constant sample rate. + # + # This fixes an issue where an input m4a file might be a + # different length than the output wav file + outputs={wav_file: "-af aresample=async=1000"}, global_options=global_options, ) ff.run()