[FFmpeg-user] Unexpected aac audio duration
naraimo at libero.it
naraimo at libero.it
Thu Feb 20 18:48:38 EET 2020
Hi all,
I'm trying to encode audio with ffmpeg aac encoder. An example with brown noise input follows:
ffmpeg -f lavfi -i anoisesrc=c=brown:a=0.05:d=1:r=8000:n=1024 -t 0.560 -ac 8000 -codec aac -b:a 16k -f adts out.aac
The result is shown below:
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, lavfi, from 'anoisesrc=c=brown:a=0.05:d=1:r=8000:n=1024':
Duration: N/A, start: 0.000000, bitrate: 512 kb/s
Stream #0:0: Audio: pcm_f64le, 8000 Hz, mono, dbl, 512 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (pcm_f64le (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, adts, to 'out.aac':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Audio: aac (LC), 8000 Hz, mono, fltp, 16 kb/s
Metadata:
encoder : Lavc57.107.100 aac
size= 1kB time=00:00:00.64 bitrate= 18.7kbits/s speed=76.3x
video:0kB audio:1kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.892562%
[aac @ 0x5563feb38820] Qavg: 11006.257
Due to the aac frames size (1024) and 8KHz sample rate the duration of each aac frame is 1024/8000 = 0.128 seconds. The required duration (-t 0.56) cannot be divided by 0.128 so it is correctly rounded to the nearest frame (5*0.128 = 0.64). The result, as reported by ffmpeg "time=00:00:00.64", should have a duration of 0.64 seconds.
But if I decode the aac to raw pcm I get a different duration:
ffmpeg -i out.aac -c pcm_s16le -f s16le out_aac.raw
[...]
Output #0, s16le, to 'out_aac.raw':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Audio: pcm_s16le, 8000 Hz, mono, s16, 128 kb/s
Metadata:
encoder : Lavc57.107.100 pcm_s16le
size= 12kB time=00:00:00.76 bitrate= 128.0kbits/s speed=1.26e+03x
video:0kB audio:12kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
It seems that an aac frame has been added to the output (6*0.128 = 0.768).
I have also checked the file size (12288 byte). This means 6144 samples. With 8KHz the duration is 6144 / 8000 = 0.768 seconds.
I have noticed the same behaviour with longer durations, without the anoisesrc source (file input) and also with muxer (e.g. HLS) based on aac encoder.
Below an example based on previously generated out.aac file (0.768 seconds) and HLS muxer:
ffmpeg -i out.aac -b:a 16k -hls_time 1.2 -hls_list_size 0 -hls_segment_type mpegts out.m3u8
[...]
Output #0, hls, to 'out.m3u8':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Audio: aac (LC), 8000 Hz, mono, fltp, 16 kb/s
Metadata:
encoder : Lavc57.107.100 aac
[hls @ 0x55f0b7d84840] Opening 'out.m3u8.tmp' for writing
size=N/A time=00:00:00.76 bitrate=N/A speed= 113x
video:0kB audio:3kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[aac @ 0x55f0b7d837c0] Qavg: 19275.893
The input samples count is divisible by 1024. However, the output duration is increased of another frame (7*0.128 = 0.896) as shown by the m3u8 file:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:1
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:0.896000,
out0.ts
#EXT-X-ENDLIST
I would like to ask if this the expected behaviour of aac encoder.
And if so, is it possible to get an output with the correct duration (eventually rounded to the first aac frame)?
Thanks for any help,
Nadir
More information about the ffmpeg-user
mailing list