Log in

View Full Version : Encoding wav files to ac3 creates files of different time length


Amarena21
28th August 2019, 08:52
Hi everyone, I'm having troubles encoding wav files to ac3.

My current workflow is untouched ac3 -> wav (i convert to wave to time stretch the audio) -> ac3.

Unfortunately once I finish time stretching these wav files and I export them to ac3 with the built-in ac3 encoder in Adobe Audition CC 2017 the length is always a little longer compared to the original wav files.

I also tried reencoding these wav files with the ffmpeg encoder (with Audacity) and also useac3to gui hoping that maybe using these other tools the length would remain unchanged but it doesn't.

The amount of milliseconds added in the ac3 encodes varies depending on the wav file and it usually goes from 20 to 50 milliseconds, but it remains the same no matter which encoder I'm using (Adobe Audition, ffmpeg library (with Audacity) or useac3to) leading me to think that this might be an issue with the ac3 codec itself not with a speciifc encoder.

Does anyone know a way to make sure that the length of an audio track remains the same once converted to ac3?

Thanks to everyone who can help.

sneaker_ger
28th August 2019, 09:03
What you observed is normal for the most common lossy audio codecs (AC3, DTS, MP3, AAC, Opus, Vorbis ..).
They add:
1. encoder delay at the start (usually 5ms for AC3)
2. some extra padding at the end because their frames have certain sizes, not arbritrary ones. (at 48 kHz every AC3 frame is 32ms long so your file ends up a multiple of 32ms)

tebasuna51
28th August 2019, 10:34
...and also useac3to gui hoping that maybe using with these other tools the length would remain unchanged but it doesn't.

The reasons are explained by sneaker_ger.

With AC3 48 KHz only 5,33 ms (256 silence samples added at the beginning) of delay are added each time you encode (the final silence added is not important for sync).

If you want minimize that delay you can use UsEac3to to encode with Output format ac3-ffm and add:

stdout.w64 -5ms | ffmpeg -i - -c:a ac3 -b:a 640k -center_mixlev 0.707 %_.ac3

BTW if you want time stretching the duration is also changed and the precision is not exact always.