Posting: 24-hour master of AAC File Format

Source: Internet
Author: User
Tags bit set iso documentation

Author: Zhang Yu

Source: http://blog.sina.com.cn/u/465bdf0b010002t0

24-hour master of AAC File Format
 
Today we have a new task to save the RTSP audio stream as a file in AAC format.
I have searched the internet for a long time and have not found the AAC file format.
Later, I consulted a colleague who specializes in coding and decoding. There may be related information in the ISO MPEG document.
It took a long time to find the ISO documentation. ISO is charged and the network is free. Although it is difficult, I still found some documents. The hard work is not enough for outsiders.
After finding An AAC file that can be played by QuickTime, you can read the file and analyze it. This is basically done. However, some documents cannot be found, and some fields do not know what it means. No matter, it can be put anyway :)
 
The AAC format is frame head + frame length, with no file header. I think there should be a file header and an adts_fixed_header on the document, but it seems that there is no header for quicktime. Let's skip it first.
See ISO/IEC 11496-3 1.1 interchange format streams
 
 
Adts_frame ()
{
Byte_alignment ()
Adts_fixed_header ()
Adts_variable_header ()
Adts_error_check ()
Óiso/iec iso/iec cd 14496-3 Subpart 4: 1998
MPEG-4 CD 14496-3 Subpart 4/20:09/22.06.98 11
For (I = 0; I <number_of_raw_data_blocks_in_frame + 1; I ++ ){
Raw_data_block ()
}
}
 
Adts_fixed_header ()
{
Syncword 12 bslbf
Id 1 bslbf
Layer 2 uimsbf
Protection_absent 1 bslbf
Profile 2 uimsbf
Sampling_frequency_index 4 uimsbf
Private_bit 1 bslbf
Channel_configuration 3 uimsbf
Original/Copy 1 bslbf
Home 1 bslbf
Emphasis 2 bslbf
}
 
Adts_variable_header ()
{
Copyright_identification_bit 1 bslbf
Copyright_identification_start 1 bslbf
Frame_length 13 bslbf
Adts_buffer_fullness 11 bslbf
Number_of_raw_data_blocks_in_frame 2 uimsfb
}
 
Code for saving files:
Static char head1 [7];
Int temp = frame_len + 7;
Head1 [0] = (char) 0xff;
Head1 [1] = (char) 0xf9;
Int sr_index = rtp_aac_get_sr_index (aac_param_ptr-> sample_rate );
Head1 [2] = (0x01 <6) | (sr_index <2) | 0x00;
// Head1 [3] = (char) 0x80; // dual channel? A = rtpmap: 97 mpeg4-generic/44100/2
Head1 [3] = (char) 0x40; // single channel? A = rtpmap: 97 mpeg4-generic/44800
Head1 [4] = (temp> 3) & 0xff;
Head1 [5] = (temp & 0x07) <5 | 0x1f );
Head1 [6] = (char) 0xfc;

Fwrite (head1, 1, sizeof (head1), g_file_audio );
Fwrite (frame_buf, 1, frame_len, g_file_audio );
 
Here, frame_buf is the data of one frame, and framec_len is the frame length.
 
Simple Description and confusions:
The length is 7 bytes.
 
Syncword 12 bit 1111 1111 1111
Id 1 bit 1 for MPEG audio
Layer 2 bit not sure, I set to 00
Protection_absent 1 bit set to 1
Profile 2 bit 1 for AAC main
Sampling_frequency_index 4 bit Sample Rate Index
Private_bit 1 bit set to 0
Is channel_configuration 3 bit the number of channels?
In SDP There Is A = rtpmap: 97 mpeg4-generic/44100/2 at this time channel_configuration = 010
A = rtpmap: 97 mpeg4-generic/44800 at this time channel_configuration = 001
Original/Copy 1 bit set to 0
Home 1 bit set ot 0
Emphasis 2bit set to 00
Copyright_identification_bit 1 bit set to 0
Copyright_identification_start 1 bit set to 0
Frame_length 13 bit. The length includes 7 bytes of the head.
The last two fields added to FC are not clear.
 
Incomplete documentation and little knowledge about codec. You can only analyze other people's files and experiments, at least sound.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.