Search code examples
ffmpegdelaylatencycross-correlation

FFMPEG: Automatically remove audio codec latency


I am using FFMPEG to apply several audio codecs to a large number of speech files. Each codec introduces a different latency and I could not find a description of the precise value of this delay. However, for an investigation I need to correct this delay, i.e. adjust the audio after coding such that it is time aligned with the original, uncoded audio. At the moment I use cross-correlation to figure out the actual latency introduced by the codecs which is working fine, but it feels slightly unreliable. Is there some way to a) remove the delay automatically or b) to exactly know the delay of the codecs? Thank you!


Solution

  • Cross-correlation is about as good as you can do to measure these delays. If you are currently using the full duration of audio data (or the same durations acoross all files), you can shorten the original audio by a little more than the maximum delay expected. This way the cross-correlations are fully supported (i.e., no zero padding) over the lag range of your interest.