I need to accurately find the playing time of .aac files. This time is needed to determine the length of a video cut. This is for a GNU/Linux Bash environment (a windows tool which works in wine would be okay if nothing native to Linux is found).

The information must be in these files somewhere, because muxing them into a non-video .m4a shows a time which is close to the actual playtime. (Why they is any difference at all is also a puzzle.)

The .aac files I have tested do not show the real playing time. The times are shown below.

Is there some way to find the real playing time?

Here are the test results.

|                |    mplayer    |               |              |   
|                |   status bar  |  mencoder's   |              |    
|                | run    length |  midentify.sh |   ffmpeg -i  |  
|                | ============= |  ============ |  =========== |
| original A.flv | 2:40     2:40 |    160.64     |     02:40.64 |
| demuxed  A.aac | 2:40     3:10 |    190.20     |     03:10.20 | < whacky times!
| remuxed  A.m4a | 2:40     2:41 |    161.21     |     02:41.20 |
|                |               |               |              |
| original B.flv | 4:54     4:55 |    295.00     |     04:54.99 |
| demuxed  B.aac | 4:55  1:36:22 |   5782.15     |  01:36:22.15 | < whacky times!
| remuxed  B.m4a | 4:49     4:55 |    295.57     |     04:55.57 |

3 Answers 3


Maybe there is some other tool which can do it, but until I find it, the following wine tools do the job quite satisfactorily, but I'm definitely interested to see a more direct method..
I find AviSynth to be a most extraordinary media manipulator.. and true to form, it can manage this task. It is, however, a bit restricted when running without Windows DirectShow support, but it can still do quite a lot; thanks to wine support. AviSynth is assisted by avs2yuv.exe; a tool written to enable Avisynth to be used in a *nix environment..

[[ -f "$1" ]] || { echo "ERROR: input file NOT found" 1>&2 ; exit 1; }
# X suffix = nix path
# Z suffix = dos path (for the wine apps)
aacX="$dirX/$namX" ; aacZ=Z:"${aacX//\//\\}"
ausX="$aacX.aus"   ; ausZ=Z:"${ausX//\//\\}"

 >"$avsX" echo '# =========================================================='
>>"$avsX" echo '# An AviSynth script which outputs to file, the playing time'
>>"$avsX" echo '#  of a .aac audio file, in float seconds'
>>"$avsX" echo '# ======================================='
>>"$avsX" echo audioFile=\""$aacZ"\" 
>>"$avsX" echo audioSecs=\""$ausZ"\" 
>>"$avsX" echo 'audioclip=FFAudioSource(audioFile)'
>>"$avsX" echo 'seconds=float(AudioLength(audioclip))/float(AudioRate(audioclip))'
>>"$avsX" echo 'Blankclip(1)'
>>"$avsX" echo 'WriteFileStart(audioSecs,string(seconds),false)'

rm -f "$ausX" ; wine avs2yuv.exe "$avsX" - >/dev/null 2>&1
cat   "$ausX"
rm -f "$avsX" "$ausX" "$aacX.ffindex"

Here is the output, in seconds, for B.aac from the question's example:


I believe these tools are not accurate because AAC files are an elementary stream, unlike MP4 or FLV which are containers. Streams are just a sequence of samples, without a global header.

To be able to determine the length of an AAC file exactly you would need to parse from start to end and count the samples.

The vast majoritiy of AAC files out there are not really written as raw AAC, but instead each sample has an ADTS header, which makes the parsing a lot easier. The format of the ADTS header is here. The header will give you the sample rate (i.e. 48Khz, 44.1Khz, etc.) and the length of the sample. With the sample rate you can compute the exact duration of that sample, knowing that an AAC sample uncompresses to 1024 PCM samples. The sample length allows you to jump to the next sample, where you will find again the ADTS header.

  • > AAC sample uncompresses to 1024 PCM samples Hello, can you please give reference to this? Is this given in a standard? Commented Aug 14, 2018 at 8:42

I believe mediainfo is capable of providing such info. Works well in both linux and windows environments.

  • I've tried it.. It does not work... Unlike the others I've tried, it at least it doesn't return wrong values... It returns nothing for Duration for .aac.. but thanks for the suggestion, because it (generally) seems quite useful.
    – perer
    Commented Dec 26, 2011 at 23:35
  • it's very useful! To bad it didn't work in this case though.
    – Fredrik
    Commented Dec 26, 2011 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.