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.

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