Take the 2-minute tour ×
Sound Design Stack Exchange is a question and answer site for sound engineers, producers, editors, and enthusiasts. It's 100% free, no registration required.

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 |
 ---------------------------------------------------------------
share|improve this question

migrated from avp.stackexchange.com Jan 24 at 12:01

This question came from our site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation.

add comment

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)
dirX="${1%/*}"
namX="${1##*/}"
aacX="$dirX/$namX" ; aacZ=Z:"${aacX//\//\\}"
ausX="$aacX.aus"   ; ausZ=Z:"${ausX//\//\\}"
avsX="$aacX.avs"

 >"$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:

295.543579
share|improve this answer
add comment

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

share|improve this answer
    
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 Dec 26 '11 at 23:35
    
it's very useful! To bad it didn't work in this case though. –  Fredrik Dec 26 '11 at 23:44
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.