Mercurial > audlegacy
comparison Input/aac/src/mp4_utils.c @ 2:6efb9e514224 trunk
[svn] Import AAC stuff.
author | nenolod |
---|---|
date | Mon, 24 Oct 2005 10:44:27 -0700 |
parents | |
children | a3913b2d0acd |
comparison
equal
deleted
inserted
replaced
1:cc6293c827ec | 2:6efb9e514224 |
---|---|
1 /* | |
2 ** some function for MP4 file based on libmp4v2 from mpeg4ip project | |
3 */ | |
4 #include <mp4.h> | |
5 #include <faad.h> | |
6 | |
7 const char *mp4AudioNames[]= | |
8 { | |
9 "MPEG-1 Audio Layers 1,2 or 3", | |
10 "MPEG-2 low biterate (MPEG-1 extension) - MP3", | |
11 "MPEG-2 AAC Main Profile", | |
12 "MPEG-2 AAC Low Complexity profile", | |
13 "MPEG-2 AAC SSR profile", | |
14 "MPEG-4 audio (MPEG-4 AAC)", | |
15 0 | |
16 }; | |
17 | |
18 const u_int8_t mp4AudioTypes[] = | |
19 { | |
20 MP4_MPEG1_AUDIO_TYPE, // 0x6B | |
21 MP4_MPEG2_AUDIO_TYPE, // 0x69 | |
22 MP4_MPEG2_AAC_MAIN_AUDIO_TYPE, // 0x66 | |
23 MP4_MPEG2_AAC_LC_AUDIO_TYPE, // 0x67 | |
24 MP4_MPEG2_AAC_SSR_AUDIO_TYPE, // 0x68 | |
25 MP4_MPEG4_AUDIO_TYPE, // 0x40 | |
26 0 | |
27 }; | |
28 | |
29 /* MPEG-4 Audio types from 14496-3 Table 1.5.1 (from mp4.h)*/ | |
30 const char *mpeg4AudioNames[]= | |
31 { | |
32 "!!!!MPEG-4 Audio track Invalid !!!!!!!", | |
33 "MPEG-4 AAC Main profile", | |
34 "MPEG-4 AAC Low Complexity profile", | |
35 "MPEG-4 AAC SSR profile", | |
36 "MPEG-4 AAC Long Term Prediction profile", | |
37 "MPEG-4 AAC Scalable", | |
38 "MPEG-4 CELP", | |
39 "MPEG-4 HVXC", | |
40 "MPEG-4 Text To Speech", | |
41 "MPEG-4 Main Synthetic profile", | |
42 "MPEG-4 Wavetable Synthesis profile", | |
43 "MPEG-4 MIDI Profile", | |
44 "MPEG-4 Algorithmic Synthesis and Audio FX profile" | |
45 }; | |
46 | |
47 int getAACTrack(MP4FileHandle file) | |
48 { | |
49 int numTracks = MP4GetNumberOfTracks(file, NULL, 0); | |
50 int i=0; | |
51 | |
52 for(i=0;i<numTracks;i++){ | |
53 MP4TrackId trackID = MP4FindTrackId(file, i, NULL, 0); | |
54 const char *trackType = MP4GetTrackType(file, trackID); | |
55 if(!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)){//we found audio track ! | |
56 int j=0; | |
57 u_int8_t audiotype = MP4GetTrackAudioType(file, trackID); | |
58 while(mp4AudioTypes[j]){ // what kind of audio is ? | |
59 if(mp4AudioTypes[j] == audiotype){ | |
60 if(mp4AudioTypes[j] == MP4_MPEG4_AUDIO_TYPE){//MPEG4 audio ok | |
61 audiotype = MP4GetTrackAudioMpeg4Type(file, trackID); | |
62 printf("%d-%s\n", audiotype, mpeg4AudioNames[audiotype]); | |
63 return (trackID); | |
64 } | |
65 else{ | |
66 printf("%s\n", mp4AudioNames[j]); | |
67 if (mp4AudioTypes[j]== MP4_MPEG2_AAC_LC_AUDIO_TYPE || | |
68 mp4AudioTypes[j]== MP4_MPEG2_AAC_MAIN_AUDIO_TYPE || | |
69 mp4AudioTypes[j]== MP4_MPEG2_AAC_SSR_AUDIO_TYPE) | |
70 return(trackID); | |
71 return(-1); | |
72 } | |
73 } | |
74 j++; | |
75 } | |
76 } | |
77 } | |
78 return(-1); | |
79 } | |
80 | |
81 int getAudioTrack(MP4FileHandle file) | |
82 { | |
83 int numTracks = MP4GetNumberOfTracks(file, NULL,0); | |
84 int i=0; | |
85 | |
86 for(i=0;i<numTracks;i++){ | |
87 MP4TrackId trackID = MP4FindTrackId(file, i, NULL, 0); | |
88 const char *trackType = MP4GetTrackType(file, trackID); | |
89 if(!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)){ | |
90 return(trackID); | |
91 } | |
92 } | |
93 return(-1); | |
94 } | |
95 | |
96 int getVideoTrack(MP4FileHandle file) | |
97 { | |
98 int numTracks = MP4GetNumberOfTracks(file, NULL, 0); | |
99 int i=0; | |
100 | |
101 for(i=0;i<numTracks; i++){ | |
102 MP4TrackId trackID = MP4FindTrackId(file, i, NULL, 0); | |
103 const char *trackType = MP4GetTrackType(file, trackID); | |
104 if(!strcmp(trackType, MP4_VIDEO_TRACK_TYPE)){ | |
105 return (trackID); | |
106 } | |
107 } | |
108 return(-1); | |
109 } | |
110 | |
111 void getMP4info(char* file) | |
112 { | |
113 MP4FileHandle mp4file; | |
114 MP4Duration trackDuration; | |
115 int numTracks; | |
116 int i=0; | |
117 | |
118 if(!(mp4file = MP4Read(file,0))) | |
119 return; | |
120 //MP4Dump(mp4file, 0, 0); | |
121 numTracks = MP4GetNumberOfTracks(mp4file, NULL, 0); | |
122 g_print("there are %d track(s)\n", numTracks); | |
123 for(i=0;i<numTracks;i++){ | |
124 MP4TrackId trackID = MP4FindTrackId(mp4file, i, NULL, 0); | |
125 const char *trackType = MP4GetTrackType(mp4file, trackID); | |
126 printf("Track %d, %s", trackID, trackType); | |
127 if(!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)){//we found audio track ! | |
128 int j=0; | |
129 u_int8_t audiotype = MP4GetTrackAudioType(mp4file, trackID); | |
130 while(mp4AudioTypes[j]){ // what kind of audio is ? | |
131 if(mp4AudioTypes[j] == audiotype){ | |
132 if(mp4AudioTypes[j] == MP4_MPEG4_AUDIO_TYPE){ | |
133 audiotype = MP4GetTrackAudioMpeg4Type(mp4file, trackID); | |
134 g_print(" %s", mpeg4AudioNames[audiotype]); | |
135 } | |
136 else{ | |
137 printf(" %s", mp4AudioNames[j]); | |
138 } | |
139 g_print(" duration :%d", | |
140 MP4ConvertFromTrackDuration(mp4file, trackID, | |
141 MP4GetTrackDuration(mp4file, | |
142 trackID), | |
143 MP4_MSECS_TIME_SCALE)); | |
144 } | |
145 j++; | |
146 } | |
147 } | |
148 printf("\n"); | |
149 } | |
150 MP4Close(mp4file); | |
151 } |