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.

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