You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1677 lines
54KB

  1. /*
  2. * MOV decoder.
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "avformat.h"
  20. #include "avi.h"
  21. #ifdef CONFIG_ZLIB
  22. #include <zlib.h>
  23. #endif
  24. /*
  25. * First version by Francois Revol revol@free.fr
  26. *
  27. * Features and limitations:
  28. * - reads most of the QT files I have (at least the structure),
  29. * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement.
  30. * FIXED, Francois Revol, 07/17/2002
  31. * - ffmpeg has nearly none of the usual QuickTime codecs,
  32. * although I succesfully dumped raw and mp3 audio tracks off .mov files.
  33. * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html
  34. * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes
  35. * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at
  36. * http://mpeg.telecomitalialab.com/faq.htm
  37. * - the code is quite ugly... maybe I won't do it recursive next time :-)
  38. *
  39. * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/
  40. * when coding this :) (it's a writer anyway)
  41. *
  42. * Reference documents:
  43. * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
  44. * Apple:
  45. * http://developer.apple.com/techpubs/quicktime/qtdevdocs/QTFF/qtff.html
  46. * http://developer.apple.com/techpubs/quicktime/qtdevdocs/PDF/QTFileFormat.pdf
  47. * QuickTime is a trademark of Apple (AFAIK :))
  48. */
  49. //#define DEBUG
  50. #ifdef DEBUG
  51. #include <stdio.h>
  52. #include <fcntl.h>
  53. #endif
  54. /* allows chunk splitting - should work now... */
  55. /* in case you can't read a file, try commenting */
  56. #define MOV_SPLIT_CHUNKS
  57. /* Special handling for movies created with Minolta Dimaxe Xi*/
  58. /* this fix should not interfere with other .mov files, but just in case*/
  59. #define MOV_MINOLTA_FIX
  60. /* some streams in QT (and in MP4 mostly) aren't either video nor audio */
  61. /* so we first list them as this, then clean up the list of streams we give back, */
  62. /* getting rid of these */
  63. #define CODEC_TYPE_MOV_OTHER (enum CodecType) 2
  64. static const CodecTag mov_video_tags[] = {
  65. /* { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */
  66. /* { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */
  67. /* { CODEC_ID_H263, MKTAG('Y', 'u', 'v', '2') }, *//* Uncompressed YUV422 */
  68. /* { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'U', 'I') }, *//* YUV with alpha-channel (AVID Uncompressed) */
  69. /* Graphics */
  70. /* Animation */
  71. /* Apple video */
  72. /* Kodak Photo CD */
  73. { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */
  74. { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
  75. { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */
  76. { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */
  77. { CODEC_ID_MJPEG, MKTAG('A', 'V', 'D', 'J') }, /* MJPEG with alpha-channel (AVID JFIF meridien compressed) */
  78. /* { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, *//* MJPEG with alpha-channel (AVID ABVB/Truevision NuVista) */
  79. /* { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, *//* embedded gif files as frames (usually one "click to play movie" frame) */
  80. /* Sorenson video */
  81. { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */
  82. { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */
  83. { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') }, /* Sorenson Video v1 (from QT specs)*/
  84. { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') }, /* Sorenson Video v3 */
  85. { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
  86. { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
  87. { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
  88. /* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */
  89. { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */
  90. { CODEC_ID_H263, MKTAG('s', '2', '6', '3') }, /* H263 ?? works */
  91. { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, /* DV NTSC */
  92. { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 'p') }, /* DV PAL */
  93. /* { CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') }, *//* AVID dv */
  94. { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, /* On2 VP3 */
  95. { CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') }, /* Apple Video (RPZA) */
  96. { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') }, /* Cinepak */
  97. { CODEC_ID_NONE, 0 },
  98. };
  99. static const CodecTag mov_audio_tags[] = {
  100. /* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
  101. { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
  102. /* { CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') },*/ /* 8 bits */
  103. { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */
  104. { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
  105. { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
  106. { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
  107. { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */
  108. { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */
  109. { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */
  110. { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */
  111. { CODEC_ID_MP2, 0x6D730055 }, /* MPEG layer 3 */
  112. { CODEC_ID_MP2, 0x5500736D }, /* MPEG layer 3 *//* XXX: check endianness */
  113. /* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
  114. /* MP4 tags */
  115. { CODEC_ID_MPEG4AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG-4 AAC */
  116. /* The standard for mpeg4 audio is still not normalised AFAIK anyway */
  117. { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */
  118. { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */
  119. { CODEC_ID_AC3, MKTAG('m', 's', 0x20, 0x00) }, /* Dolby AC-3 */
  120. { CODEC_ID_NONE, 0 },
  121. };
  122. /* the QuickTime file format is quite convoluted...
  123. * it has lots of index tables, each indexing something in another one...
  124. * Here we just use what is needed to read the chunks
  125. */
  126. typedef struct MOV_sample_to_chunk_tbl {
  127. long first;
  128. long count;
  129. long id;
  130. } MOV_sample_to_chunk_tbl;
  131. typedef struct {
  132. uint32_t type;
  133. int64_t offset;
  134. int64_t size; /* total size (excluding the size and type fields) */
  135. } MOV_atom_t;
  136. typedef struct {
  137. int seed;
  138. int flags;
  139. int size;
  140. void* clrs;
  141. } MOV_ctab_t;
  142. typedef struct {
  143. uint8_t version;
  144. uint32_t flags; // 24bit
  145. /* 0x03 ESDescrTag */
  146. uint16_t es_id;
  147. #define MP4ODescrTag 0x01
  148. #define MP4IODescrTag 0x02
  149. #define MP4ESDescrTag 0x03
  150. #define MP4DecConfigDescrTag 0x04
  151. #define MP4DecSpecificDescrTag 0x05
  152. #define MP4SLConfigDescrTag 0x06
  153. #define MP4ContentIdDescrTag 0x07
  154. #define MP4SupplContentIdDescrTag 0x08
  155. #define MP4IPIPtrDescrTag 0x09
  156. #define MP4IPMPPtrDescrTag 0x0A
  157. #define MP4IPMPDescrTag 0x0B
  158. #define MP4RegistrationDescrTag 0x0D
  159. #define MP4ESIDIncDescrTag 0x0E
  160. #define MP4ESIDRefDescrTag 0x0F
  161. #define MP4FileIODescrTag 0x10
  162. #define MP4FileODescrTag 0x11
  163. #define MP4ExtProfileLevelDescrTag 0x13
  164. #define MP4ExtDescrTagsStart 0x80
  165. #define MP4ExtDescrTagsEnd 0xFE
  166. uint8_t stream_priority;
  167. /* 0x04 DecConfigDescrTag */
  168. uint8_t object_type_id;
  169. uint8_t stream_type;
  170. /* XXX: really streamType is
  171. * only 6bit, followed by:
  172. * 1bit upStream
  173. * 1bit reserved
  174. */
  175. uint32_t buffer_size_db; // 24
  176. uint32_t max_bitrate;
  177. uint32_t avg_bitrate;
  178. /* 0x05 DecSpecificDescrTag */
  179. uint8_t decoder_cfg_len;
  180. uint8_t *decoder_cfg;
  181. /* 0x06 SLConfigDescrTag */
  182. uint8_t sl_config_len;
  183. uint8_t *sl_config;
  184. } MOV_esds_t;
  185. struct MOVParseTableEntry;
  186. typedef struct MOVStreamContext {
  187. int ffindex; /* the ffmpeg stream id */
  188. int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */
  189. long next_chunk;
  190. long chunk_count;
  191. int64_t *chunk_offsets;
  192. long sample_to_chunk_sz;
  193. MOV_sample_to_chunk_tbl *sample_to_chunk;
  194. long sample_to_chunk_index;
  195. long sample_size;
  196. long sample_count;
  197. long *sample_sizes;
  198. int time_scale;
  199. long current_sample;
  200. long left_in_chunk; /* how many samples before next chunk */
  201. /* specific MPEG4 header which is added at the beginning of the stream */
  202. int header_len;
  203. uint8_t *header_data;
  204. MOV_esds_t esds;
  205. } MOVStreamContext;
  206. typedef struct MOVContext {
  207. int mp4; /* set to 1 as soon as we are sure that the file is an .mp4 file (even some header parsing depends on this) */
  208. AVFormatContext *fc;
  209. int time_scale;
  210. int duration; /* duration of the longest track */
  211. int found_moov; /* when both 'moov' and 'mdat' sections has been found */
  212. int found_mdat; /* we suppose we have enough data to read the file */
  213. int64_t mdat_size;
  214. int64_t mdat_offset;
  215. int total_streams;
  216. /* some streams listed here aren't presented to the ffmpeg API, since they aren't either video nor audio
  217. * but we need the info to be able to skip data from those streams in the 'mdat' section
  218. */
  219. MOVStreamContext *streams[MAX_STREAMS];
  220. int64_t next_chunk_offset;
  221. MOVStreamContext *partial; /* != 0 : there is still to read in the current chunk */
  222. int ctab_size;
  223. MOV_ctab_t **ctab; /* color tables */
  224. const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */
  225. /* NOTE: for recursion save to/ restore from local variable! */
  226. } MOVContext;
  227. /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
  228. /* those functions parse an atom */
  229. /* return code:
  230. 1: found what I wanted, exit
  231. 0: continue to parse next atom
  232. -1: error occured, exit
  233. */
  234. typedef int (*mov_parse_function)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom);
  235. /* links atom IDs to parse functions */
  236. typedef struct MOVParseTableEntry {
  237. uint32_t type;
  238. mov_parse_function func;
  239. } MOVParseTableEntry;
  240. #ifdef DEBUG
  241. /*
  242. * XXX: static sux, even more in a multithreaded environment...
  243. * Avoid them. This is here just to help debugging.
  244. */
  245. static int debug_indent = 0;
  246. void print_atom(const char *str, MOV_atom_t atom)
  247. {
  248. unsigned int tag, i;
  249. tag = (unsigned int) atom.type;
  250. i=debug_indent;
  251. if(tag == 0) tag = MKTAG('N', 'U', 'L', 'L');
  252. while(i--)
  253. printf("|");
  254. printf("parse:");
  255. printf(" %s: tag=%c%c%c%c offset=0x%x size=0x%x\n",
  256. str, tag & 0xff,
  257. (tag >> 8) & 0xff,
  258. (tag >> 16) & 0xff,
  259. (tag >> 24) & 0xff,
  260. (unsigned int)atom.offset,
  261. (unsigned int)atom.size);
  262. assert((unsigned int)atom.size < 0x7fffffff);// catching errors
  263. }
  264. #else
  265. #define print_atom(a,b)
  266. #endif
  267. static int mov_read_leaf(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  268. {
  269. print_atom("leaf", atom);
  270. if (atom.size>1)
  271. url_fskip(pb, atom.size);
  272. /* url_seek(pb, atom_offset+atom.size, SEEK_SET); */
  273. return 0;
  274. }
  275. static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  276. {
  277. int64_t total_size = 0;
  278. MOV_atom_t a;
  279. int i;
  280. int err = 0;
  281. #ifdef DEBUG
  282. print_atom("default", atom);
  283. debug_indent++;
  284. #endif
  285. a.offset = atom.offset;
  286. if (atom.size < 0)
  287. atom.size = 0x7fffffffffffffffLL;
  288. while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) {
  289. a.size = atom.size;
  290. a.type=0L;
  291. if(atom.size >= 8) {
  292. a.size = get_be32(pb);
  293. a.type = get_le32(pb);
  294. }
  295. total_size += 8;
  296. a.offset += 8;
  297. //printf("type: %08x %.4s sz: %Lx %Lx %Lx\n", type, (char*)&type, size, atom.size, total_size);
  298. if (a.size == 1) { /* 64 bit extended size */
  299. a.size = get_be64(pb) - 8;
  300. a.offset += 8;
  301. total_size += 8;
  302. }
  303. if (a.size == 0) {
  304. a.size = atom.size - total_size;
  305. if (a.size <= 8)
  306. break;
  307. }
  308. for (i = 0; c->parse_table[i].type != 0L
  309. && c->parse_table[i].type != a.type; i++)
  310. /* empty */;
  311. a.size -= 8;
  312. // printf(" i=%ld\n", i);
  313. if (c->parse_table[i].type == 0) { /* skip leaf atoms data */
  314. // url_seek(pb, atom.offset+atom.size, SEEK_SET);
  315. #ifdef DEBUG
  316. print_atom("unknown", a);
  317. #endif
  318. url_fskip(pb, a.size);
  319. } else {
  320. #ifdef DEBUG
  321. //char b[5] = { type & 0xff, (type >> 8) & 0xff, (type >> 16) & 0xff, (type >> 24) & 0xff, 0 };
  322. //print_atom(b, type, offset, size);
  323. #endif
  324. err = (c->parse_table[i].func)(c, pb, a);
  325. }
  326. a.offset += a.size;
  327. total_size += a.size;
  328. }
  329. if (!err && total_size < atom.size && atom.size < 0x7ffff) {
  330. //printf("RESET %Ld %Ld err:%d\n", atom.size, total_size, err);
  331. url_fskip(pb, atom.size - total_size);
  332. }
  333. #ifdef DEBUG
  334. debug_indent--;
  335. #endif
  336. return err;
  337. }
  338. static int mov_read_ctab(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  339. {
  340. unsigned int len;
  341. MOV_ctab_t *t;
  342. //url_fskip(pb, atom.size); // for now
  343. c->ctab = av_realloc(c->ctab, ++c->ctab_size);
  344. t = c->ctab[c->ctab_size];
  345. t->seed = get_be32(pb);
  346. t->flags = get_be16(pb);
  347. t->size = get_be16(pb) + 1;
  348. len = 2 * t->size * 4;
  349. if (len > 0) {
  350. t->clrs = av_malloc(len); // 16bit A R G B
  351. if (t->clrs)
  352. get_buffer(pb, t->clrs, len);
  353. }
  354. return 0;
  355. }
  356. static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  357. {
  358. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  359. int len = 0;
  360. uint32_t type;
  361. uint32_t ctype;
  362. print_atom("hdlr", atom);
  363. get_byte(pb); /* version */
  364. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  365. /* component type */
  366. ctype = get_le32(pb);
  367. type = get_le32(pb); /* component subtype */
  368. #ifdef DEBUG
  369. printf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype);
  370. printf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
  371. #endif
  372. #ifdef DEBUG
  373. /* XXX: yeah this is ugly... */
  374. if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
  375. if(type == MKTAG('v', 'i', 'd', 'e'))
  376. puts("hdlr: vide");
  377. else if(type == MKTAG('s', 'o', 'u', 'n'))
  378. puts("hdlr: soun");
  379. } else if(ctype == 0) { /* MP4 */
  380. if(type == MKTAG('v', 'i', 'd', 'e'))
  381. puts("hdlr: vide");
  382. else if(type == MKTAG('s', 'o', 'u', 'n'))
  383. puts("hdlr: soun");
  384. else if(type == MKTAG('o', 'd', 's', 'm'))
  385. puts("hdlr: odsm");
  386. else if(type == MKTAG('s', 'd', 's', 'm'))
  387. puts("hdlr: sdsm");
  388. } else puts("hdlr: meta");
  389. #endif
  390. if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
  391. /* helps parsing the string hereafter... */
  392. c->mp4 = 0;
  393. if(type == MKTAG('v', 'i', 'd', 'e'))
  394. st->codec.codec_type = CODEC_TYPE_VIDEO;
  395. else if(type == MKTAG('s', 'o', 'u', 'n'))
  396. st->codec.codec_type = CODEC_TYPE_AUDIO;
  397. } else if(ctype == 0) { /* MP4 */
  398. /* helps parsing the string hereafter... */
  399. c->mp4 = 1;
  400. if(type == MKTAG('v', 'i', 'd', 'e'))
  401. st->codec.codec_type = CODEC_TYPE_VIDEO;
  402. else if(type == MKTAG('s', 'o', 'u', 'n'))
  403. st->codec.codec_type = CODEC_TYPE_AUDIO;
  404. }
  405. get_be32(pb); /* component manufacture */
  406. get_be32(pb); /* component flags */
  407. get_be32(pb); /* component flags mask */
  408. if(atom.size <= 24)
  409. return 0; /* nothing left to read */
  410. /* XXX: MP4 uses a C string, not a pascal one */
  411. /* component name */
  412. if(c->mp4) {
  413. /* .mp4: C string */
  414. while(get_byte(pb) && (++len < (atom.size - 24)));
  415. } else {
  416. /* .mov: PASCAL string */
  417. #ifdef DEBUG
  418. char* buf;
  419. #endif
  420. len = get_byte(pb);
  421. #ifdef DEBUG
  422. buf = (uint8_t*) av_malloc(len+1);
  423. if (buf) {
  424. get_buffer(pb, buf, len);
  425. buf[len] = '\0';
  426. printf("**buf='%s'\n", buf);
  427. av_free(buf);
  428. } else
  429. #endif
  430. url_fskip(pb, len);
  431. }
  432. return 0;
  433. }
  434. static int mov_mp4_read_descr_len(ByteIOContext *pb)
  435. {
  436. int len = 0;
  437. int count = 4;
  438. while (count--) {
  439. int c = get_byte(pb);
  440. len = (len << 7) | (c & 0x7f);
  441. if (!(c & 0x80))
  442. break;
  443. }
  444. return len;
  445. }
  446. static int mov_mp4_read_descr(ByteIOContext *pb, int *tag)
  447. {
  448. int len;
  449. *tag = get_byte(pb);
  450. len = mov_mp4_read_descr_len(pb);
  451. #ifdef DEBUG
  452. printf("MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
  453. #endif
  454. return len;
  455. }
  456. static inline unsigned int get_be24(ByteIOContext *s)
  457. {
  458. unsigned int val;
  459. val = get_byte(s) << 16;
  460. val |= get_byte(s) << 8;
  461. val |= get_byte(s);
  462. return val;
  463. }
  464. static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  465. {
  466. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  467. MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
  468. int64_t start_pos = url_ftell(pb);
  469. int tag, len;
  470. print_atom("esds", atom);
  471. /* Well, broken but suffisant for some MP4 streams */
  472. get_be32(pb); /* version + flags */
  473. len = mov_mp4_read_descr(pb, &tag);
  474. if (tag == MP4ESDescrTag) {
  475. get_be16(pb); /* ID */
  476. get_byte(pb); /* priority */
  477. } else
  478. get_be16(pb); /* ID */
  479. len = mov_mp4_read_descr(pb, &tag);
  480. if (tag == MP4DecConfigDescrTag) {
  481. sc->esds.object_type_id = get_byte(pb);
  482. sc->esds.stream_type = get_byte(pb);
  483. sc->esds.buffer_size_db = get_be24(pb);
  484. sc->esds.max_bitrate = get_be32(pb);
  485. sc->esds.avg_bitrate = get_be32(pb);
  486. len = mov_mp4_read_descr(pb, &tag);
  487. //printf("LEN %d TAG %d m:%d a:%d\n", len, tag, sc->esds.max_bitrate, sc->esds.avg_bitrate);
  488. if (tag == MP4DecSpecificDescrTag) {
  489. #ifdef DEBUG
  490. printf("Specific MPEG4 header len=%d\n", len);
  491. #endif
  492. st->codec.extradata = (uint8_t*) av_mallocz(len);
  493. if (st->codec.extradata) {
  494. get_buffer(pb, st->codec.extradata, len);
  495. st->codec.extradata_size = len;
  496. }
  497. }
  498. }
  499. /* in any case, skip garbage */
  500. url_fskip(pb, atom.size - ((url_ftell(pb) - start_pos)));
  501. return 0;
  502. }
  503. /* this atom contains actual media data */
  504. static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  505. {
  506. print_atom("mdat", atom);
  507. if(atom.size == 0) /* wrong one (MP4) */
  508. return 0;
  509. c->found_mdat=1;
  510. c->mdat_offset = atom.offset;
  511. c->mdat_size = atom.size;
  512. if(c->found_moov)
  513. return 1; /* found both, just go */
  514. url_fskip(pb, atom.size);
  515. return 0; /* now go for moov */
  516. }
  517. /* this atom should contain all header atoms */
  518. static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  519. {
  520. int err;
  521. print_atom("moov", atom);
  522. err = mov_read_default(c, pb, atom);
  523. /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
  524. /* so we don't parse the whole file if over a network */
  525. c->found_moov=1;
  526. if(c->found_mdat)
  527. return 1; /* found both, just go */
  528. return 0; /* now go for mdat */
  529. }
  530. static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  531. {
  532. print_atom("mdhd", atom);
  533. get_byte(pb); /* version */
  534. get_byte(pb); get_byte(pb);
  535. get_byte(pb); /* flags */
  536. get_be32(pb); /* creation time */
  537. get_be32(pb); /* modification time */
  538. c->streams[c->total_streams]->time_scale = get_be32(pb);
  539. #ifdef DEBUG
  540. printf("track[%i].time_scale = %i\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */
  541. #endif
  542. get_be32(pb); /* duration */
  543. get_be16(pb); /* language */
  544. get_be16(pb); /* quality */
  545. return 0;
  546. }
  547. static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  548. {
  549. print_atom("mvhd", atom);
  550. get_byte(pb); /* version */
  551. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  552. get_be32(pb); /* creation time */
  553. get_be32(pb); /* modification time */
  554. c->time_scale = get_be32(pb); /* time scale */
  555. #ifdef DEBUG
  556. printf("time scale = %i\n", c->time_scale);
  557. #endif
  558. c->duration = get_be32(pb); /* duration */
  559. get_be32(pb); /* preferred scale */
  560. get_be16(pb); /* preferred volume */
  561. url_fskip(pb, 10); /* reserved */
  562. url_fskip(pb, 36); /* display matrix */
  563. get_be32(pb); /* preview time */
  564. get_be32(pb); /* preview duration */
  565. get_be32(pb); /* poster time */
  566. get_be32(pb); /* selection time */
  567. get_be32(pb); /* selection duration */
  568. get_be32(pb); /* current time */
  569. get_be32(pb); /* next track ID */
  570. return 0;
  571. }
  572. static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  573. {
  574. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  575. // currently SVQ3 decoder expect full STSD header - so let's fake it
  576. // this should be fixed and just SMI header should be passed
  577. av_free(st->codec.extradata);
  578. st->codec.extradata_size = 0x5a + atom.size;
  579. st->codec.extradata = (uint8_t*) av_mallocz(st->codec.extradata_size);
  580. if (st->codec.extradata) {
  581. strcpy(st->codec.extradata, "SVQ3"); // fake
  582. get_buffer(pb, st->codec.extradata + 0x5a, atom.size);
  583. //printf("Reading SMI %Ld %s\n", atom.size, (char*)st->codec.extradata + 0x5a);
  584. } else
  585. url_fskip(pb, atom.size);
  586. return 0;
  587. }
  588. static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  589. {
  590. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  591. MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
  592. int entries, i;
  593. print_atom("stco", atom);
  594. get_byte(pb); /* version */
  595. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  596. entries = get_be32(pb);
  597. sc->chunk_count = entries;
  598. sc->chunk_offsets = (int64_t*) av_malloc(entries * sizeof(int64_t));
  599. if (!sc->chunk_offsets)
  600. return -1;
  601. if (atom.type == MKTAG('s', 't', 'c', 'o')) {
  602. for(i=0; i<entries; i++) {
  603. sc->chunk_offsets[i] = get_be32(pb);
  604. }
  605. } else if (atom.type == MKTAG('c', 'o', '6', '4')) {
  606. for(i=0; i<entries; i++) {
  607. sc->chunk_offsets[i] = get_be64(pb);
  608. }
  609. } else
  610. return -1;
  611. #ifdef DEBUG
  612. /*
  613. for(i=0; i<entries; i++) {
  614. printf("chunk offset=0x%Lx\n", sc->chunk_offsets[i]);
  615. }
  616. */
  617. #endif
  618. return 0;
  619. }
  620. static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  621. {
  622. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  623. //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
  624. int entries, frames_per_sample;
  625. uint32_t format;
  626. print_atom("stsd", atom);
  627. get_byte(pb); /* version */
  628. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  629. entries = get_be32(pb);
  630. while(entries--) { //Parsing Sample description table
  631. enum CodecID id;
  632. int size = get_be32(pb); /* size */
  633. format = get_le32(pb); /* data format */
  634. get_be32(pb); /* reserved */
  635. get_be16(pb); /* reserved */
  636. get_be16(pb); /* index */
  637. /* for MPEG4: set codec type by looking for it */
  638. id = codec_get_id(mov_video_tags, format);
  639. if (id >= 0) {
  640. AVCodec *codec;
  641. codec = avcodec_find_decoder(id);
  642. if (codec)
  643. st->codec.codec_type = codec->type;
  644. }
  645. #ifdef DEBUG
  646. printf("size=%d 4CC= %c%c%c%c codec_type=%d\n",
  647. size,
  648. (format >> 0) & 0xff,
  649. (format >> 8) & 0xff,
  650. (format >> 16) & 0xff,
  651. (format >> 24) & 0xff,
  652. st->codec.codec_type);
  653. #endif
  654. st->codec.codec_tag = format;
  655. if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
  656. MOV_atom_t a = { 0, 0, 0 };
  657. st->codec.codec_id = id;
  658. get_be16(pb); /* version */
  659. get_be16(pb); /* revision level */
  660. get_be32(pb); /* vendor */
  661. get_be32(pb); /* temporal quality */
  662. get_be32(pb); /* spacial quality */
  663. st->codec.width = get_be16(pb); /* width */
  664. st->codec.height = get_be16(pb); /* height */
  665. #if 1
  666. if (st->codec.codec_id == CODEC_ID_MPEG4) {
  667. /* in some MPEG4 the width/height are not correct, so
  668. we ignore this info */
  669. st->codec.width = 0;
  670. st->codec.height = 0;
  671. }
  672. #endif
  673. get_be32(pb); /* horiz resolution */
  674. get_be32(pb); /* vert resolution */
  675. get_be32(pb); /* data size, always 0 */
  676. frames_per_sample = get_be16(pb); /* frames per samples */
  677. #ifdef DEBUG
  678. printf("frames/samples = %d\n", frames_per_sample);
  679. #endif
  680. get_buffer(pb, (uint8_t *)st->codec.codec_name, 32); /* codec name */
  681. st->codec.bits_per_sample = get_be16(pb); /* depth */
  682. st->codec.color_table_id = get_be16(pb); /* colortable id */
  683. /* These are set in mov_read_stts and might already be set!
  684. st->codec.frame_rate = 25;
  685. st->codec.frame_rate_base = 1;
  686. */
  687. size -= (16+8*4+2+32+2*2);
  688. #if 0
  689. while (size >= 8) {
  690. MOV_atom_t a;
  691. int64_t start_pos;
  692. a.size = get_be32(pb);
  693. a.type = get_le32(pb);
  694. size -= 8;
  695. #ifdef DEBUG
  696. printf("VIDEO: atom_type=%c%c%c%c atom.size=%Ld size_left=%d\n",
  697. (a.type >> 0) & 0xff,
  698. (a.type >> 8) & 0xff,
  699. (a.type >> 16) & 0xff,
  700. (a.type >> 24) & 0xff,
  701. a.size, size);
  702. #endif
  703. start_pos = url_ftell(pb);
  704. switch(a.type) {
  705. case MKTAG('e', 's', 'd', 's'):
  706. {
  707. int tag, len;
  708. /* Well, broken but suffisant for some MP4 streams */
  709. get_be32(pb); /* version + flags */
  710. len = mov_mp4_read_descr(pb, &tag);
  711. if (tag == 0x03) {
  712. /* MP4ESDescrTag */
  713. get_be16(pb); /* ID */
  714. get_byte(pb); /* priority */
  715. len = mov_mp4_read_descr(pb, &tag);
  716. if (tag != 0x04)
  717. goto fail;
  718. /* MP4DecConfigDescrTag */
  719. get_byte(pb); /* objectTypeId */
  720. get_be32(pb); /* streamType + buffer size */
  721. get_be32(pb); /* max bit rate */
  722. get_be32(pb); /* avg bit rate */
  723. len = mov_mp4_read_descr(pb, &tag);
  724. if (tag != 0x05)
  725. goto fail;
  726. /* MP4DecSpecificDescrTag */
  727. #ifdef DEBUG
  728. printf("Specific MPEG4 header len=%d\n", len);
  729. #endif
  730. sc->header_data = av_mallocz(len);
  731. if (sc->header_data) {
  732. get_buffer(pb, sc->header_data, len);
  733. sc->header_len = len;
  734. }
  735. }
  736. /* in any case, skip garbage */
  737. }
  738. break;
  739. default:
  740. break;
  741. }
  742. fail:
  743. printf("ATOMENEWSIZE %Ld %d\n", atom.size, url_ftell(pb) - start_pos);
  744. if (atom.size > 8) {
  745. url_fskip(pb, (atom.size - 8) -
  746. ((url_ftell(pb) - start_pos)));
  747. size -= atom.size - 8;
  748. }
  749. }
  750. if (size > 0) {
  751. /* unknown extension */
  752. url_fskip(pb, size);
  753. }
  754. #else
  755. a.size = size;
  756. mov_read_default(c, pb, a);
  757. #endif
  758. } else {
  759. st->codec.codec_id = codec_get_id(mov_audio_tags, format);
  760. if(st->codec.codec_id==CODEC_ID_AMR_NB || st->codec.codec_id==CODEC_ID_AMR_WB) //from TS26.244
  761. {
  762. #ifdef DEBUG
  763. printf("AMR-NB or AMR-WB audio identified!!\n");
  764. #endif
  765. get_be32(pb);get_be32(pb); //Reserved_8
  766. get_be16(pb);//Reserved_2
  767. get_be16(pb);//Reserved_2
  768. get_be32(pb);//Reserved_4
  769. get_be16(pb);//TimeScale
  770. get_be16(pb);//Reserved_2
  771. //AMRSpecificBox.(10 bytes)
  772. get_be32(pb); //size
  773. get_be32(pb); //type=='damr'
  774. get_be32(pb); //vendor
  775. get_byte(pb); //decoder version
  776. get_be16(pb); //mode_set
  777. get_byte(pb); //mode_change_period
  778. get_byte(pb); //frames_per_sample
  779. st->duration = AV_NOPTS_VALUE;//Not possible to get from this info, must count number of AMR frames
  780. if(st->codec.codec_id==CODEC_ID_AMR_NB)
  781. {
  782. st->codec.sample_rate=8000;
  783. st->codec.channels=1;
  784. }
  785. else //AMR-WB
  786. {
  787. st->codec.sample_rate=16000;
  788. st->codec.channels=1;
  789. }
  790. st->codec.bits_per_sample=16;
  791. st->codec.bit_rate=0; /*It is not possible to tell this before we have
  792. an audio frame and even then every frame can be different*/
  793. }
  794. else if( st->codec.codec_tag == MKTAG( 'm', 'p', '4', 's' ))
  795. {
  796. //This is some stuff for the hint track, lets ignore it!
  797. //Do some mp4 auto detect.
  798. c->mp4=1;
  799. size-=(16);
  800. url_fskip(pb, size); /* The mp4s atom also contians a esds atom that we can skip*/
  801. }
  802. else if(size>=(16+20))
  803. {//16 bytes read, reading atleast 20 more
  804. #ifdef DEBUG
  805. printf("audio size=0x%X\n",size);
  806. #endif
  807. uint16_t version = get_be16(pb); /* version */
  808. get_be16(pb); /* revision level */
  809. get_be32(pb); /* vendor */
  810. st->codec.channels = get_be16(pb); /* channel count */
  811. st->codec.bits_per_sample = get_be16(pb); /* sample size */
  812. /* handle specific s8 codec */
  813. get_be16(pb); /* compression id = 0*/
  814. get_be16(pb); /* packet size = 0 */
  815. st->codec.sample_rate = ((get_be32(pb) >> 16));
  816. //printf("CODECID %d %d %.4s\n", st->codec.codec_id, CODEC_ID_PCM_S16BE, (char*)&format);
  817. switch (st->codec.codec_id) {
  818. case CODEC_ID_PCM_S16BE:
  819. if (st->codec.bits_per_sample == 8)
  820. st->codec.codec_id = CODEC_ID_PCM_S8;
  821. /* fall */
  822. case CODEC_ID_PCM_U8:
  823. st->codec.bit_rate = st->codec.sample_rate * 8;
  824. break;
  825. default:
  826. ;
  827. }
  828. //Read QT version 1 fields. In version 0 theese dont exist
  829. #ifdef DEBUG
  830. printf("version =%d mp4=%d\n",version,c->mp4);
  831. printf("size-(16+20+16)=%d\n",size-(16+20+16));
  832. #endif
  833. if((version==1) && size>=(16+20+16))
  834. {
  835. get_be32(pb); /* samples per packet */
  836. get_be32(pb); /* bytes per packet */
  837. get_be32(pb); /* bytes per frame */
  838. get_be32(pb); /* bytes per sample */
  839. if(size>(16+20+16))
  840. {
  841. //Optional, additional atom-based fields
  842. #ifdef DEBUG
  843. printf("offest=0x%X, sizeleft=%d=0x%x,format=%c%c%c%c\n",(int)url_ftell(pb),size - (16 + 20 + 16 ),size - (16 + 20 + 16 ),
  844. (format >> 0) & 0xff,
  845. (format >> 8) & 0xff,
  846. (format >> 16) & 0xff,
  847. (format >> 24) & 0xff);
  848. #endif
  849. MOV_atom_t a = { format, url_ftell(pb), size - (16 + 20 + 16 + 8) };
  850. mov_read_default(c, pb, a);
  851. }
  852. }
  853. else
  854. {
  855. //We should be down to 0 bytes here, but lets make sure.
  856. size-=(16+20);
  857. #ifdef DEBUG
  858. if(size>0)
  859. printf("skipping 0x%X bytes\n",size-(16+20));
  860. #endif
  861. url_fskip(pb, size);
  862. }
  863. }
  864. else
  865. {
  866. size-=16;
  867. //Unknown size, but lets do our best and skip the rest.
  868. #ifdef DEBUG
  869. printf("Strange size, skipping 0x%X bytes\n",size);
  870. #endif
  871. url_fskip(pb, size);
  872. }
  873. }
  874. }
  875. return 0;
  876. }
  877. static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  878. {
  879. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  880. MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
  881. int entries, i;
  882. print_atom("stsc", atom);
  883. get_byte(pb); /* version */
  884. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  885. entries = get_be32(pb);
  886. #ifdef DEBUG
  887. printf("track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
  888. #endif
  889. sc->sample_to_chunk_sz = entries;
  890. sc->sample_to_chunk = (MOV_sample_to_chunk_tbl*) av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl));
  891. if (!sc->sample_to_chunk)
  892. return -1;
  893. for(i=0; i<entries; i++) {
  894. sc->sample_to_chunk[i].first = get_be32(pb);
  895. sc->sample_to_chunk[i].count = get_be32(pb);
  896. sc->sample_to_chunk[i].id = get_be32(pb);
  897. #ifdef DEBUG
  898. /* printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id); */
  899. #endif
  900. }
  901. return 0;
  902. }
  903. static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  904. {
  905. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  906. MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
  907. int entries, i;
  908. print_atom("stsz", atom);
  909. get_byte(pb); /* version */
  910. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  911. sc->sample_size = get_be32(pb);
  912. entries = get_be32(pb);
  913. sc->sample_count = entries;
  914. #ifdef DEBUG
  915. printf("sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count);
  916. #endif
  917. if(sc->sample_size)
  918. return 0; /* there isn't any table following */
  919. sc->sample_sizes = (long*) av_malloc(entries * sizeof(long));
  920. if (!sc->sample_sizes)
  921. return -1;
  922. for(i=0; i<entries; i++) {
  923. sc->sample_sizes[i] = get_be32(pb);
  924. #ifdef DEBUG
  925. /* printf("sample_sizes[]=%ld\n", sc->sample_sizes[i]); */
  926. #endif
  927. }
  928. return 0;
  929. }
  930. static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  931. {
  932. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  933. //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
  934. int entries, i;
  935. int duration=0;
  936. int total_sample_count=0;
  937. print_atom("stts", atom);
  938. get_byte(pb); /* version */
  939. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  940. entries = get_be32(pb);
  941. #ifdef DEBUG
  942. printf("track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
  943. #endif
  944. for(i=0; i<entries; i++) {
  945. int sample_duration;
  946. int sample_count;
  947. sample_count=get_be32(pb);
  948. sample_duration = get_be32(pb);
  949. #ifdef DEBUG
  950. printf("sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
  951. #endif
  952. duration+=sample_duration*sample_count;
  953. total_sample_count+=sample_count;
  954. #if 0 //We calculate an average instead, needed by .mp4-files created with nec e606 3g phone
  955. if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {
  956. st->codec.frame_rate_base = sample_duration ? sample_duration : 1;
  957. st->codec.frame_rate = c->streams[c->total_streams]->time_scale;
  958. #ifdef DEBUG
  959. printf("VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration);
  960. #endif
  961. }
  962. #endif
  963. }
  964. #define MAX(a,b) a>b?a:b
  965. #define MIN(a,b) a>b?b:a
  966. /*The stsd atom which contain codec type sometimes comes after the stts so we cannot check for codec_type*/
  967. if(duration>0)
  968. {
  969. //Find greatest common divisor to avoid overflow using the Euclidean Algorithm...
  970. uint32_t max=MAX(duration,total_sample_count);
  971. uint32_t min=MIN(duration,total_sample_count);
  972. uint32_t spare=max%min;
  973. while(spare!=0)
  974. {
  975. max=min;
  976. min=spare;
  977. spare=max%min;
  978. }
  979. duration/=min;
  980. total_sample_count/=min;
  981. //Only support constant frame rate. But lets calculate the average. Needed by .mp4-files created with nec e606 3g phone.
  982. //To get better precision, we use the duration as frame_rate_base
  983. st->codec.frame_rate_base=duration;
  984. st->codec.frame_rate = c->streams[c->total_streams]->time_scale * total_sample_count;
  985. #ifdef DEBUG
  986. printf("FRAME RATE average (video or audio)= %f (tot sample count= %i ,tot dur= %i timescale=%d)\n", (float)st->codec.frame_rate/st->codec.frame_rate_base,total_sample_count,duration,c->streams[c->total_streams]->time_scale);
  987. #endif
  988. }
  989. else
  990. {
  991. st->codec.frame_rate_base = 1;
  992. st->codec.frame_rate = c->streams[c->total_streams]->time_scale;
  993. }
  994. #undef MAX
  995. #undef MIN
  996. return 0;
  997. }
  998. static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  999. {
  1000. AVStream *st;
  1001. MOVStreamContext *sc;
  1002. print_atom("trak", atom);
  1003. st = av_new_stream(c->fc, c->fc->nb_streams);
  1004. if (!st) return -2;
  1005. sc = (MOVStreamContext*) av_mallocz(sizeof(MOVStreamContext));
  1006. if (!sc) {
  1007. av_free(st);
  1008. return -1;
  1009. }
  1010. sc->sample_to_chunk_index = -1;
  1011. st->priv_data = sc;
  1012. st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
  1013. st->start_time = 0; /* XXX: check */
  1014. st->duration = (c->duration * (int64_t)AV_TIME_BASE) / c->time_scale;
  1015. c->streams[c->fc->nb_streams-1] = sc;
  1016. return mov_read_default(c, pb, atom);
  1017. }
  1018. static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1019. {
  1020. AVStream *st;
  1021. print_atom("tkhd", atom);
  1022. st = c->fc->streams[c->fc->nb_streams-1];
  1023. get_byte(pb); /* version */
  1024. get_byte(pb); get_byte(pb);
  1025. get_byte(pb); /* flags */
  1026. /*
  1027. MOV_TRACK_ENABLED 0x0001
  1028. MOV_TRACK_IN_MOVIE 0x0002
  1029. MOV_TRACK_IN_PREVIEW 0x0004
  1030. MOV_TRACK_IN_POSTER 0x0008
  1031. */
  1032. get_be32(pb); /* creation time */
  1033. get_be32(pb); /* modification time */
  1034. st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
  1035. get_be32(pb); /* reserved */
  1036. st->start_time = 0; /* check */
  1037. st->duration = (get_be32(pb) * (int64_t)AV_TIME_BASE) / c->time_scale; /* duration */
  1038. get_be32(pb); /* reserved */
  1039. get_be32(pb); /* reserved */
  1040. get_be16(pb); /* layer */
  1041. get_be16(pb); /* alternate group */
  1042. get_be16(pb); /* volume */
  1043. get_be16(pb); /* reserved */
  1044. url_fskip(pb, 36); /* display matrix */
  1045. /* those are fixed-point */
  1046. st->codec.width = get_be32(pb) >> 16; /* track width */
  1047. st->codec.height = get_be32(pb) >> 16; /* track height */
  1048. return 0;
  1049. }
  1050. /* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */
  1051. /* like the files created with Adobe Premiere 5.0, for samples see */
  1052. /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */
  1053. static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1054. {
  1055. int err;
  1056. #ifdef DEBUG
  1057. print_atom("wide", atom);
  1058. debug_indent++;
  1059. #endif
  1060. if (atom.size < 8)
  1061. return 0; /* continue */
  1062. if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
  1063. url_fskip(pb, atom.size - 4);
  1064. return 0;
  1065. }
  1066. atom.type = get_le32(pb);
  1067. atom.offset += 8;
  1068. atom.size -= 8;
  1069. if (atom.type != MKTAG('m', 'd', 'a', 't')) {
  1070. url_fskip(pb, atom.size);
  1071. return 0;
  1072. }
  1073. err = mov_read_mdat(c, pb, atom);
  1074. #ifdef DEBUG
  1075. debug_indent--;
  1076. #endif
  1077. return err;
  1078. }
  1079. #ifdef CONFIG_ZLIB
  1080. static int null_read_packet(void *opaque, uint8_t *buf, int buf_size)
  1081. {
  1082. return -1;
  1083. }
  1084. static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1085. {
  1086. ByteIOContext ctx;
  1087. uint8_t *cmov_data;
  1088. uint8_t *moov_data; /* uncompressed data */
  1089. long cmov_len, moov_len;
  1090. int ret;
  1091. print_atom("cmov", atom);
  1092. get_be32(pb); /* dcom atom */
  1093. if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' ))
  1094. return -1;
  1095. if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) {
  1096. dprintf("unknown compression for cmov atom !");
  1097. return -1;
  1098. }
  1099. get_be32(pb); /* cmvd atom */
  1100. if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' ))
  1101. return -1;
  1102. moov_len = get_be32(pb); /* uncompressed size */
  1103. cmov_len = atom.size - 6 * 4;
  1104. cmov_data = (uint8_t *) av_malloc(cmov_len);
  1105. if (!cmov_data)
  1106. return -1;
  1107. moov_data = (uint8_t *) av_malloc(moov_len);
  1108. if (!moov_data) {
  1109. av_free(cmov_data);
  1110. return -1;
  1111. }
  1112. get_buffer(pb, cmov_data, cmov_len);
  1113. if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
  1114. return -1;
  1115. if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0)
  1116. return -1;
  1117. ctx.buf_end = ctx.buffer + moov_len;
  1118. atom.type = MKTAG( 'm', 'o', 'o', 'v' );
  1119. atom.offset = 0;
  1120. atom.size = moov_len;
  1121. #ifdef DEBUG
  1122. { int fd = open("/tmp/uncompheader.mov", O_WRONLY | O_CREAT); write(fd, moov_data, moov_len); close(fd); }
  1123. #endif
  1124. ret = mov_read_default(c, &ctx, atom);
  1125. av_free(moov_data);
  1126. av_free(cmov_data);
  1127. return ret;
  1128. }
  1129. #endif
  1130. static const MOVParseTableEntry mov_default_parse_table[] = {
  1131. /* mp4 atoms */
  1132. { MKTAG( 'c', 'o', '6', '4' ), mov_read_stco },
  1133. { MKTAG( 'c', 'p', 'r', 't' ), mov_read_default },
  1134. { MKTAG( 'c', 'r', 'h', 'd' ), mov_read_default },
  1135. { MKTAG( 'c', 't', 't', 's' ), mov_read_leaf }, /* composition time to sample */
  1136. { MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default }, /* data information */
  1137. { MKTAG( 'd', 'p', 'n', 'd' ), mov_read_leaf },
  1138. { MKTAG( 'd', 'r', 'e', 'f' ), mov_read_leaf },
  1139. { MKTAG( 'e', 'd', 't', 's' ), mov_read_default },
  1140. { MKTAG( 'e', 'l', 's', 't' ), mov_read_leaf },
  1141. { MKTAG( 'f', 'r', 'e', 'e' ), mov_read_leaf },
  1142. { MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr },
  1143. { MKTAG( 'h', 'i', 'n', 't' ), mov_read_leaf },
  1144. { MKTAG( 'h', 'm', 'h', 'd' ), mov_read_leaf },
  1145. { MKTAG( 'i', 'o', 'd', 's' ), mov_read_leaf },
  1146. { MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat },
  1147. { MKTAG( 'm', 'd', 'h', 'd' ), mov_read_mdhd },
  1148. { MKTAG( 'm', 'd', 'i', 'a' ), mov_read_default },
  1149. { MKTAG( 'm', 'i', 'n', 'f' ), mov_read_default },
  1150. { MKTAG( 'm', 'o', 'o', 'v' ), mov_read_moov },
  1151. { MKTAG( 'm', 'p', '4', 'a' ), mov_read_default },
  1152. { MKTAG( 'm', 'p', '4', 's' ), mov_read_default },
  1153. { MKTAG( 'm', 'p', '4', 'v' ), mov_read_default },
  1154. { MKTAG( 'm', 'p', 'o', 'd' ), mov_read_leaf },
  1155. { MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd },
  1156. { MKTAG( 'n', 'm', 'h', 'd' ), mov_read_leaf },
  1157. { MKTAG( 'o', 'd', 'h', 'd' ), mov_read_default },
  1158. { MKTAG( 's', 'd', 'h', 'd' ), mov_read_default },
  1159. { MKTAG( 's', 'k', 'i', 'p' ), mov_read_default },
  1160. { MKTAG( 's', 'm', 'h', 'd' ), mov_read_leaf }, /* sound media info header */
  1161. { MKTAG( 'S', 'M', 'I', ' ' ), mov_read_smi }, /* Sorrenson extension ??? */
  1162. { MKTAG( 's', 't', 'b', 'l' ), mov_read_default },
  1163. { MKTAG( 's', 't', 'c', 'o' ), mov_read_stco },
  1164. { MKTAG( 's', 't', 'd', 'p' ), mov_read_default },
  1165. { MKTAG( 's', 't', 's', 'c' ), mov_read_stsc },
  1166. { MKTAG( 's', 't', 's', 'd' ), mov_read_stsd }, /* sample description */
  1167. { MKTAG( 's', 't', 's', 'h' ), mov_read_default },
  1168. { MKTAG( 's', 't', 's', 's' ), mov_read_leaf }, /* sync sample */
  1169. { MKTAG( 's', 't', 's', 'z' ), mov_read_stsz }, /* sample size */
  1170. { MKTAG( 's', 't', 't', 's' ), mov_read_stts },
  1171. { MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */
  1172. { MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak },
  1173. { MKTAG( 't', 'r', 'e', 'f' ), mov_read_default }, /* not really */
  1174. { MKTAG( 'u', 'd', 't', 'a' ), mov_read_leaf },
  1175. { MKTAG( 'u', 'r', 'l', ' ' ), mov_read_leaf },
  1176. { MKTAG( 'u', 'r', 'n', ' ' ), mov_read_leaf },
  1177. { MKTAG( 'u', 'u', 'i', 'd' ), mov_read_default },
  1178. { MKTAG( 'v', 'm', 'h', 'd' ), mov_read_leaf }, /* video media info header */
  1179. { MKTAG( 'w', 'a', 'v', 'e' ), mov_read_default },
  1180. /* extra mp4 */
  1181. { MKTAG( 'M', 'D', 'E', 'S' ), mov_read_leaf },
  1182. /* QT atoms */
  1183. { MKTAG( 'c', 'h', 'a', 'p' ), mov_read_leaf },
  1184. { MKTAG( 'c', 'l', 'i', 'p' ), mov_read_default },
  1185. { MKTAG( 'c', 'r', 'g', 'n' ), mov_read_leaf },
  1186. { MKTAG( 'c', 't', 'a', 'b' ), mov_read_ctab },
  1187. { MKTAG( 'e', 's', 'd', 's' ), mov_read_esds },
  1188. { MKTAG( 'k', 'm', 'a', 't' ), mov_read_leaf },
  1189. { MKTAG( 'm', 'a', 't', 't' ), mov_read_default },
  1190. { MKTAG( 'r', 'd', 'r', 'f' ), mov_read_leaf },
  1191. { MKTAG( 'r', 'm', 'd', 'a' ), mov_read_default },
  1192. { MKTAG( 'r', 'm', 'd', 'r' ), mov_read_leaf },
  1193. { MKTAG( 'r', 'm', 'r', 'a' ), mov_read_default },
  1194. { MKTAG( 's', 'c', 'p', 't' ), mov_read_leaf },
  1195. { MKTAG( 's', 's', 'r', 'c' ), mov_read_leaf },
  1196. { MKTAG( 's', 'y', 'n', 'c' ), mov_read_leaf },
  1197. { MKTAG( 't', 'c', 'm', 'd' ), mov_read_leaf },
  1198. { MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */
  1199. //{ MKTAG( 'r', 'm', 'q', 'u' ), mov_read_leaf },
  1200. #ifdef CONFIG_ZLIB
  1201. { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov },
  1202. #else
  1203. { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_leaf },
  1204. #endif
  1205. { 0L, mov_read_leaf }
  1206. };
  1207. static void mov_free_stream_context(MOVStreamContext *sc)
  1208. {
  1209. if(sc) {
  1210. av_free(sc->chunk_offsets);
  1211. av_free(sc->sample_to_chunk);
  1212. av_free(sc->sample_sizes);
  1213. av_free(sc->header_data);
  1214. av_free(sc);
  1215. }
  1216. }
  1217. static inline uint32_t mov_to_tag(uint8_t *buf)
  1218. {
  1219. return MKTAG(buf[0], buf[1], buf[2], buf[3]);
  1220. }
  1221. static inline uint32_t to_be32(uint8_t *buf)
  1222. {
  1223. return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
  1224. }
  1225. /* XXX: is it sufficient ? */
  1226. static int mov_probe(AVProbeData *p)
  1227. {
  1228. unsigned int offset;
  1229. uint32_t tag;
  1230. /* check file header */
  1231. if (p->buf_size <= 12)
  1232. return 0;
  1233. offset = 0;
  1234. for(;;) {
  1235. /* ignore invalid offset */
  1236. if ((offset + 8) > (unsigned int)p->buf_size)
  1237. return 0;
  1238. tag = mov_to_tag(p->buf + offset + 4);
  1239. switch(tag) {
  1240. case MKTAG( 'm', 'o', 'o', 'v' ):
  1241. case MKTAG( 'w', 'i', 'd', 'e' ):
  1242. case MKTAG( 'f', 'r', 'e', 'e' ):
  1243. case MKTAG( 'm', 'd', 'a', 't' ):
  1244. case MKTAG( 'p', 'n', 'o', 't' ): /* detect movs with preview pics like ew.mov and april.mov */
  1245. case MKTAG( 'u', 'd', 't', 'a' ): /* Packet Video PVAuthor adds this and a lot of more junk */
  1246. return AVPROBE_SCORE_MAX;
  1247. case MKTAG( 'f', 't', 'y', 'p' ):
  1248. case MKTAG( 's', 'k', 'i', 'p' ):
  1249. offset = to_be32(p->buf+offset) + offset;
  1250. break;
  1251. default:
  1252. /* unrecognized tag */
  1253. return 0;
  1254. }
  1255. }
  1256. return 0;
  1257. }
  1258. static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
  1259. {
  1260. MOVContext *mov = (MOVContext *) s->priv_data;
  1261. ByteIOContext *pb = &s->pb;
  1262. int i, j, nb, err;
  1263. MOV_atom_t atom = { 0, 0, 0 };
  1264. mov->fc = s;
  1265. mov->parse_table = mov_default_parse_table;
  1266. #if 0
  1267. /* XXX: I think we should auto detect */
  1268. if(s->iformat->name[1] == 'p')
  1269. mov->mp4 = 1;
  1270. #endif
  1271. if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
  1272. atom.size = url_filesize(url_fileno(pb));
  1273. else
  1274. atom.size = 0x7FFFFFFFFFFFFFFFLL;
  1275. #ifdef DEBUG
  1276. printf("filesz=%Ld\n", atom.size);
  1277. #endif
  1278. /* check MOV header */
  1279. err = mov_read_default(mov, pb, atom);
  1280. if (err<0 || (!mov->found_moov && !mov->found_mdat)) {
  1281. fprintf(stderr, "mov: header not found !!! (err:%d, moov:%d, mdat:%d) pos:%lld\n",
  1282. err, mov->found_moov, mov->found_mdat, url_ftell(pb));
  1283. return -1;
  1284. }
  1285. #ifdef DEBUG
  1286. printf("on_parse_exit_offset=%d\n", (int) url_ftell(pb));
  1287. #endif
  1288. /* some cleanup : make sure we are on the mdat atom */
  1289. if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset))
  1290. url_fseek(pb, mov->mdat_offset, SEEK_SET);
  1291. mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */
  1292. #ifdef DEBUG
  1293. printf("mdat_reset_offset=%d\n", (int) url_ftell(pb));
  1294. #endif
  1295. #ifdef DEBUG
  1296. printf("streams= %d\n", s->nb_streams);
  1297. #endif
  1298. mov->total_streams = nb = s->nb_streams;
  1299. #if 1
  1300. for(i=0; i<s->nb_streams;) {
  1301. if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */
  1302. av_free(s->streams[i]);
  1303. for(j=i+1; j<s->nb_streams; j++)
  1304. s->streams[j-1] = s->streams[j];
  1305. s->nb_streams--;
  1306. } else
  1307. i++;
  1308. }
  1309. for(i=0; i<s->nb_streams;i++) {
  1310. MOVStreamContext *sc;
  1311. sc = (MOVStreamContext *)s->streams[i]->priv_data;
  1312. sc->ffindex = i;
  1313. sc->is_ff_stream = 1;
  1314. }
  1315. #endif
  1316. #ifdef DEBUG
  1317. printf("real streams= %d\n", s->nb_streams);
  1318. #endif
  1319. return 0;
  1320. }
  1321. /* Yes, this is ugly... I didn't write the specs of QT :p */
  1322. /* XXX:remove useless commented code sometime */
  1323. static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
  1324. {
  1325. MOVContext *mov = (MOVContext *) s->priv_data;
  1326. MOVStreamContext *sc;
  1327. int64_t offset = 0x0FFFFFFFFFFFFFFFLL;
  1328. int i;
  1329. int size;
  1330. size = 0x0FFFFFFF;
  1331. #ifdef MOV_SPLIT_CHUNKS
  1332. if (mov->partial) {
  1333. int idx;
  1334. sc = mov->partial;
  1335. idx = sc->sample_to_chunk_index;
  1336. if (idx < 0) return 0;
  1337. size = sc->sample_sizes[sc->current_sample];
  1338. sc->current_sample++;
  1339. sc->left_in_chunk--;
  1340. if (sc->left_in_chunk <= 0)
  1341. mov->partial = 0;
  1342. offset = mov->next_chunk_offset;
  1343. /* extract the sample */
  1344. goto readchunk;
  1345. }
  1346. #endif
  1347. again:
  1348. sc = 0;
  1349. for(i=0; i<mov->total_streams; i++) {
  1350. MOVStreamContext *msc = mov->streams[i];
  1351. //printf("MOCHUNK %ld %d %p pos:%Ld\n", mov->streams[i]->next_chunk, mov->total_streams, mov->streams[i], url_ftell(&s->pb));
  1352. if ((msc->next_chunk < msc->chunk_count) && msc->next_chunk >= 0
  1353. && (msc->chunk_offsets[msc->next_chunk] < offset)) {
  1354. sc = msc;
  1355. offset = msc->chunk_offsets[msc->next_chunk];
  1356. //printf("SELETED %Ld i:%d\n", offset, i);
  1357. }
  1358. }
  1359. if (!sc || offset==0x0FFFFFFFFFFFFFFFLL)
  1360. return -1;
  1361. sc->next_chunk++;
  1362. if(mov->next_chunk_offset < offset) { /* some meta data */
  1363. url_fskip(&s->pb, (offset - mov->next_chunk_offset));
  1364. mov->next_chunk_offset = offset;
  1365. }
  1366. //printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);
  1367. if(!sc->is_ff_stream) {
  1368. url_fskip(&s->pb, (offset - mov->next_chunk_offset));
  1369. mov->next_chunk_offset = offset;
  1370. offset = 0x0FFFFFFFFFFFFFFFLL;
  1371. goto again;
  1372. }
  1373. /* now get the chunk size... */
  1374. for(i=0; i<mov->total_streams; i++) {
  1375. MOVStreamContext *msc = mov->streams[i];
  1376. if ((msc->next_chunk < msc->chunk_count)
  1377. && ((msc->chunk_offsets[msc->next_chunk] - offset) < size))
  1378. size = msc->chunk_offsets[msc->next_chunk] - offset;
  1379. }
  1380. #ifdef MOV_MINOLTA_FIX
  1381. //Make sure that size is according to sample_size (Needed by .mov files
  1382. //created on a Minolta Dimage Xi where audio chunks contains waste data in the end)
  1383. //Maybe we should really not only check sc->sample_size, but also sc->sample_sizes
  1384. //but I have no such movies
  1385. if (sc->sample_size > 0) {
  1386. int foundsize=0;
  1387. for(i=0; i<(sc->sample_to_chunk_sz); i++) {
  1388. if( (sc->sample_to_chunk[i].first)<=(sc->next_chunk) && (sc->sample_size>0) )
  1389. {
  1390. foundsize=sc->sample_to_chunk[i].count*sc->sample_size;
  1391. }
  1392. #ifdef DEBUG
  1393. /*printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id);*/
  1394. #endif
  1395. }
  1396. if( (foundsize>0) && (foundsize<size) )
  1397. {
  1398. #ifdef DEBUG
  1399. /*printf("this size should actually be %d\n",foundsize);*/
  1400. #endif
  1401. size=foundsize;
  1402. }
  1403. }
  1404. #endif //MOV_MINOLTA_FIX
  1405. #ifdef MOV_SPLIT_CHUNKS
  1406. /* split chunks into samples */
  1407. if (sc->sample_size == 0) {
  1408. int idx = sc->sample_to_chunk_index;
  1409. if ((idx + 1 < sc->sample_to_chunk_sz)
  1410. && (sc->next_chunk >= sc->sample_to_chunk[idx + 1].first))
  1411. idx++;
  1412. sc->sample_to_chunk_index = idx;
  1413. if (idx >= 0 && sc->sample_to_chunk[idx].count != 1) {
  1414. mov->partial = sc;
  1415. /* we'll have to get those samples before next chunk */
  1416. sc->left_in_chunk = sc->sample_to_chunk[idx].count - 1;
  1417. size = sc->sample_sizes[sc->current_sample];
  1418. }
  1419. sc->current_sample++;
  1420. }
  1421. #endif
  1422. readchunk:
  1423. //printf("chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size);
  1424. if(size == 0x0FFFFFFF)
  1425. size = mov->mdat_size + mov->mdat_offset - offset;
  1426. if(size < 0)
  1427. return -1;
  1428. if(size == 0)
  1429. return -1;
  1430. url_fseek(&s->pb, offset, SEEK_SET);
  1431. //printf("READCHUNK hlen: %d %d off: %Ld pos:%Ld\n", size, sc->header_len, offset, url_ftell(&s->pb));
  1432. if (sc->header_len > 0) {
  1433. av_new_packet(pkt, size + sc->header_len);
  1434. memcpy(pkt->data, sc->header_data, sc->header_len);
  1435. get_buffer(&s->pb, pkt->data + sc->header_len, size);
  1436. /* free header */
  1437. av_freep(&sc->header_data);
  1438. sc->header_len = 0;
  1439. } else {
  1440. av_new_packet(pkt, size);
  1441. get_buffer(&s->pb, pkt->data, pkt->size);
  1442. }
  1443. pkt->stream_index = sc->ffindex;
  1444. #ifdef DEBUG
  1445. /*
  1446. printf("Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size);
  1447. for(i=0; i<8; i++)
  1448. printf("%02x ", pkt->data[i]);
  1449. for(i=0; i<8; i++)
  1450. printf("%c ", (pkt->data[i]) & 0x7F);
  1451. puts("");
  1452. */
  1453. #endif
  1454. mov->next_chunk_offset = offset + size;
  1455. return 0;
  1456. }
  1457. static int mov_read_close(AVFormatContext *s)
  1458. {
  1459. int i;
  1460. MOVContext *mov = (MOVContext *) s->priv_data;
  1461. for(i=0; i<mov->total_streams; i++)
  1462. mov_free_stream_context(mov->streams[i]);
  1463. for(i=0; i<s->nb_streams; i++)
  1464. av_freep(&s->streams[i]);
  1465. /* free color tabs */
  1466. for(i=0; i<mov->ctab_size; i++)
  1467. av_freep(&mov->ctab[i]);
  1468. av_freep(&mov->ctab);
  1469. return 0;
  1470. }
  1471. static AVInputFormat mov_iformat = {
  1472. "mov,mp4,m4a,3gp",
  1473. "QuickTime/MPEG4 format",
  1474. sizeof(MOVContext),
  1475. mov_probe,
  1476. mov_read_header,
  1477. mov_read_packet,
  1478. mov_read_close,
  1479. };
  1480. int mov_init(void)
  1481. {
  1482. av_register_input_format(&mov_iformat);
  1483. return 0;
  1484. }