<div dir="ltr"><div class="gmail_signature">Hi,</div><div class="gmail_signature"><br></div><div class="gmail_signature">I am struggeling a bit to find out how to handle encoder delay (e.g. for aac) correctly using libavformat/libavcodec.</div><div class="gmail_signature"><br></div><div class="gmail_signature">Let's take an example (using current ffmpeg from git master):</div><div class="gmail_signature"><br></div><div class="gmail_signature">If I create an aac file using ffmpeg on the command line, say 1second sine wave like so:</div><div class="gmail_signature">
<p class=""><span class="">ffmpeg -f lavfi -i "sine=frequency=1000:sample_rate=48000:duration=1" -strict -2 -c:a aac -y ~/tmp/audiodelay/ffmpeg_sine_1s.m4a</span></p><p class="">and then decode the file, it has a start time of approx -22ms (which is equivalent to 1024 samples, which I presume to be the encoder delay that is detected or assumed).</p><p class="">So, is my reading correct, that to really obtain the samples of the signal without the padding samples, I would have to discard the first 1024 samples. But how do I decide that e.g. in a player or (more critical) analysis application? I then assumed that maybe AVCodecContext::delay would let me make that decision but that is 0 for these files that ffmpeg generates and all others I checked.</p><p class="">How can an ffmpeg api user know when to cut off how many samples or do I have to use heuristics for that?</p><p class="">I foundĀ <a href="https://trac.ffmpeg.org/ticket/2325">https://trac.ffmpeg.org/ticket/2325</a>, which seems related and never got resolved.</p><p class="">Another observation I made was that the ffmpeg-generated pcm file converted to aac (in m4a) using Apple Compressor did not have this timestamp offset and decoding the signal naively using ffmpeg did not yield any sync issues. Maybe they do something in the mov container to account for the padding but I have not checked that.</p><p class="">What needs to be done to find out if this is an ffmpeg bug?</p><p class="">If someone wants this visually (signals compared as they come out of ffmpeg libs when decoding pcm vs. aac file), here are signal comparison graphs scaled to 8000Hz.</p><p class=""><a href="https://www.dropbox.com/s/7shkg94x16we3n0/acompare_sinewave_wav_ffmpeg_aac_m4a.png">https://www.dropbox.com/s/7shkg94x16we3n0/acompare_sinewave_wav_ffmpeg_aac_m4a.png</a></p><p class=""><a href="https://www.dropbox.com/s/jhviq8scig5scac/acompare_sinewave_wav_compressor_aac_m4a.png">https://www.dropbox.com/s/jhviq8scig5scac/acompare_sinewave_wav_compressor_aac_m4a.png</a></p><p class="">Best regards,</p><p class="">Robert</p><p class=""><br></p><p class=""><br></p><p class=""><br></p></div>
</div>