00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/mathematics.h"
00023 #include "libavcodec/avcodec.h"
00024 #include "avformat.h"
00025 #include "avio_internal.h"
00026 #include "riff.h"
00027 #include "libavcodec/bytestream.h"
00028
00029
00030
00031 const AVCodecTag ff_codec_bmp_tags[] = {
00032 { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
00033 { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
00034 { CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
00035 { CODEC_ID_H264, MKTAG('x', '2', '6', '4') },
00036 { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
00037 { CODEC_ID_H264, MKTAG('D', 'A', 'V', 'C') },
00038 { CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') },
00039 { CODEC_ID_H264, MKTAG('Q', '2', '6', '4') },
00040 { CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
00041 { CODEC_ID_H263, MKTAG('X', '2', '6', '3') },
00042 { CODEC_ID_H263, MKTAG('T', '2', '6', '3') },
00043 { CODEC_ID_H263, MKTAG('L', '2', '6', '3') },
00044 { CODEC_ID_H263, MKTAG('V', 'X', '1', 'K') },
00045 { CODEC_ID_H263, MKTAG('Z', 'y', 'G', 'o') },
00046 { CODEC_ID_H263, MKTAG('M', '2', '6', '3') },
00047 { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') },
00048 { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') },
00049 { CODEC_ID_H261, MKTAG('H', '2', '6', '1') },
00050 { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') },
00051 { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') },
00052 { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4') },
00053 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') },
00054 { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0') },
00055 { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
00056 { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
00057 { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
00058 { CODEC_ID_MPEG4, MKTAG( 4 , 0 , 0 , 0 ) },
00059 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') },
00060 { CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') },
00061 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
00062 { CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') },
00063 { CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') },
00064 { CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') },
00065 { CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
00066 { CODEC_ID_MPEG4, MKTAG('3', 'I', 'V', '2') },
00067 { CODEC_ID_MPEG4, MKTAG('W', 'A', 'W', 'V') },
00068 { CODEC_ID_MPEG4, MKTAG('F', 'F', 'D', 'S') },
00069 { CODEC_ID_MPEG4, MKTAG('F', 'V', 'F', 'W') },
00070 { CODEC_ID_MPEG4, MKTAG('D', 'C', 'O', 'D') },
00071 { CODEC_ID_MPEG4, MKTAG('M', 'V', 'X', 'M') },
00072 { CODEC_ID_MPEG4, MKTAG('P', 'M', '4', 'V') },
00073 { CODEC_ID_MPEG4, MKTAG('S', 'M', 'P', '4') },
00074 { CODEC_ID_MPEG4, MKTAG('D', 'X', 'G', 'M') },
00075 { CODEC_ID_MPEG4, MKTAG('V', 'I', 'D', 'M') },
00076 { CODEC_ID_MPEG4, MKTAG('M', '4', 'T', '3') },
00077 { CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'X') },
00078 { CODEC_ID_MPEG4, MKTAG('H', 'D', 'X', '4') },
00079 { CODEC_ID_MPEG4, MKTAG('D', 'M', 'K', '2') },
00080 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'G', 'I') },
00081 { CODEC_ID_MPEG4, MKTAG('I', 'N', 'M', 'C') },
00082 { CODEC_ID_MPEG4, MKTAG('E', 'P', 'H', 'V') },
00083 { CODEC_ID_MPEG4, MKTAG('E', 'M', '4', 'A') },
00084 { CODEC_ID_MPEG4, MKTAG('M', '4', 'C', 'C') },
00085 { CODEC_ID_MPEG4, MKTAG('S', 'N', '4', '0') },
00086 { CODEC_ID_MPEG4, MKTAG('V', 'S', 'P', 'X') },
00087 { CODEC_ID_MPEG4, MKTAG('U', 'L', 'D', 'X') },
00088 { CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'V') },
00089 { CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') },
00090 { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'X') },
00091 { CODEC_ID_MPEG4, MKTAG('D', 'r', 'e', 'X') },
00092 { CODEC_ID_MPEG4, MKTAG('Q', 'M', 'P', '4') },
00093 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
00094 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') },
00095 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
00096 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
00097 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') },
00098 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') },
00099 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'V', 'X', '3') },
00100 { CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') },
00101 { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') },
00102 { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') },
00103 { CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') },
00104 { CODEC_ID_MSMPEG4V2, MKTAG('D', 'I', 'V', '2') },
00105 { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') },
00106 { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', '4', '1') },
00107 { CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
00108 { CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') },
00109 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') },
00110 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') },
00111 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '1') },
00112 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') },
00113 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') },
00114 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', '0') },
00115 { CODEC_ID_DVVIDEO, MKTAG('c', 'd', 'v', 'c') },
00116 { CODEC_ID_DVVIDEO, MKTAG('C', 'D', 'V', 'H') },
00117 { CODEC_ID_DVVIDEO, MKTAG('C', 'D', 'V', '5') },
00118 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
00119 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 's') },
00120 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '1') },
00121 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') },
00122 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') },
00123 { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', '2') },
00124 { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'E', 'G') },
00125 { CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
00126 { CODEC_ID_MPEG2VIDEO, MKTAG('P', 'I', 'M', '2') },
00127 { CODEC_ID_MPEG1VIDEO, MKTAG('V', 'C', 'R', '2') },
00128 { CODEC_ID_MPEG1VIDEO, MKTAG( 1 , 0 , 0 , 16) },
00129 { CODEC_ID_MPEG2VIDEO, MKTAG( 2 , 0 , 0 , 16) },
00130 { CODEC_ID_MPEG4, MKTAG( 4 , 0 , 0 , 16) },
00131 { CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') },
00132 { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'M', 'E', 'S') },
00133 { CODEC_ID_MPEG2VIDEO, MKTAG('L', 'M', 'P', '2') },
00134 { CODEC_ID_MPEG2VIDEO, MKTAG('s', 'l', 'i', 'f') },
00135 { CODEC_ID_MPEG2VIDEO, MKTAG('E', 'M', '2', 'V') },
00136 { CODEC_ID_MPEG2VIDEO, MKTAG('M', '7', '0', '1') },
00137 { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', 'v') },
00138 { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
00139 { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') },
00140 { CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') },
00141 { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') },
00142 { CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') },
00143 { CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') },
00144 { CODEC_ID_JPEGLS, MKTAG('M', 'J', 'L', 'S') },
00145 { CODEC_ID_JPEGLS, MKTAG('M', 'J', 'P', 'G') },
00146 { CODEC_ID_MJPEG, MKTAG('M', 'J', 'L', 'S') },
00147 { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') },
00148 { CODEC_ID_MJPEG, MKTAG('I', 'J', 'P', 'G') },
00149 { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') },
00150 { CODEC_ID_MJPEG, MKTAG('A', 'C', 'D', 'V') },
00151 { CODEC_ID_MJPEG, MKTAG('Q', 'I', 'V', 'G') },
00152 { CODEC_ID_MJPEG, MKTAG('S', 'L', 'M', 'J') },
00153 { CODEC_ID_MJPEG, MKTAG('C', 'J', 'P', 'G') },
00154 { CODEC_ID_MJPEG, MKTAG('I', 'J', 'L', 'V') },
00155 { CODEC_ID_MJPEG, MKTAG('M', 'V', 'J', 'P') },
00156 { CODEC_ID_MJPEG, MKTAG('A', 'V', 'I', '1') },
00157 { CODEC_ID_MJPEG, MKTAG('A', 'V', 'I', '2') },
00158 { CODEC_ID_MJPEG, MKTAG('M', 'T', 'S', 'J') },
00159 { CODEC_ID_MJPEG, MKTAG('Z', 'J', 'P', 'G') },
00160 { CODEC_ID_MJPEG, MKTAG('M', 'M', 'J', 'P') },
00161 { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') },
00162 { CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') },
00163 { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') },
00164 { CODEC_ID_RAWVIDEO, MKTAG( 0 , 0 , 0 , 0 ) },
00165 { CODEC_ID_RAWVIDEO, MKTAG( 3 , 0 , 0 , 0 ) },
00166 { CODEC_ID_RAWVIDEO, MKTAG('I', '4', '2', '0') },
00167 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'Y', '2') },
00168 { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', '2') },
00169 { CODEC_ID_RAWVIDEO, MKTAG('V', '4', '2', '2') },
00170 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'N', 'V') },
00171 { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'N', 'V') },
00172 { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'N', 'Y') },
00173 { CODEC_ID_RAWVIDEO, MKTAG('u', 'y', 'v', '1') },
00174 { CODEC_ID_RAWVIDEO, MKTAG('2', 'V', 'u', '1') },
00175 { CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') },
00176 { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') },
00177 { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', '2') },
00178 { CODEC_ID_RAWVIDEO, MKTAG('P', '4', '2', '2') },
00179 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') },
00180 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '6') },
00181 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '2', '4') },
00182 { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') },
00183 { CODEC_ID_RAWVIDEO, MKTAG('V', 'Y', 'U', 'Y') },
00184 { CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') },
00185 { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') },
00186 { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', ' ', ' ') },
00187 { CODEC_ID_RAWVIDEO, MKTAG('H', 'D', 'Y', 'C') },
00188 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') },
00189 { CODEC_ID_RAWVIDEO, MKTAG('V', 'D', 'T', 'Z') },
00190 { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '1', '1') },
00191 { CODEC_ID_RAWVIDEO, MKTAG('N', 'V', '1', '2') },
00192 { CODEC_ID_RAWVIDEO, MKTAG('N', 'V', '2', '1') },
00193 { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '1', 'B') },
00194 { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', 'B') },
00195 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'V', '9') },
00196 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') },
00197 { CODEC_ID_RAWVIDEO, MKTAG('a', 'u', 'v', '2') },
00198 { CODEC_ID_FRWU, MKTAG('F', 'R', 'W', 'U') },
00199 { CODEC_ID_R10K, MKTAG('R', '1', '0', 'k') },
00200 { CODEC_ID_R210, MKTAG('r', '2', '1', '0') },
00201 { CODEC_ID_V210, MKTAG('v', '2', '1', '0') },
00202 { CODEC_ID_V410, MKTAG('v', '4', '1', '0') },
00203 { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') },
00204 { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') },
00205 { CODEC_ID_INDEO4, MKTAG('I', 'V', '4', '1') },
00206 { CODEC_ID_INDEO5, MKTAG('I', 'V', '5', '0') },
00207 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
00208 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
00209 { CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
00210 { CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') },
00211 { CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') },
00212 { CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') },
00213 { CODEC_ID_VP6F, MKTAG('V', 'P', '6', 'F') },
00214 { CODEC_ID_VP6F, MKTAG('F', 'L', 'V', '4') },
00215 { CODEC_ID_VP8, MKTAG('V', 'P', '8', '0') },
00216 { CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') },
00217 { CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
00218 { CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
00219 { CODEC_ID_FFV1, MKTAG('F', 'F', 'V', '1') },
00220 { CODEC_ID_XAN_WC4, MKTAG('X', 'x', 'a', 'n') },
00221 { CODEC_ID_MIMIC, MKTAG('L', 'M', '2', '0') },
00222 { CODEC_ID_MSRLE, MKTAG('m', 'r', 'l', 'e') },
00223 { CODEC_ID_MSRLE, MKTAG( 1 , 0 , 0 , 0 ) },
00224 { CODEC_ID_MSRLE, MKTAG( 2 , 0 , 0 , 0 ) },
00225 { CODEC_ID_MSVIDEO1, MKTAG('M', 'S', 'V', 'C') },
00226 { CODEC_ID_MSVIDEO1, MKTAG('m', 's', 'v', 'c') },
00227 { CODEC_ID_MSVIDEO1, MKTAG('C', 'R', 'A', 'M') },
00228 { CODEC_ID_MSVIDEO1, MKTAG('c', 'r', 'a', 'm') },
00229 { CODEC_ID_MSVIDEO1, MKTAG('W', 'H', 'A', 'M') },
00230 { CODEC_ID_MSVIDEO1, MKTAG('w', 'h', 'a', 'm') },
00231 { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') },
00232 { CODEC_ID_TRUEMOTION1, MKTAG('D', 'U', 'C', 'K') },
00233 { CODEC_ID_TRUEMOTION1, MKTAG('P', 'V', 'E', 'Z') },
00234 { CODEC_ID_MSZH, MKTAG('M', 'S', 'Z', 'H') },
00235 { CODEC_ID_ZLIB, MKTAG('Z', 'L', 'I', 'B') },
00236 { CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') },
00237 { CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') },
00238 { CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') },
00239 { CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') },
00240 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') },
00241 { CODEC_ID_TSCC, MKTAG('t', 's', 'c', 'c') },
00242 { CODEC_ID_ULTI, MKTAG('U', 'L', 'T', 'I') },
00243 { CODEC_ID_VIXL, MKTAG('V', 'I', 'X', 'L') },
00244 { CODEC_ID_QPEG, MKTAG('Q', 'P', 'E', 'G') },
00245 { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '0') },
00246 { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') },
00247 { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
00248 { CODEC_ID_WMV3IMAGE, MKTAG('W', 'M', 'V', 'P') },
00249 { CODEC_ID_VC1, MKTAG('W', 'V', 'C', '1') },
00250 { CODEC_ID_VC1, MKTAG('W', 'M', 'V', 'A') },
00251 { CODEC_ID_VC1IMAGE, MKTAG('W', 'V', 'P', '2') },
00252 { CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') },
00253 { CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') },
00254 { CODEC_ID_AASC, MKTAG('A', 'A', 'S', 'C') },
00255 { CODEC_ID_INDEO2, MKTAG('R', 'T', '2', '1') },
00256 { CODEC_ID_FRAPS, MKTAG('F', 'P', 'S', '1') },
00257 { CODEC_ID_THEORA, MKTAG('t', 'h', 'e', 'o') },
00258 { CODEC_ID_TRUEMOTION2, MKTAG('T', 'M', '2', '0') },
00259 { CODEC_ID_CSCD, MKTAG('C', 'S', 'C', 'D') },
00260 { CODEC_ID_ZMBV, MKTAG('Z', 'M', 'B', 'V') },
00261 { CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') },
00262 { CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') },
00263 { CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') },
00264 { CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') },
00265 { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'C') },
00266 { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'K') },
00267 { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') },
00268 { CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') },
00269 { CODEC_ID_PNG, MKTAG('M', 'P', 'N', 'G') },
00270 { CODEC_ID_PNG, MKTAG('P', 'N', 'G', '1') },
00271 { CODEC_ID_CLJR, MKTAG('C', 'L', 'J', 'R') },
00272 { CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') },
00273 { CODEC_ID_RPZA, MKTAG('a', 'z', 'p', 'r') },
00274 { CODEC_ID_RPZA, MKTAG('R', 'P', 'Z', 'A') },
00275 { CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') },
00276 { CODEC_ID_SP5X, MKTAG('S', 'P', '5', '4') },
00277 { CODEC_ID_AURA, MKTAG('A', 'U', 'R', 'A') },
00278 { CODEC_ID_AURA2, MKTAG('A', 'U', 'R', '2') },
00279 { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') },
00280 { CODEC_ID_KGV1, MKTAG('K', 'G', 'V', '1') },
00281 { CODEC_ID_LAGARITH, MKTAG('L', 'A', 'G', 'S') },
00282 { CODEC_ID_G2M, MKTAG('G', '2', 'M', '2') },
00283 { CODEC_ID_G2M, MKTAG('G', '2', 'M', '3') },
00284 { CODEC_ID_G2M, MKTAG('G', '2', 'M', '4') },
00285 { CODEC_ID_AMV, MKTAG('A', 'M', 'V', 'F') },
00286 { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'A') },
00287 { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'G') },
00288 { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '0') },
00289 { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '2') },
00290 { CODEC_ID_VBLE, MKTAG('V', 'B', 'L', 'E') },
00291 { CODEC_ID_ESCAPE130, MKTAG('E', '1', '3', '0') },
00292 { CODEC_ID_DXTORY, MKTAG('x', 't', 'o', 'r') },
00293 { CODEC_ID_Y41P, MKTAG('Y', '4', '1', 'P') },
00294 { CODEC_ID_NONE, 0 }
00295 };
00296
00297 const AVCodecTag ff_codec_wav_tags[] = {
00298 { CODEC_ID_PCM_S16LE, 0x0001 },
00299 { CODEC_ID_PCM_U8, 0x0001 },
00300 { CODEC_ID_PCM_S24LE, 0x0001 },
00301 { CODEC_ID_PCM_S32LE, 0x0001 },
00302 { CODEC_ID_ADPCM_MS, 0x0002 },
00303 { CODEC_ID_PCM_F32LE, 0x0003 },
00304 { CODEC_ID_PCM_F64LE, 0x0003 },
00305 { CODEC_ID_PCM_ALAW, 0x0006 },
00306 { CODEC_ID_PCM_MULAW, 0x0007 },
00307 { CODEC_ID_WMAVOICE, 0x000A },
00308 { CODEC_ID_ADPCM_IMA_WAV, 0x0011 },
00309 { CODEC_ID_PCM_ZORK, 0x0011 },
00310 { CODEC_ID_ADPCM_YAMAHA, 0x0020 },
00311 { CODEC_ID_TRUESPEECH, 0x0022 },
00312 { CODEC_ID_GSM_MS, 0x0031 },
00313 { CODEC_ID_AMR_NB, 0x0038 },
00314 { CODEC_ID_ADPCM_G726, 0x0045 },
00315 { CODEC_ID_MP2, 0x0050 },
00316 { CODEC_ID_MP3, 0x0055 },
00317 { CODEC_ID_AMR_NB, 0x0057 },
00318 { CODEC_ID_AMR_WB, 0x0058 },
00319 { CODEC_ID_ADPCM_IMA_DK4, 0x0061 },
00320 { CODEC_ID_ADPCM_IMA_DK3, 0x0062 },
00321 { CODEC_ID_ADPCM_IMA_WAV, 0x0069 },
00322 { CODEC_ID_VOXWARE, 0x0075 },
00323 { CODEC_ID_AAC, 0x00ff },
00324 { CODEC_ID_SIPR, 0x0130 },
00325 { CODEC_ID_WMAV1, 0x0160 },
00326 { CODEC_ID_WMAV2, 0x0161 },
00327 { CODEC_ID_WMAPRO, 0x0162 },
00328 { CODEC_ID_WMALOSSLESS, 0x0163 },
00329 { CODEC_ID_ADPCM_CT, 0x0200 },
00330 { CODEC_ID_ATRAC3, 0x0270 },
00331 { CODEC_ID_ADPCM_G722, 0x028F },
00332 { CODEC_ID_IMC, 0x0401 },
00333 { CODEC_ID_GSM_MS, 0x1500 },
00334 { CODEC_ID_TRUESPEECH, 0x1501 },
00335 { CODEC_ID_AAC, 0x1600 },
00336 { CODEC_ID_AAC_LATM, 0x1602 },
00337 { CODEC_ID_AC3, 0x2000 },
00338 { CODEC_ID_DTS, 0x2001 },
00339 { CODEC_ID_SONIC, 0x2048 },
00340 { CODEC_ID_SONIC_LS, 0x2048 },
00341 { CODEC_ID_PCM_MULAW, 0x6c75 },
00342 { CODEC_ID_AAC, 0x706d },
00343 { CODEC_ID_AAC, 0x4143 },
00344 { CODEC_ID_SPEEX, 0xA109 },
00345 { CODEC_ID_FLAC, 0xF1AC },
00346 { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' },
00347 { CODEC_ID_VORBIS, ('V'<<8)+'o' },
00348
00349
00350
00351 { CODEC_ID_PCM_S16LE, MKTAG('R', 'A', 'W', 'A') },
00352 { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') },
00353 { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') },
00354 { CODEC_ID_NONE, 0 },
00355 };
00356
00357 const AVCodecGuid ff_codec_wav_guids[] = {
00358 {CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
00359 {CODEC_ID_ATRAC3P, {0xBF,0xAA,0x23,0xE9,0x58,0xCB,0x71,0x44,0xA1,0x19,0xFF,0xFA,0x01,0xE4,0xCE,0x62}},
00360 {CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}},
00361 {CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
00362 {CODEC_ID_NONE}
00363 };
00364
00365 const AVMetadataConv ff_riff_info_conv[] = {
00366 { "IART", "artist" },
00367 { "ICMT", "comment" },
00368 { "ICOP", "copyright" },
00369 { "ICRD", "date" },
00370 { "IGNR", "genre" },
00371 { "ILNG", "language" },
00372 { "INAM", "title" },
00373 { "IPRD", "album" },
00374 { "IPRT", "track" },
00375 { "ISFT", "encoder" },
00376 { "ITCH", "encoded_by"},
00377 { 0 },
00378 };
00379
00380 const char ff_riff_tags[][5] = {
00381 "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
00382 "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
00383 "IPRT", "ISBJ", "ISFT", "ISHP", "ISRC", "ISRF", "ITCH",
00384 {0}
00385 };
00386
00387 #if CONFIG_MUXERS
00388 int64_t ff_start_tag(AVIOContext *pb, const char *tag)
00389 {
00390 ffio_wfourcc(pb, tag);
00391 avio_wl32(pb, 0);
00392 return avio_tell(pb);
00393 }
00394
00395 void ff_end_tag(AVIOContext *pb, int64_t start)
00396 {
00397 int64_t pos;
00398
00399 pos = avio_tell(pb);
00400 avio_seek(pb, start - 4, SEEK_SET);
00401 avio_wl32(pb, (uint32_t)(pos - start));
00402 avio_seek(pb, pos, SEEK_SET);
00403 }
00404
00405
00406
00407 int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
00408 {
00409 int bps, blkalign, bytespersec;
00410 int hdrsize = 18;
00411 int waveformatextensible;
00412 uint8_t temp[256];
00413 uint8_t *riff_extradata= temp;
00414 uint8_t *riff_extradata_start= temp;
00415
00416 if(!enc->codec_tag || enc->codec_tag > 0xffff)
00417 return -1;
00418 waveformatextensible = (enc->channels > 2 && enc->channel_layout)
00419 || enc->sample_rate > 48000
00420 || av_get_bits_per_sample(enc->codec_id) > 16;
00421
00422 if (waveformatextensible) {
00423 avio_wl16(pb, 0xfffe);
00424 } else {
00425 avio_wl16(pb, enc->codec_tag);
00426 }
00427 avio_wl16(pb, enc->channels);
00428 avio_wl32(pb, enc->sample_rate);
00429 if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {
00430 bps = 0;
00431 } else {
00432 if (!(bps = av_get_bits_per_sample(enc->codec_id))) {
00433 if (enc->bits_per_coded_sample)
00434 bps = enc->bits_per_coded_sample;
00435 else
00436 bps = 16;
00437 }
00438 }
00439 if(bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample){
00440 av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps);
00441 }
00442
00443 if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
00444 blkalign = enc->frame_size;
00445
00446 } else if (enc->codec_id == CODEC_ID_AC3) {
00447 blkalign = 3840;
00448 } else if (enc->block_align != 0) {
00449 blkalign = enc->block_align;
00450 } else
00451 blkalign = bps * enc->channels / av_gcd(8, bps);
00452 if (enc->codec_id == CODEC_ID_PCM_U8 ||
00453 enc->codec_id == CODEC_ID_PCM_S24LE ||
00454 enc->codec_id == CODEC_ID_PCM_S32LE ||
00455 enc->codec_id == CODEC_ID_PCM_F32LE ||
00456 enc->codec_id == CODEC_ID_PCM_F64LE ||
00457 enc->codec_id == CODEC_ID_PCM_S16LE) {
00458 bytespersec = enc->sample_rate * blkalign;
00459 } else {
00460 bytespersec = enc->bit_rate / 8;
00461 }
00462 avio_wl32(pb, bytespersec);
00463 avio_wl16(pb, blkalign);
00464 avio_wl16(pb, bps);
00465 if (enc->codec_id == CODEC_ID_MP3) {
00466 hdrsize += 12;
00467 bytestream_put_le16(&riff_extradata, 1);
00468 bytestream_put_le32(&riff_extradata, 2);
00469 bytestream_put_le16(&riff_extradata, 1152);
00470 bytestream_put_le16(&riff_extradata, 1);
00471 bytestream_put_le16(&riff_extradata, 1393);
00472 } else if (enc->codec_id == CODEC_ID_MP2) {
00473 hdrsize += 22;
00474 bytestream_put_le16(&riff_extradata, 2);
00475 bytestream_put_le32(&riff_extradata, enc->bit_rate);
00476 bytestream_put_le16(&riff_extradata, enc->channels == 2 ? 1 : 8);
00477 bytestream_put_le16(&riff_extradata, 0);
00478 bytestream_put_le16(&riff_extradata, 1);
00479 bytestream_put_le16(&riff_extradata, 16);
00480 bytestream_put_le32(&riff_extradata, 0);
00481 bytestream_put_le32(&riff_extradata, 0);
00482 } else if (enc->codec_id == CODEC_ID_GSM_MS || enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
00483 hdrsize += 2;
00484 bytestream_put_le16(&riff_extradata, enc->frame_size);
00485 } else if(enc->extradata_size){
00486 riff_extradata_start= enc->extradata;
00487 riff_extradata= enc->extradata + enc->extradata_size;
00488 hdrsize += enc->extradata_size;
00489 }
00490 if(waveformatextensible) {
00491 hdrsize += 22;
00492 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
00493 avio_wl16(pb, bps);
00494 avio_wl32(pb, enc->channel_layout);
00495 avio_wl32(pb, enc->codec_tag);
00496 avio_wl32(pb, 0x00100000);
00497 avio_wl32(pb, 0xAA000080);
00498 avio_wl32(pb, 0x719B3800);
00499 } else {
00500 avio_wl16(pb, riff_extradata - riff_extradata_start);
00501 }
00502 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
00503 if(hdrsize&1){
00504 hdrsize++;
00505 avio_w8(pb, 0);
00506 }
00507
00508 return hdrsize;
00509 }
00510
00511
00512 void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
00513 {
00514 avio_wl32(pb, 40 + enc->extradata_size);
00515 avio_wl32(pb, enc->width);
00516
00517 avio_wl32(pb, enc->codec_tag ? enc->height : -enc->height);
00518 avio_wl16(pb, 1);
00519
00520 avio_wl16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24);
00521
00522 avio_wl32(pb, enc->codec_tag);
00523 avio_wl32(pb, (enc->width * enc->height * (enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24)+7) / 8);
00524 avio_wl32(pb, 0);
00525 avio_wl32(pb, 0);
00526 avio_wl32(pb, 0);
00527 avio_wl32(pb, 0);
00528
00529 avio_write(pb, enc->extradata, enc->extradata_size);
00530
00531 if (!for_asf && enc->extradata_size & 1)
00532 avio_w8(pb, 0);
00533 }
00534 #endif //CONFIG_MUXERS
00535
00536 #if CONFIG_DEMUXERS
00537
00538
00539
00540
00541
00542
00543
00544 int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
00545 {
00546 int id;
00547
00548 id = avio_rl16(pb);
00549 codec->codec_type = AVMEDIA_TYPE_AUDIO;
00550 codec->channels = avio_rl16(pb);
00551 codec->sample_rate = avio_rl32(pb);
00552 codec->bit_rate = avio_rl32(pb) * 8;
00553 codec->block_align = avio_rl16(pb);
00554 if (size == 14) {
00555 codec->bits_per_coded_sample = 8;
00556 }else
00557 codec->bits_per_coded_sample = avio_rl16(pb);
00558 if (id == 0xFFFE) {
00559 codec->codec_tag = 0;
00560 } else {
00561 codec->codec_tag = id;
00562 codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample);
00563 }
00564 if (size >= 18) {
00565 int cbSize = avio_rl16(pb);
00566 size -= 18;
00567 cbSize = FFMIN(size, cbSize);
00568 if (cbSize >= 22 && id == 0xfffe) {
00569 ff_asf_guid subformat;
00570 codec->bits_per_coded_sample = avio_rl16(pb);
00571 codec->channel_layout = avio_rl32(pb);
00572 ff_get_guid(pb, &subformat);
00573 if (!memcmp(subformat + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) {
00574 codec->codec_tag = AV_RL32(subformat);
00575 codec->codec_id = ff_wav_codec_get_id(codec->codec_tag, codec->bits_per_coded_sample);
00576 } else {
00577 codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat);
00578 if (!codec->codec_id)
00579 av_log(codec, AV_LOG_WARNING, "unknown subformat:"FF_PRI_GUID"\n", FF_ARG_GUID(subformat));
00580 }
00581 cbSize -= 22;
00582 size -= 22;
00583 }
00584 codec->extradata_size = cbSize;
00585 if (cbSize > 0) {
00586 av_free(codec->extradata);
00587 codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
00588 if (!codec->extradata)
00589 return AVERROR(ENOMEM);
00590 avio_read(pb, codec->extradata, codec->extradata_size);
00591 size -= cbSize;
00592 }
00593
00594
00595 if (size > 0)
00596 avio_skip(pb, size);
00597 }
00598 if (codec->codec_id == CODEC_ID_AAC_LATM) {
00599
00600 codec->channels = 0;
00601 codec->sample_rate = 0;
00602 }
00603
00604 if (codec->codec_id == CODEC_ID_ADPCM_G726)
00605 codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;
00606
00607 return 0;
00608 }
00609
00610
00611 enum CodecID ff_wav_codec_get_id(unsigned int tag, int bps)
00612 {
00613 enum CodecID id;
00614 id = ff_codec_get_id(ff_codec_wav_tags, tag);
00615 if (id <= 0)
00616 return id;
00617
00618 if (id == CODEC_ID_PCM_S16LE && bps == 8)
00619 id = CODEC_ID_PCM_U8;
00620 if (id == CODEC_ID_PCM_S16LE && bps == 24)
00621 id = CODEC_ID_PCM_S24LE;
00622 if (id == CODEC_ID_PCM_S16LE && bps == 32)
00623 id = CODEC_ID_PCM_S32LE;
00624 if (id == CODEC_ID_PCM_F32LE && bps == 64)
00625 id = CODEC_ID_PCM_F64LE;
00626 if (id == CODEC_ID_ADPCM_IMA_WAV && bps == 8)
00627 id = CODEC_ID_PCM_ZORK;
00628 return id;
00629 }
00630
00631 int ff_get_bmp_header(AVIOContext *pb, AVStream *st)
00632 {
00633 int tag1;
00634 avio_rl32(pb);
00635 st->codec->width = avio_rl32(pb);
00636 st->codec->height = (int32_t)avio_rl32(pb);
00637 avio_rl16(pb);
00638 st->codec->bits_per_coded_sample= avio_rl16(pb);
00639 tag1 = avio_rl32(pb);
00640 avio_rl32(pb);
00641 avio_rl32(pb);
00642 avio_rl32(pb);
00643 avio_rl32(pb);
00644 avio_rl32(pb);
00645 return tag1;
00646 }
00647 #endif // CONFIG_DEMUXERS
00648
00649 void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
00650 {
00651 int gcd;
00652
00653 *au_ssize= stream->block_align;
00654 if(stream->frame_size && stream->sample_rate){
00655 *au_scale=stream->frame_size;
00656 *au_rate= stream->sample_rate;
00657 }else if(stream->codec_type == AVMEDIA_TYPE_VIDEO ||
00658 stream->codec_type == AVMEDIA_TYPE_DATA ||
00659 stream->codec_type == AVMEDIA_TYPE_SUBTITLE){
00660 *au_scale= stream->time_base.num;
00661 *au_rate = stream->time_base.den;
00662 }else{
00663 *au_scale= stream->block_align ? stream->block_align*8 : 8;
00664 *au_rate = stream->bit_rate ? stream->bit_rate : 8*stream->sample_rate;
00665 }
00666 gcd= av_gcd(*au_scale, *au_rate);
00667 *au_scale /= gcd;
00668 *au_rate /= gcd;
00669 }
00670
00671 void ff_get_guid(AVIOContext *s, ff_asf_guid *g)
00672 {
00673 assert(sizeof(*g) == 16);
00674 avio_read(s, *g, sizeof(*g));
00675 }
00676
00677 enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid)
00678 {
00679 int i;
00680 for (i = 0; guids[i].id != CODEC_ID_NONE; i++) {
00681 if (!ff_guidcmp(guids[i].guid, guid))
00682 return guids[i].id;
00683 }
00684 return CODEC_ID_NONE;
00685 }
00686
00687 int ff_read_riff_info(AVFormatContext *s, int64_t size)
00688 {
00689 int64_t start, end, cur;
00690 AVIOContext *pb = s->pb;
00691
00692 start = avio_tell(pb);
00693 end = start + size;
00694
00695 while ((cur = avio_tell(pb)) >= 0 && cur <= end - 8 ) {
00696 uint32_t chunk_code;
00697 int64_t chunk_size;
00698 char key[5] = {0};
00699 char *value;
00700
00701 chunk_code = avio_rl32(pb);
00702 chunk_size = avio_rl32(pb);
00703 if (chunk_size > end || end - chunk_size < cur || chunk_size == UINT_MAX) {
00704 av_log(s, AV_LOG_ERROR, "too big INFO subchunk\n");
00705 return AVERROR_INVALIDDATA;
00706 }
00707
00708 chunk_size += (chunk_size & 1);
00709
00710 value = av_malloc(chunk_size + 1);
00711 if (!value) {
00712 av_log(s, AV_LOG_ERROR, "out of memory, unable to read INFO tag\n");
00713 return AVERROR(ENOMEM);
00714 }
00715
00716 AV_WL32(key, chunk_code);
00717
00718 if (avio_read(pb, value, chunk_size) != chunk_size) {
00719 av_freep(&value);
00720 av_log(s, AV_LOG_ERROR, "premature end of file while reading INFO tag\n");
00721 return AVERROR_INVALIDDATA;
00722 }
00723
00724 value[chunk_size] = 0;
00725
00726 av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
00727 }
00728
00729 return 0;
00730 }