Writing AAC Audio

579 views
Skip to first unread message

aswin....@gmail.com

unread,
Oct 19, 2012, 10:04:37 AM10/19/12
to mp...@googlegroups.com
Hi,
i'm getting video and audio stream from a device. I was able to write the video(h264) and audio(aac) to the file. However when i print the information using mp4info this is what i see.
mp4info version trunk-r496
20121019-123644.683341.3.mp4:
FindBytesProperty: no such property moov.trak[1].mdia.minf.stbl.stsd.*[0].*.esds.decConfigDescr.decSpecificInfo[0].info (src/mp4file.cpp,865)
Track   Type    Info
1       video   H264 Baseline@4.1, 13.844 secs, 30 kbps, 640x480 @ 7.078879 fps
2       audio   MPEG-4 Unknown Profile(0), 13.952 secs, 64 kbps, 16000 Hz

when i use the trackdump for audio, this is what i'm getting.

mp4trackdump version trunk-r496
mp4file 20121019-133846.919365.3.mp4, track 2, samples 214, timescale 16000
operator[]: illegal array index: 2147483647 of 0: errno: 34 (src/mp4array.h,128)
sampleId      1, size   513 duration     1024 time        0 00:00:00.000  
operator[]: illegal array index: 2147483647 of 0: errno: 34 (src/mp4array.h,128)
sampleId      2, size   513 duration     1024 time     1024 00:00:00.064  
operator[]: illegal array index: 2147483647 of 0: errno: 34 (src/mp4array.h,128)
sampleId      3, size   513 duration     1024 time     2048 00:00:00.128  
operator[]: illegal array index: 2147483647 of 0: errno: 34 (src/mp4array.h,128)
sampleId      4, size   513 duration     1024 time     3072 00:00:00.192  
operator[]: illegal array index: 2147483647 of 0: errno: 34 (src/mp4array.h,128)
sampleId      5, size   513 duration     1024 time     4096 00:00:00.256  

when i play the file using VLC, i see video and don't hear any audio.

I dont know whether the information i have written is right or wrong.
Can someone help me on this.

Thanks,
Aswin

Aswin Paranji

unread,
Oct 22, 2012, 5:51:18 AM10/22/12
to mp...@googlegroups.com
Hi,

I checked on what mp4info is doing. The  MP4GetTrackAudioMpeg4Type return 0. Further investigating on this call goes to mp4file.cpp and calls these functions:
GetTrackAudioMpeg4Type
   GetTrackESConfiguration
Within GetTrackESConfiguration 
GetTrackBytesProperty(trackId,"mdia.minf.stbl.stsd.*[0].esds.decConfigDescr.decSpecificInfo[0].info",
                              ppConfig, pConfigSize);
is called.

It seems that the decoder specific info is not set when MP4AddAudioTrack is called.

Could someone tell me what I need to provide 

thanks
Aswin Paranji

Aswin Paranji

unread,
Oct 23, 2012, 2:43:35 AM10/23/12
to mp...@googlegroups.com
Hi,
I figured out how to write the decoder specific info.
I get the following data from SDP.
m=audio 49230 RTP/AVP 96
   a=rtpmap:96 mpeg4-generic/16000/1
   a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr;
   config=1408; sizeLength=13; indexLength=3;
   indexDeltaLength=3; profile=1; bitrate=64000

so i call the following function after MP4AddAudioTrack
MP4SetAudioProfileLevel( m_mp4File, 0x0F );
bool bRet=MP4SetTrackESConfiguration(m_mp4File,m_audioTrackId,rr,2);

where rr is a pointer array which contain 1408 which tells the type of AAC and the channel. This i was able to figure out from the following wiki.
http://wiki.multimedia.cx/index.php?title=MP4A#Audio_Specific_Config

when i use mp4info this is what get printed.
mp4info version trunk-r496
20121023-062928.639858.3.mp4:
Track   Type    Info
1       audio   MPEG-4 AAC main, 13.696 secs, 64 kbps, 16000 Hz
2       video   H264 Baseline@4.1, 13.578 secs, 54 kbps, 640x480 @ 7.070261 fps

This tells me the file contains necessary information for the deocder to start decoding.
However, when i use VLC to decode the VLC log shows this

[aac @ 0x7f9b70c17340] Number of bands (20) exceeds limit (3).
[0x7f9b70c02c48] avcodec decoder warning: cannot decode one frame (513 bytes)

Now, if you look at the bytes it says 513. this is what i write into the file. I get the AAC audio in RTP format which is of size 509 bytes. i Append 4 bytes in front of the AAC frame which contains the total bytes(509) and push it thru WriteSample.

I think I have to strip some data from AAC. When i use VLC to write a mp4 file, the size of the audio frame is less than 509.if i check using mp4info it says AAC Low complexity.

Am i doing something wrong. How should i write an AAC audio streamed in RTP format.

Thanks,
Aswin Paranji

Aswin Paranji

unread,
Jan 22, 2013, 5:57:33 AM1/22/13
to mp...@googlegroups.com
Ok what i was doing wrong is i was using decimal value instead of hexdecimal.

this is how it has to loook like
audioTrackId=MP4AddAudioTrack(
                            mp4File,
                            16000,
                            MP4_INVALID_DURATION);

                uint8_t *rrr=new uint8_t[2];
                rrr[0]=0x14;
                rrr[1]=0x08;
                MP4SetAudioProfileLevel( mp4File, 0x0F );
                bool bRet=MP4SetTrackESConfiguration(mp4File,audioTrackId,rrr,2);
                delete []rrr;

then add 4 bytes in each frame for sample length
MP4WriteSample(mp4File,audioTrackId,frame+4, static_cast<u_int32_t>(frameSize-4),audioTicks , 0, KF);

On Friday, 19 October 2012 19:34:37 UTC+5:30, Aswin Paranji wrote:
Reply all
Reply to author
Forward
0 new messages