Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration's calcul for AAC audio files with ADTS header #55

Open
Sami32 opened this issue May 11, 2016 · 4 comments
Open

Duration's calcul for AAC audio files with ADTS header #55

Sami32 opened this issue May 11, 2016 · 4 comments

Comments

@Sami32
Copy link
Contributor

Sami32 commented May 11, 2016

Hello,

Do you plane to implement this ?

I just discover that the duration was not displayed with this kind of AAC files, so my open source media server that use your very useful program don't as well.

I search on Internet and find this explanation :

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.

Thank you for your amazing work :-D
Regards

@Sami32
Copy link
Contributor Author

Sami32 commented Jun 9, 2017

I don't know if it will acceptable or even follow the MediaInfo "convention", but i find an easyway to woraround that.

After having saw that renderers use some approximation algorithm for the duration, certainly the same as WMP, that are not accurate at all.
I then played with FFmpeg and discovered that -bsf:a aac_adtstoasc filter will give me an immediate and accurate result: of course as M4A ;)

So i wondered if MediaInfo could use a similar filter for such case ?

I guess that you already knew about that, but as i was happy to find a way to solve my duration issue, and would like share it, in case that it can be useful to someone else as well.

@JeromeMartinez
Copy link
Member

So i wondered if MediaInfo could use a similar filter for such case ?

Are you sure FFmpeg does not parse the whole file? pure AAC files are usually small so if you test on a single file you may miss the fact the whole file is parsed.
Parsing the whole file and getting the duration is also possible, but it would not be by default (in case someone parses thousands of files, it would be too slow).

@Sami32
Copy link
Contributor Author

Sami32 commented Jun 10, 2017

Sure...no 😳
As it was too fast, i thought that it was, but you could be right.
And yes, i'm thinking about thousand of files been parsed as well, so that's interest me, as some users have huge libraries of 20.000 files, far biggest than my little test library.

How can i make sure FFmpeg filter do not parse the file ?
I admit that checking at the FFmpeg code could be incertain for me, so perhaps try create a huge ADTS(AAC) file ?

@Sami32
Copy link
Contributor Author

Sami32 commented Jun 11, 2017

Sniff...you are right.

It taken 7.6 s for a 220 MB AAC-LC (ADTS) file (1H30mn), so it's really parsed.

EDIT: Thank you for the idea of impleming it as an option 👍 as i should have missed that it was parsed and that some delay was added to users libraries scanning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants