在 AAC 中转换后 ffmpeg 错误的音频文件

ffmpeg wrong audio file after conversion in AAC

我在使用 FFmpeg 进行编码时遇到问题。 我有带 aac 音频的 au mp4 文件。我试图用 ffmpeg 复制音频。 在源 mp4 文件中,第一个音频噪声出现在 0.30 秒处。 使用ffmpeg -i inputfile.mp4 -c:a copy outputfile.aac转换后,生成的文件是错误的,第一个音频噪音出现在0.32秒。 文件的持续时间也不一样。

当我强制编码器为 libfaac 时,它可以工作,但文件太大。

那么为什么在使用默认编码器 (aac, libfdk_aac) 时它不起作用? 请注意,当我从 audacity 转换时会出现同样的事情。

非常感谢

解码器需要音频流中的填充帧来解码第一帧。这是 AAC 等 MDCT 音频编解码器的技术要求。在像 MP4/MKV 这样的定时样本容器中,第一帧具有负的呈现时间戳。在原始 AAC 比特流中,第一帧被简单地解码。每帧有 1024 个样本,因此持续时间为 21-23 毫秒。您在时间上的差异是由于该偏移造成的。重新包装到像 M4A 这样的容器中以避免这种情况。

背景,来自Apple

AAC requires data beyond the source PCM audio samples in order to correctly encode and decode audio samples due to the nature of the encoding algorithm. AAC encoding uses a transform over consecutive sets of 2048 audio samples, applied every 1024 audio samples (overlapped). For correct audio to be decoded, both transforms for any period of 1024 audio samples are needed. For this reason, encoders add at least 1024 samples of silence before the first ‘true’ audio sample, and often add more. This is called variously “priming”, “priming samples”, or “encoder delay”.

The lack of explicit representation for encoder delay and remainder samples is not a problem unique to AAC encoding. With MPEG-4 and ADTS/MPEG-2 bitstreams and file containers, there is still no satisfactory, explicit representation for either the encoder delay or remainder samples. MP3 also has these data dependencies and delays in its bitstream, as do proprietary codecs such as AC-3 and others.