Skip to main content

Topic: Extract AAC audio data from FLV: Missing headers (Read 8016 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • ceso
  • [*]
Extract AAC audio data from FLV: Missing headers
Hi,

I try to extract the AAC data from a FLV video. According to the FLV specifications (see Annex E), I can read all audio tags in the FLV. Afterwards I can just put all the data which is contained in audio tags together. This works so far.
Unfortunately, my extracted .aac files are not playable by any player.

For testing purposes, I extracted the AAC data from the FLV by using ffmpeg:
Code: [Select]
ffmpeg -i video.flv -acodec copy audio.aac

This file is playable. I made a binary comparison between the two files. They are just differentiate in some bytes. The ffmpeg output file has some extra bytes included. They follow this pattern:
FF F1 50 80 XX XX FC 21 XX
These additional bytes are repeated about every 700 bytes and the XX can vary per occurence (not per file). At the beginning of the file, these bytes are missing several times.

Two images of the diff (start and middle of the file) are available  here.

Does anyone know where these additional bytes come from?
And where they are specified in order to add them programmatically?

Regards,
ceso

  • nu774
  • [*][*][*][*][*]
  • Developer
Extract AAC audio data from FLV: Missing headers
Reply #1
FF F1 50 80 XX XX FC 21 XX

It's an ADTS header. I don't know if any software capable of playing raw (header-less, container-less) AAC files.

  • Yaztromo
  • [*][*][*]
Extract AAC audio data from FLV: Missing headers
Reply #2
FF F1 50 80 XX XX FC 21 XX

It's an ADTS header. I don't know if any software capable of playing raw (header-less, container-less) AAC files.


A lot of players should work fine with raw AAC. Mplayer and deadbeef do for sure.

@ceso

Probably won't change anything but add -vn to your command line:

ffmpeg -i video.mp4 -vn -acodec copy audio.aac

  • smok3
  • [*][*][*][*][*]
  • Moderator
Extract AAC audio data from FLV: Missing headers
Reply #3
how about "audio.mp4" as output?
  • Last Edit: 30 December, 2011, 04:48:37 PM by smok3
PANIC: CPU 1: Cache Error (unrecoverable - dcache data) Eframe = 0x90000000208cf3b8
NOTICE - cpu 0 didn't dump TLB, may be hung

  • nu774
  • [*][*][*][*][*]
  • Developer
Extract AAC audio data from FLV: Missing headers
Reply #4
A lot of players should work fine with raw AAC. Mplayer and deadbeef do for sure.

Thanks to let me know it, but mplayer doesn't seem to play raw AAC in my environment.
Tried with svn-34401 in Windows. [ Attachment Invalid Or Does Not Exist ]
I can play this file by generating/adding ADTS header with faad like the following:
Code: [Select]
faad -a output.adts.aac input.raw.aac.

Quote
ffmpeg -i video.mp4 -vn -acodec copy audio.aac

He is saying that output of ffmpeg method (which has ADTS header) is already playable.
What he was asking is, he has written a program to programmically extract AAC stream from FLV, and couldn't get playable result (This is because it lacks the headers).
He doesn't need to be taught how to use ffmpeg.

  • Hanseat
  • [*]
Extract AAC audio data from FLV: Missing headers
Reply #5
Edit: Understood question of TO wrong. Please ignore.

You can use
Code: [Select]
ffmpeg.exe -i input.aac -acodec copy -absf aac_adtstoasc output.mp4

to convert aac-streams to a valid mp4 container.

And
Code: [Select]
ffmpeg.exe -i input.flv -acodec copy -vn output.mp4

to convert flv container to mp4 container without video.
  • Last Edit: 31 December, 2011, 12:50:26 PM by Hanseat

  • benski
  • [*][*][*][*][*]
  • Developer
Extract AAC audio data from FLV: Missing headers
Reply #6
The ADTS header is trivial to generate once you have the decoder configuration (stored in the first FLV packet) and the size for the current frame.  Remember that the first byte of the FLV AAC data isn't part of the AAC frame, it's a 1 byte value indicated whether it's a decoder configuration frame or an audio frame.

There is information about the layout of the ADTS header here - http://wiki.multimedia.cx/index.php?title=ADTS
The FLV decoder configuration packet follows the MPEG-4 File Format convention for storing decoder configuration.  It's usually 2 bytes (sometimes more in the case of HE-AAC), I can't remember the exact layout (and not at a computer where I'd have that information anywhere) but google should be able to find it nicely for you.