00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "avformat.h"
00027 #include "internal.h"
00028 #include "isom.h"
00029 #include "riff.h"
00030 #include "libavcodec/mpeg4audio.h"
00031 #include "libavcodec/mpegaudiodata.h"
00032
00033
00034
00035 const AVCodecTag ff_mp4_obj_type[] = {
00036 { AV_CODEC_ID_MOV_TEXT , 0x08 },
00037 { AV_CODEC_ID_MPEG4 , 0x20 },
00038 { AV_CODEC_ID_H264 , 0x21 },
00039 { AV_CODEC_ID_AAC , 0x40 },
00040 { AV_CODEC_ID_MP4ALS , 0x40 },
00041 { AV_CODEC_ID_MPEG2VIDEO , 0x61 },
00042 { AV_CODEC_ID_MPEG2VIDEO , 0x60 },
00043 { AV_CODEC_ID_MPEG2VIDEO , 0x62 },
00044 { AV_CODEC_ID_MPEG2VIDEO , 0x63 },
00045 { AV_CODEC_ID_MPEG2VIDEO , 0x64 },
00046 { AV_CODEC_ID_MPEG2VIDEO , 0x65 },
00047 { AV_CODEC_ID_AAC , 0x66 },
00048 { AV_CODEC_ID_AAC , 0x67 },
00049 { AV_CODEC_ID_AAC , 0x68 },
00050 { AV_CODEC_ID_MP3 , 0x69 },
00051 { AV_CODEC_ID_MP2 , 0x69 },
00052 { AV_CODEC_ID_MPEG1VIDEO , 0x6A },
00053 { AV_CODEC_ID_MP3 , 0x6B },
00054 { AV_CODEC_ID_MJPEG , 0x6C },
00055 { AV_CODEC_ID_PNG , 0x6D },
00056 { AV_CODEC_ID_JPEG2000 , 0x6E },
00057 { AV_CODEC_ID_VC1 , 0xA3 },
00058 { AV_CODEC_ID_DIRAC , 0xA4 },
00059 { AV_CODEC_ID_AC3 , 0xA5 },
00060 { AV_CODEC_ID_DTS , 0xA9 },
00061 { AV_CODEC_ID_VORBIS , 0xDD },
00062 { AV_CODEC_ID_DVD_SUBTITLE, 0xE0 },
00063 { AV_CODEC_ID_QCELP , 0xE1 },
00064 { AV_CODEC_ID_MPEG4SYSTEMS, 0x01 },
00065 { AV_CODEC_ID_MPEG4SYSTEMS, 0x02 },
00066 { AV_CODEC_ID_NONE , 0 },
00067 };
00068
00069 const AVCodecTag ff_codec_movvideo_tags[] = {
00070
00071
00072 { AV_CODEC_ID_RAWVIDEO, MKTAG('r', 'a', 'w', ' ') },
00073 { AV_CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', '2') },
00074 { AV_CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') },
00075 { AV_CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') },
00076
00077 { AV_CODEC_ID_RAWVIDEO, MKTAG('L', '5', '5', '5') },
00078 { AV_CODEC_ID_RAWVIDEO, MKTAG('L', '5', '6', '5') },
00079 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '5', '6', '5') },
00080 { AV_CODEC_ID_RAWVIDEO, MKTAG('2', '4', 'B', 'G') },
00081 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 'A') },
00082 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 'A') },
00083 { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'B', 'G', 'R') },
00084 { AV_CODEC_ID_RAWVIDEO, MKTAG('b', '1', '6', 'g') },
00085 { AV_CODEC_ID_RAWVIDEO, MKTAG('b', '4', '8', 'r') },
00086 { AV_CODEC_ID_RAWVIDEO, MKTAG('b', 'x', 'b', 'g') },
00087 { AV_CODEC_ID_RAWVIDEO, MKTAG('b', 'x', 'r', 'g') },
00088 { AV_CODEC_ID_RAWVIDEO, MKTAG('b', 'x', 'y', 'v') },
00089 { AV_CODEC_ID_RAWVIDEO, MKTAG('N', 'O', '1', '6') },
00090 { AV_CODEC_ID_RAWVIDEO, MKTAG('D', 'V', 'O', 'O') },
00091 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', '4', '2', '0') },
00092 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', '4', '1', '1') },
00093
00094 { AV_CODEC_ID_R10K, MKTAG('R', '1', '0', 'k') },
00095 { AV_CODEC_ID_R10K, MKTAG('R', '1', '0', 'g') },
00096 { AV_CODEC_ID_R210, MKTAG('r', '2', '1', '0') },
00097 { AV_CODEC_ID_AVUI, MKTAG('A', 'V', 'U', 'I') },
00098 { AV_CODEC_ID_AVRP, MKTAG('A', 'V', 'r', 'p') },
00099 { AV_CODEC_ID_AVRP, MKTAG('S', 'U', 'D', 'S') },
00100 { AV_CODEC_ID_V210, MKTAG('v', '2', '1', '0') },
00101 { AV_CODEC_ID_V210, MKTAG('b', 'x', 'y', '2') },
00102 { AV_CODEC_ID_V308, MKTAG('v', '3', '0', '8') },
00103 { AV_CODEC_ID_V408, MKTAG('v', '4', '0', '8') },
00104 { AV_CODEC_ID_V410, MKTAG('v', '4', '1', '0') },
00105 { AV_CODEC_ID_Y41P, MKTAG('Y', '4', '1', 'P') },
00106 { AV_CODEC_ID_YUV4, MKTAG('y', 'u', 'v', '4') },
00107
00108 { AV_CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') },
00109 { AV_CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') },
00110 { AV_CODEC_ID_MJPEG, MKTAG('A', 'V', 'D', 'J') },
00111
00112 { AV_CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') },
00113 { AV_CODEC_ID_MJPEGB, MKTAG('m', 'j', 'p', 'b') },
00114
00115 { AV_CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') },
00116 { AV_CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') },
00117 { AV_CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') },
00118 { AV_CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
00119
00120 { AV_CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
00121 { AV_CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') },
00122 { AV_CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
00123 { AV_CODEC_ID_MPEG4, MKTAG('3', 'I', 'V', '2') },
00124
00125 { AV_CODEC_ID_H263, MKTAG('h', '2', '6', '3') },
00126 { AV_CODEC_ID_H263, MKTAG('s', '2', '6', '3') },
00127
00128 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 'p') },
00129 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
00130 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'p', 'p') },
00131 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', 'p') },
00132 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', 'n') },
00133 { AV_CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') },
00134 { AV_CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', '1') },
00135 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'q') },
00136 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'p') },
00137 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '1') },
00138 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '2') },
00139 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '4') },
00140 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '5') },
00141 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '6') },
00142 { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '3') },
00143
00144 { AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
00145 { AV_CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') },
00146 { AV_CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') },
00147 { AV_CODEC_ID_8BPS, MKTAG('8', 'B', 'P', 'S') },
00148 { AV_CODEC_ID_SMC, MKTAG('s', 'm', 'c', ' ') },
00149 { AV_CODEC_ID_QTRLE, MKTAG('r', 'l', 'e', ' ') },
00150 { AV_CODEC_ID_MSRLE, MKTAG('W', 'R', 'L', 'E') },
00151 { AV_CODEC_ID_QDRAW, MKTAG('q', 'd', 'r', 'w') },
00152
00153 { AV_CODEC_ID_RAWVIDEO, MKTAG('W', 'R', 'A', 'W') },
00154
00155 { AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
00156 { AV_CODEC_ID_H264, MKTAG('a', 'i', '5', 'p') },
00157 { AV_CODEC_ID_H264, MKTAG('a', 'i', '5', 'q') },
00158 { AV_CODEC_ID_H264, MKTAG('a', 'i', '5', '2') },
00159 { AV_CODEC_ID_H264, MKTAG('a', 'i', '5', '3') },
00160 { AV_CODEC_ID_H264, MKTAG('a', 'i', '5', '5') },
00161 { AV_CODEC_ID_H264, MKTAG('a', 'i', '5', '6') },
00162 { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', 'p') },
00163 { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', 'q') },
00164 { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', '2') },
00165 { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', '3') },
00166 { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', '5') },
00167 { AV_CODEC_ID_H264, MKTAG('a', 'i', '1', '6') },
00168
00169 { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', '1') },
00170 { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') },
00171 { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', ' ') },
00172 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', '2', 'v', '1') },
00173 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '1') },
00174 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') },
00175 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '3') },
00176 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '4') },
00177 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '5') },
00178 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '6') },
00179 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '7') },
00180 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '8') },
00181 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '9') },
00182 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', 'a') },
00183 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'n') },
00184 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'p') },
00185 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '4', 'n') },
00186 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '4', 'p') },
00187 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'n') },
00188 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'p') },
00189 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '4') },
00190 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '5') },
00191 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '9') },
00192 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'a') },
00193 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'b') },
00194 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'c') },
00195 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'd') },
00196 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'e') },
00197 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'f') },
00198 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '1') },
00199 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '2') },
00200 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '3') },
00201 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '4') },
00202 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '5') },
00203 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '6') },
00204 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '7') },
00205 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '8') },
00206 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '9') },
00207 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'a') },
00208 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'b') },
00209 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'c') },
00210 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'd') },
00211 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'e') },
00212 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'f') },
00213 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'h', 'd') },
00214 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'h', '2') },
00215 { AV_CODEC_ID_MPEG2VIDEO, MKTAG('A', 'V', 'm', 'p') },
00216
00217 { AV_CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') },
00218
00219 { AV_CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') },
00220 { AV_CODEC_ID_TIFF, MKTAG('t', 'i', 'f', 'f') },
00221 { AV_CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') },
00222 { AV_CODEC_ID_PNG, MKTAG('p', 'n', 'g', ' ') },
00223 { AV_CODEC_ID_PNG, MKTAG('M', 'N', 'G', ' ') },
00224
00225 { AV_CODEC_ID_VC1, MKTAG('v', 'c', '-', '1') },
00226 { AV_CODEC_ID_CAVS, MKTAG('a', 'v', 's', '2') },
00227
00228 { AV_CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') },
00229 { AV_CODEC_ID_DNXHD, MKTAG('A', 'V', 'd', 'n') },
00230
00231 { AV_CODEC_ID_MSMPEG4V3, MKTAG('3', 'I', 'V', 'D') },
00232 { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'V', '1', 'x') },
00233 { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'u', 'p') },
00234 { AV_CODEC_ID_SGI, MKTAG('s', 'g', 'i', ' ') },
00235 { AV_CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') },
00236 { AV_CODEC_ID_EXR, MKTAG('e', 'x', 'r', ' ') },
00237
00238 { AV_CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'h') },
00239 { AV_CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'n') },
00240 { AV_CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 's') },
00241 { AV_CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'o') },
00242 { AV_CODEC_ID_PRORES, MKTAG('a', 'p', '4', 'h') },
00243 { AV_CODEC_ID_FLIC, MKTAG('f', 'l', 'i', 'c') },
00244
00245 { AV_CODEC_ID_NONE, 0 },
00246 };
00247
00248 const AVCodecTag ff_codec_movaudio_tags[] = {
00249 { AV_CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') },
00250 { AV_CODEC_ID_AC3, MKTAG('a', 'c', '-', '3') },
00251 { AV_CODEC_ID_AC3, MKTAG('s', 'a', 'c', '3') },
00252 { AV_CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') },
00253 { AV_CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') },
00254 { AV_CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') },
00255 { AV_CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') },
00256 { AV_CODEC_ID_DTS, MKTAG('d', 't', 's', 'c') },
00257 { AV_CODEC_ID_DTS, MKTAG('d', 't', 's', 'h') },
00258 { AV_CODEC_ID_DTS, MKTAG('d', 't', 's', 'l') },
00259 { AV_CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') },
00260 { AV_CODEC_ID_EAC3, MKTAG('e', 'c', '-', '3') },
00261 { AV_CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') },
00262 { AV_CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') },
00263 { AV_CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') },
00264 { AV_CODEC_ID_ILBC, MKTAG('i', 'l', 'b', 'c') },
00265 { AV_CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') },
00266 { AV_CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') },
00267 { AV_CODEC_ID_MP1, MKTAG('.', 'm', 'p', '1') },
00268 { AV_CODEC_ID_MP2, MKTAG('.', 'm', 'p', '2') },
00269 { AV_CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') },
00270 { AV_CODEC_ID_MP3, 0x6D730055 },
00271 { AV_CODEC_ID_NELLYMOSER, MKTAG('n', 'm', 'o', 's') },
00272 { AV_CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') },
00273 { AV_CODEC_ID_PCM_F32BE, MKTAG('f', 'l', '3', '2') },
00274 { AV_CODEC_ID_PCM_F32LE, MKTAG('f', 'l', '3', '2') },
00275 { AV_CODEC_ID_PCM_F64BE, MKTAG('f', 'l', '6', '4') },
00276 { AV_CODEC_ID_PCM_F64LE, MKTAG('f', 'l', '6', '4') },
00277 { AV_CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') },
00278 { AV_CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') },
00279 { AV_CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') },
00280 { AV_CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') },
00281 { AV_CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') },
00282 { AV_CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') },
00283 { AV_CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') },
00284 { AV_CODEC_ID_PCM_S32LE, MKTAG('i', 'n', '3', '2') },
00285 { AV_CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') },
00286 { AV_CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') },
00287 { AV_CODEC_ID_PCM_U8, MKTAG('N', 'O', 'N', 'E') },
00288 { AV_CODEC_ID_QCELP, MKTAG('Q', 'c', 'l', 'p') },
00289 { AV_CODEC_ID_QCELP, MKTAG('Q', 'c', 'l', 'q') },
00290 { AV_CODEC_ID_QCELP, MKTAG('s', 'q', 'c', 'p') },
00291 { AV_CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2') },
00292 { AV_CODEC_ID_QDMC, MKTAG('Q', 'D', 'M', 'C') },
00293 { AV_CODEC_ID_SPEEX, MKTAG('s', 'p', 'e', 'x') },
00294 { AV_CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') },
00295 { AV_CODEC_ID_NONE, 0 },
00296 };
00297
00298 const AVCodecTag ff_codec_movsubtitle_tags[] = {
00299 { AV_CODEC_ID_MOV_TEXT, MKTAG('t', 'e', 'x', 't') },
00300 { AV_CODEC_ID_MOV_TEXT, MKTAG('t', 'x', '3', 'g') },
00301 { AV_CODEC_ID_EIA_608, MKTAG('c', '6', '0', '8') },
00302 { AV_CODEC_ID_NONE, 0 },
00303 };
00304
00305
00306
00307
00308
00309 static const char mov_mdhd_language_map[][4] = {
00310
00311 "eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor",
00312 "heb", "jpn", "ara", "fin", "gre", "ice", "mlt", "tur", "hr ", "chi",
00313 "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav", "",
00314 "fo ", "", "rus", "chi", "", "iri", "alb", "ron", "ces", "slk",
00315 "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze",
00316
00317 "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", "", "pus",
00318 "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj",
00319 "pa ", "ori", "mal", "kan", "tam", "tel", "", "bur", "khm", "lao",
00320
00321 "vie", "ind", "tgl", "may", "may", "amh", "tir", "orm", "som", "swa",
00322
00323 "", "run", "", "mlg", "epo", "", "", "", "", "",
00324
00325 "", "", "", "", "", "", "", "", "", "",
00326 "", "", "", "", "", "", "", "", "", "",
00327 "", "", "", "", "", "", "", "", "wel", "baq",
00328 "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
00329 };
00330
00331 int ff_mov_iso639_to_lang(const char lang[4], int mp4)
00332 {
00333 int i, code = 0;
00334
00335
00336 for (i = 0; lang[0] && !mp4 && i < FF_ARRAY_ELEMS(mov_mdhd_language_map); i++) {
00337 if (!strcmp(lang, mov_mdhd_language_map[i]))
00338 return i;
00339 }
00340
00341 if (!mp4)
00342 return -1;
00343
00344 if (lang[0] == '\0')
00345 lang = "und";
00346
00347 for (i = 0; i < 3; i++) {
00348 uint8_t c = lang[i];
00349 c -= 0x60;
00350 if (c > 0x1f)
00351 return -1;
00352 code <<= 5;
00353 code |= c;
00354 }
00355 return code;
00356 }
00357
00358 int ff_mov_lang_to_iso639(unsigned code, char to[4])
00359 {
00360 int i;
00361 memset(to, 0, 4);
00362
00363
00364 if (code >= 0x400 && code != 0x7fff) {
00365 for (i = 2; i >= 0; i--) {
00366 to[i] = 0x60 + (code & 0x1f);
00367 code >>= 5;
00368 }
00369 return 1;
00370 }
00371
00372 if (code >= FF_ARRAY_ELEMS(mov_mdhd_language_map))
00373 return 0;
00374 if (!mov_mdhd_language_map[code][0])
00375 return 0;
00376 memcpy(to, mov_mdhd_language_map[code], 4);
00377 return 1;
00378 }
00379
00380 int ff_mp4_read_descr_len(AVIOContext *pb)
00381 {
00382 int len = 0;
00383 int count = 4;
00384 while (count--) {
00385 int c = avio_r8(pb);
00386 len = (len << 7) | (c & 0x7f);
00387 if (!(c & 0x80))
00388 break;
00389 }
00390 return len;
00391 }
00392
00393 int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag)
00394 {
00395 int len;
00396 *tag = avio_r8(pb);
00397 len = ff_mp4_read_descr_len(pb);
00398 av_dlog(fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
00399 return len;
00400 }
00401
00402 void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
00403 {
00404 int flags;
00405 if (es_id) *es_id = avio_rb16(pb);
00406 else avio_rb16(pb);
00407 flags = avio_r8(pb);
00408 if (flags & 0x80)
00409 avio_rb16(pb);
00410 if (flags & 0x40) {
00411 int len = avio_r8(pb);
00412 avio_skip(pb, len);
00413 }
00414 if (flags & 0x20)
00415 avio_rb16(pb);
00416 }
00417
00418 static const AVCodecTag mp4_audio_types[] = {
00419 { AV_CODEC_ID_MP3ON4, AOT_PS },
00420 { AV_CODEC_ID_MP3ON4, AOT_L1 },
00421 { AV_CODEC_ID_MP3ON4, AOT_L2 },
00422 { AV_CODEC_ID_MP3ON4, AOT_L3 },
00423 { AV_CODEC_ID_MP4ALS, AOT_ALS },
00424 { AV_CODEC_ID_NONE, AOT_NULL },
00425 };
00426
00427 int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
00428 {
00429 int len, tag;
00430 int object_type_id = avio_r8(pb);
00431 avio_r8(pb);
00432 avio_rb24(pb);
00433 avio_rb32(pb);
00434 avio_rb32(pb);
00435
00436 st->codec->codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id);
00437 av_dlog(fc, "esds object type id 0x%02x\n", object_type_id);
00438 len = ff_mp4_read_descr(fc, pb, &tag);
00439 if (tag == MP4DecSpecificDescrTag) {
00440 av_dlog(fc, "Specific MPEG4 header len=%d\n", len);
00441 if (!len || (uint64_t)len > (1<<30))
00442 return -1;
00443 av_free(st->codec->extradata);
00444 st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
00445 if (!st->codec->extradata)
00446 return AVERROR(ENOMEM);
00447 avio_read(pb, st->codec->extradata, len);
00448 st->codec->extradata_size = len;
00449 if (st->codec->codec_id == AV_CODEC_ID_AAC) {
00450 MPEG4AudioConfig cfg;
00451 avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata,
00452 st->codec->extradata_size * 8, 1);
00453 st->codec->channels = cfg.channels;
00454 if (cfg.object_type == 29 && cfg.sampling_index < 3)
00455 st->codec->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index];
00456 else if (cfg.ext_sample_rate)
00457 st->codec->sample_rate = cfg.ext_sample_rate;
00458 else
00459 st->codec->sample_rate = cfg.sample_rate;
00460 av_dlog(fc, "mp4a config channels %d obj %d ext obj %d "
00461 "sample rate %d ext sample rate %d\n", st->codec->channels,
00462 cfg.object_type, cfg.ext_object_type,
00463 cfg.sample_rate, cfg.ext_sample_rate);
00464 if (!(st->codec->codec_id = ff_codec_get_id(mp4_audio_types,
00465 cfg.object_type)))
00466 st->codec->codec_id = AV_CODEC_ID_AAC;
00467 }
00468 }
00469 return 0;
00470 }
00471
00472 typedef struct MovChannelLayout {
00473 int64_t channel_layout;
00474 uint32_t layout_tag;
00475 } MovChannelLayout;
00476
00477 static const MovChannelLayout mov_channel_layout[] = {
00478 { AV_CH_LAYOUT_MONO, (100<<16) | 1},
00479 { AV_CH_LAYOUT_STEREO, (101<<16) | 2},
00480 { AV_CH_LAYOUT_STEREO, (102<<16) | 2},
00481 { AV_CH_LAYOUT_2_1, (131<<16) | 3},
00482 { AV_CH_LAYOUT_QUAD, (132<<16) | 4},
00483 { AV_CH_LAYOUT_2_2, (132<<16) | 4},
00484 { AV_CH_LAYOUT_QUAD, (108<<16) | 4},
00485 { AV_CH_LAYOUT_SURROUND, (113<<16) | 3},
00486 { AV_CH_LAYOUT_4POINT0, (115<<16) | 4},
00487 { AV_CH_LAYOUT_5POINT0_BACK, (117<<16) | 5},
00488 { AV_CH_LAYOUT_5POINT0, (117<<16) | 5},
00489 { AV_CH_LAYOUT_5POINT1_BACK, (121<<16) | 6},
00490 { AV_CH_LAYOUT_5POINT1, (121<<16) | 6},
00491 { AV_CH_LAYOUT_7POINT1, (128<<16) | 8},
00492 { AV_CH_LAYOUT_7POINT1_WIDE, (126<<16) | 8},
00493 { AV_CH_LAYOUT_5POINT1_BACK|AV_CH_LAYOUT_STEREO_DOWNMIX, (130<<16) | 8},
00494 { AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, (133<<16) | 3},
00495 { AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY, (134<<16) | 4},
00496 { AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY, (135<<16) | 4},
00497 { AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY, (135<<16) | 4},
00498 { AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, (136<<16) | 4},
00499 { AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, (137<<16) | 5},
00500 { 0, 0},
00501 };
00502 #if 0
00503 int ff_mov_read_chan(AVFormatContext *s, AVStream *st, int64_t size)
00504 {
00505 AVCodecContext *codec= st->codec;
00506 uint32_t layout_tag;
00507 AVIOContext *pb = s->pb;
00508 const MovChannelLayout *layouts = mov_channel_layout;
00509
00510 if (size < 12)
00511 return AVERROR_INVALIDDATA;
00512
00513 layout_tag = avio_rb32(pb);
00514 size -= 4;
00515 if (layout_tag == 0) {
00516
00517 av_log_ask_for_sample(s, "Unimplemented container channel layout.\n");
00518 avio_skip(pb, size);
00519 return 0;
00520 }
00521 if (layout_tag == 0x10000) {
00522 codec->channel_layout = avio_rb32(pb);
00523 size -= 4;
00524 avio_skip(pb, size);
00525 return 0;
00526 }
00527 while (layouts->channel_layout) {
00528 if (layout_tag == layouts->layout_tag) {
00529 codec->channel_layout = layouts->channel_layout;
00530 break;
00531 }
00532 layouts++;
00533 }
00534 if (!codec->channel_layout)
00535 av_log(s, AV_LOG_WARNING, "Unknown container channel layout.\n");
00536 avio_skip(pb, size);
00537
00538 return 0;
00539 }
00540 #endif
00541
00542 void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout)
00543 {
00544 const MovChannelLayout *layouts;
00545 uint32_t layout_tag = 0;
00546
00547 for (layouts = mov_channel_layout; layouts->channel_layout; layouts++)
00548 if (channel_layout == layouts->channel_layout) {
00549 layout_tag = layouts->layout_tag;
00550 break;
00551 }
00552
00553 if (layout_tag) {
00554 avio_wb32(pb, layout_tag);
00555 avio_wb32(pb, 0);
00556 } else {
00557 avio_wb32(pb, 0x10000);
00558 avio_wb32(pb, channel_layout);
00559 }
00560 avio_wb32(pb, 0);
00561 }
00562