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.

1113 lines
36KB

  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. /*
  52. * XXX: static sux, even more in a multithreaded environment...
  53. * Avoid them. This is here just to help debugging.
  54. */
  55. static int debug_indent = 0;
  56. void print_atom(const char *str, UINT32 type, UINT64 offset, UINT64 size)
  57. {
  58. unsigned int tag, i;
  59. tag = (unsigned int) type;
  60. i=debug_indent;
  61. if(tag == 0) tag = MKTAG('N', 'U', 'L', 'L');
  62. while(i--)
  63. printf("|");
  64. printf("parse:");
  65. printf(" %s: tag=%c%c%c%c offset=%d size=0x%x\n",
  66. str, tag & 0xff,
  67. (tag >> 8) & 0xff,
  68. (tag >> 16) & 0xff,
  69. (tag >> 24) & 0xff,
  70. (unsigned int)offset,
  71. (unsigned int)size);
  72. }
  73. #endif
  74. /* some streams in QT (and in MP4 mostly) aren't either video nor audio */
  75. /* so we first list them as this, then clean up the list of streams we give back, */
  76. /* getting rid of these */
  77. #define CODEC_TYPE_MOV_OTHER 2
  78. static const CodecTag mov_video_tags[] = {
  79. /* { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */
  80. /* { CODEC_ID_JPEG, MKTAG('j', 'p', 'e', 'g') }, *//* JPEG */
  81. /* { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */
  82. /* { CODEC_ID_H263, MKTAG('Y', 'u', 'v', '2') }, *//* Uncompressed YUV422 */
  83. /* Graphics */
  84. /* Animation */
  85. /* Apple video */
  86. /* Kodak Photo CD */
  87. /* { CODEC_ID_JPEG, MKTAG('j', 'p', 'e', 'g') }, *//* JPEG ? */
  88. { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
  89. { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format A) */
  90. { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */
  91. /* { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, *//* embedded gif files as frames (usually one "click to play movie" frame) */
  92. /* Sorenson video */
  93. { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */
  94. { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */
  95. { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') }, /* OpenDiVX *//* yeah ! */
  96. { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
  97. /* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */
  98. { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */
  99. { 0, 0 },
  100. };
  101. static const CodecTag mov_audio_tags[] = {
  102. /* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
  103. { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
  104. { CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') }, /* 8 bits */
  105. { CODEC_ID_PCM_U8, 0x20776172 }, /* 8 bits unsigned */
  106. { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
  107. { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
  108. { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
  109. { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */
  110. { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */
  111. { CODEC_ID_MP2, 0x6D730055 }, /* MPEG layer 3 */
  112. { CODEC_ID_MP2, 0x5500736D }, /* MPEG layer 3 *//* XXX: check endianness */
  113. /* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
  114. /* MP4 tags */
  115. /* { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, *//* MPEG 4 AAC or audio ? */
  116. /* The standard for mpeg4 audio is still not normalised AFAIK anyway */
  117. { 0, 0 },
  118. };
  119. /* the QuickTime file format is quite convoluted...
  120. * it has lots of index tables, each indexing something in another one...
  121. * Here we just use what is needed to read the chunks
  122. */
  123. typedef struct MOV_sample_to_chunk_tbl {
  124. long first;
  125. long count;
  126. long id;
  127. } MOV_sample_to_chunk_tbl;
  128. typedef struct MOVStreamContext {
  129. int ffindex; /* the ffmpeg stream id */
  130. int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */
  131. long next_chunk;
  132. long chunk_count;
  133. INT64 *chunk_offsets;
  134. long sample_to_chunk_sz;
  135. MOV_sample_to_chunk_tbl *sample_to_chunk;
  136. long sample_size;
  137. long sample_count;
  138. long *sample_sizes;
  139. long time_scale;
  140. } MOVStreamContext;
  141. typedef struct MOVContext {
  142. 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) */
  143. AVFormatContext *fc;
  144. long time_scale;
  145. int found_moov; /* when both 'moov' and 'mdat' sections has been found */
  146. int found_mdat; /* we suppose we have enough data to read the file */
  147. INT64 mdat_size;
  148. INT64 mdat_offset;
  149. int total_streams;
  150. /* some streams listed here aren't presented to the ffmpeg API, since they aren't either video nor audio
  151. * but we need the info to be able to skip data from those streams in the 'mdat' section
  152. */
  153. MOVStreamContext *streams[MAX_STREAMS];
  154. INT64 next_chunk_offset;
  155. } MOVContext;
  156. struct MOVParseTableEntry;
  157. /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
  158. /* those functions parse an atom */
  159. /* return code:
  160. 1: found what I wanted, exit
  161. 0: continue to parse next atom
  162. -1: error occured, exit
  163. */
  164. typedef int (*mov_parse_function)(const struct MOVParseTableEntry *parse_table,
  165. ByteIOContext *pb,
  166. UINT32 atom_type,
  167. INT64 atom_offset, /* after the size and type field (and eventually the extended size) */
  168. INT64 atom_size, /* total size (excluding the size and type fields) */
  169. void *param);
  170. /* links atom IDs to parse functions */
  171. typedef struct MOVParseTableEntry {
  172. UINT32 type;
  173. mov_parse_function func;
  174. } MOVParseTableEntry;
  175. static int parse_leaf(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  176. {
  177. #ifdef DEBUG
  178. print_atom("leaf", atom_type, atom_offset, atom_size);
  179. #endif
  180. if(atom_size>1)
  181. url_fskip(pb, atom_size);
  182. /* url_seek(pb, atom_offset+atom_size, SEEK_SET); */
  183. return 0;
  184. }
  185. static int parse_default(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  186. {
  187. UINT32 type, foo=0;
  188. UINT64 offset, size;
  189. UINT64 total_size = 0;
  190. int i;
  191. int err = 0;
  192. foo=0;
  193. #ifdef DEBUG
  194. print_atom("default", atom_type, atom_offset, atom_size);
  195. debug_indent++;
  196. #endif
  197. offset = atom_offset;
  198. if(atom_size < 0)
  199. atom_size = 0x0FFFFFFFFFFFFFFF;
  200. while((total_size < atom_size) && !url_feof(pb) && !err) {
  201. size=atom_size;
  202. type=0L;
  203. if(atom_size >= 8) {
  204. size = get_be32(pb);
  205. type = get_le32(pb);
  206. }
  207. total_size += 8;
  208. offset+=8;
  209. // printf("type: %08lx sz: %08lx", type, size);
  210. if(size == 1) { /* 64 bit extended size */
  211. size = get_be64(pb);
  212. offset+=8;
  213. total_size+=8;
  214. size-=8;
  215. }
  216. if(size == 0)
  217. size = atom_size - total_size;
  218. size-=8;
  219. for(i=0; parse_table[i].type != 0L && parse_table[i].type != type; i++);
  220. // printf(" i=%ld\n", i);
  221. if (parse_table[i].type == 0) { /* skip leaf atoms data */
  222. // url_seek(pb, atom_offset+atom_size, SEEK_SET);
  223. #ifdef DEBUG
  224. print_atom("unknown", type, offset, size);
  225. #endif
  226. url_fskip(pb, size);
  227. } else
  228. err = (parse_table[i].func)(parse_table, pb, type, offset, size, param);
  229. offset+=size;
  230. total_size+=size;
  231. }
  232. #ifdef DEBUG
  233. debug_indent--;
  234. #endif
  235. return err;
  236. }
  237. static int parse_mvhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  238. {
  239. MOVContext *c;
  240. #ifdef DEBUG
  241. print_atom("mvhd", atom_type, atom_offset, atom_size);
  242. #endif
  243. c = (MOVContext *)param;
  244. get_byte(pb); /* version */
  245. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  246. get_be32(pb); /* creation time */
  247. get_be32(pb); /* modification time */
  248. c->time_scale = get_be32(pb); /* time scale */
  249. #ifdef DEBUG
  250. printf("time scale = %li\n", c->time_scale);
  251. #endif
  252. get_be32(pb); /* duration */
  253. get_be32(pb); /* preferred scale */
  254. get_be16(pb); /* preferred volume */
  255. url_fskip(pb, 10); /* reserved */
  256. url_fskip(pb, 36); /* display matrix */
  257. get_be32(pb); /* preview time */
  258. get_be32(pb); /* preview duration */
  259. get_be32(pb); /* poster time */
  260. get_be32(pb); /* selection time */
  261. get_be32(pb); /* selection duration */
  262. get_be32(pb); /* current time */
  263. get_be32(pb); /* next track ID */
  264. return 0;
  265. }
  266. /* this atom should contain all header atoms */
  267. static int parse_moov(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  268. {
  269. int err;
  270. MOVContext *c;
  271. #ifdef DEBUG
  272. print_atom("moov", atom_type, atom_offset, atom_size);
  273. #endif
  274. c = (MOVContext *)param;
  275. err = parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
  276. /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
  277. /* so we don't parse the whole file if over a network */
  278. c->found_moov=1;
  279. if(c->found_mdat)
  280. return 1; /* found both, just go */
  281. return 0; /* now go for mdat */
  282. }
  283. /* this atom contains actual media data */
  284. static int parse_mdat(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  285. {
  286. MOVContext *c;
  287. #ifdef DEBUG
  288. print_atom("mdat", atom_type, atom_offset, atom_size);
  289. #endif
  290. c = (MOVContext *)param;
  291. if(atom_size == 0) /* wrong one (MP4) */
  292. return 0;
  293. c->found_mdat=1;
  294. c->mdat_offset = atom_offset;
  295. c->mdat_size = atom_size;
  296. if(c->found_moov)
  297. return 1; /* found both, just go */
  298. url_fskip(pb, atom_size);
  299. return 0; /* now go for moov */
  300. }
  301. static int parse_trak(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  302. {
  303. MOVContext *c;
  304. AVStream *st;
  305. MOVStreamContext *sc;
  306. #ifdef DEBUG
  307. print_atom("trak", atom_type, atom_offset, atom_size);
  308. #endif
  309. c = (MOVContext *)param;
  310. st = av_malloc(sizeof(AVStream));
  311. if (!st) return -2;
  312. memset(st, 0, sizeof(AVStream));
  313. c->fc->streams[c->fc->nb_streams] = st;
  314. sc = av_malloc(sizeof(MOVStreamContext));
  315. st->priv_data = sc;
  316. st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
  317. c->streams[c->fc->nb_streams++] = sc;
  318. return parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
  319. }
  320. static int parse_tkhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  321. {
  322. MOVContext *c;
  323. AVStream *st;
  324. #ifdef DEBUG
  325. print_atom("tkhd", atom_type, atom_offset, atom_size);
  326. #endif
  327. c = (MOVContext *)param;
  328. st = c->fc->streams[c->fc->nb_streams-1];
  329. get_byte(pb); /* version */
  330. get_byte(pb); get_byte(pb);
  331. get_byte(pb); /* flags */
  332. /*
  333. MOV_TRACK_ENABLED 0x0001
  334. MOV_TRACK_IN_MOVIE 0x0002
  335. MOV_TRACK_IN_PREVIEW 0x0004
  336. MOV_TRACK_IN_POSTER 0x0008
  337. */
  338. get_be32(pb); /* creation time */
  339. get_be32(pb); /* modification time */
  340. st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
  341. get_be32(pb); /* reserved */
  342. get_be32(pb); /* duration */
  343. get_be32(pb); /* reserved */
  344. get_be32(pb); /* reserved */
  345. get_be16(pb); /* layer */
  346. get_be16(pb); /* alternate group */
  347. get_be16(pb); /* volume */
  348. get_be16(pb); /* reserved */
  349. url_fskip(pb, 36); /* display matrix */
  350. /* those are fixed-point */
  351. st->codec.width = get_be32(pb) >> 16; /* track width */
  352. st->codec.height = get_be32(pb) >> 16; /* track height */
  353. return 0;
  354. }
  355. static int parse_mdhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  356. {
  357. MOVContext *c;
  358. AVStream *st;
  359. #ifdef DEBUG
  360. print_atom("mdhd", atom_type, atom_offset, atom_size);
  361. #endif
  362. c = (MOVContext *)param;
  363. st = c->fc->streams[c->fc->nb_streams-1];
  364. get_byte(pb); /* version */
  365. get_byte(pb); get_byte(pb);
  366. get_byte(pb); /* flags */
  367. get_be32(pb); /* creation time */
  368. get_be32(pb); /* modification time */
  369. c->streams[c->total_streams]->time_scale = get_be32(pb);
  370. #ifdef DEBUG
  371. printf("track[%i].time_scale = %li\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */
  372. #endif
  373. get_be32(pb); /* duration */
  374. get_be16(pb); /* language */
  375. get_be16(pb); /* quality */
  376. return 0;
  377. }
  378. static int parse_hdlr(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  379. {
  380. MOVContext *c;
  381. int len;
  382. char *buf;
  383. UINT32 type;
  384. AVStream *st;
  385. UINT32 ctype;
  386. #ifdef DEBUG
  387. print_atom("hdlr", atom_type, atom_offset, atom_size);
  388. #endif
  389. c = (MOVContext *)param;
  390. st = c->fc->streams[c->fc->nb_streams-1];
  391. get_byte(pb); /* version */
  392. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  393. /* component type */
  394. ctype = get_le32(pb);
  395. type = get_le32(pb); /* component subtype */
  396. #ifdef DEBUG
  397. printf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype);
  398. printf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
  399. #endif
  400. #ifdef DEBUG
  401. /* XXX: yeah this is ugly... */
  402. if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
  403. if(type == MKTAG('v', 'i', 'd', 'e'))
  404. puts("hdlr: vide");
  405. else if(type == MKTAG('s', 'o', 'u', 'n'))
  406. puts("hdlr: soun");
  407. } else if(ctype == 0) { /* MP4 */
  408. if(type == MKTAG('v', 'i', 'd', 'e'))
  409. puts("hdlr: vide");
  410. else if(type == MKTAG('s', 'o', 'u', 'n'))
  411. puts("hdlr: soun");
  412. else if(type == MKTAG('o', 'd', 's', 'm'))
  413. puts("hdlr: odsm");
  414. else if(type == MKTAG('s', 'd', 's', 'm'))
  415. puts("hdlr: sdsm");
  416. } else puts("hdlr: meta");
  417. #endif
  418. if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
  419. /* helps parsing the string hereafter... */
  420. c->mp4 = 0;
  421. if(type == MKTAG('v', 'i', 'd', 'e'))
  422. st->codec.codec_type = CODEC_TYPE_VIDEO;
  423. else if(type == MKTAG('s', 'o', 'u', 'n'))
  424. st->codec.codec_type = CODEC_TYPE_AUDIO;
  425. } else if(ctype == 0) { /* MP4 */
  426. /* helps parsing the string hereafter... */
  427. c->mp4 = 1;
  428. if(type == MKTAG('v', 'i', 'd', 'e'))
  429. st->codec.codec_type = CODEC_TYPE_VIDEO;
  430. else if(type == MKTAG('s', 'o', 'u', 'n'))
  431. st->codec.codec_type = CODEC_TYPE_AUDIO;
  432. }
  433. get_be32(pb); /* component manufacture */
  434. get_be32(pb); /* component flags */
  435. get_be32(pb); /* component flags mask */
  436. if(atom_size <= 24)
  437. return 0; /* nothing left to read */
  438. /* XXX: MP4 uses a C string, not a pascal one */
  439. /* component name */
  440. if(c->mp4) {
  441. /* .mp4: C string */
  442. while(get_byte(pb) && (++len < (atom_size - 24)));
  443. } else {
  444. /* .mov: PASCAL string */
  445. len = get_byte(pb);
  446. buf = av_malloc(len+1);
  447. get_buffer(pb, buf, len);
  448. buf[len] = '\0';
  449. #ifdef DEBUG
  450. printf("**buf='%s'\n", buf);
  451. #endif
  452. av_free(buf);
  453. }
  454. #if 0
  455. len = get_byte(pb);
  456. /* XXX: use a better heuristic */
  457. if(len < 32) {
  458. /* assume that it is a Pascal like string */
  459. buf = av_malloc(len+1);
  460. get_buffer(pb, buf, len);
  461. buf[len] = '\0';
  462. #ifdef DEBUG
  463. printf("**buf='%s'\n", buf);
  464. #endif
  465. av_free(buf);
  466. } else {
  467. /* MP4 string */
  468. for(;;) {
  469. if (len == 0)
  470. break;
  471. len = get_byte(pb);
  472. }
  473. }
  474. #endif
  475. return 0;
  476. }
  477. static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  478. {
  479. MOVContext *c;
  480. int entries, size, samp_sz, frames_per_sample;
  481. UINT32 format;
  482. AVStream *st;
  483. #ifdef DEBUG
  484. print_atom("stsd", atom_type, atom_offset, atom_size);
  485. #endif
  486. c = (MOVContext *)param;
  487. st = c->fc->streams[c->fc->nb_streams-1];
  488. get_byte(pb); /* version */
  489. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  490. entries = get_be32(pb);
  491. while(entries--) {
  492. size = get_be32(pb); /* size */
  493. format = get_le32(pb); /* data format */
  494. get_be32(pb); /* reserved */
  495. get_be16(pb); /* reserved */
  496. get_be16(pb); /* index */
  497. /* if(format == MKTAG('m', 'p', '4', 'v')) */
  498. /* st->codec.codec_type=CODEC_TYPE_VIDEO; *//* force things (XXX: was this for .mp4 ?) */
  499. if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
  500. st->codec.codec_tag = format;
  501. st->codec.codec_id = codec_get_id(mov_video_tags, format);
  502. get_be16(pb); /* version */
  503. get_be16(pb); /* revision level */
  504. get_be32(pb); /* vendor */
  505. get_be32(pb); /* temporal quality */
  506. get_be32(pb); /* spacial quality */
  507. st->codec.width = get_be16(pb); /* width */
  508. st->codec.height = get_be16(pb); /* height */
  509. get_be32(pb); /* horiz resolution */
  510. get_be32(pb); /* vert resolution */
  511. get_be32(pb); /* data size, always 0 */
  512. frames_per_sample = get_be16(pb); /* frame per samples */
  513. #ifdef DEBUG
  514. printf("frames/samples = %d\n", frames_per_sample);
  515. #endif
  516. url_fskip(pb, 32); /* codec name */
  517. get_be16(pb); /* depth */
  518. get_be16(pb); /* colortable id */
  519. get_be16(pb); /* */
  520. get_be16(pb); /* */
  521. st->codec.sample_rate = 25 * FRAME_RATE_BASE;
  522. if(size > 16)
  523. url_fskip(pb, size-(16+24+18+32));
  524. } else {
  525. st->codec.codec_tag = format;
  526. get_be16(pb); /* version */
  527. get_be16(pb); /* revision level */
  528. get_be32(pb); /* vendor */
  529. st->codec.channels = get_be16(pb);/* channel count */
  530. samp_sz = get_be16(pb); /* sample size */
  531. #ifdef DEBUG
  532. if(samp_sz != 16)
  533. puts("!!! stsd: audio sample size is not 16 bit !");
  534. #endif
  535. st->codec.codec_id = codec_get_id(mov_audio_tags, format);
  536. /* handle specific s8 codec */
  537. if (st->codec.codec_id == CODEC_ID_PCM_S16BE && samp_sz == 8)
  538. st->codec.codec_id = CODEC_ID_PCM_S8;
  539. get_be16(pb); /* compression id = 0*/
  540. get_be16(pb); /* packet size = 0 */
  541. st->codec.sample_rate = ((get_be32(pb) >> 16));
  542. st->codec.bit_rate = 0;
  543. /* this is for .mp4 files */
  544. if(format == MKTAG('m', 'p', '4', 'v')) { /* XXX */
  545. st->codec.codec_type=CODEC_TYPE_VIDEO; /* force things */
  546. st->codec.codec_id = CODEC_ID_MPEG4;
  547. st->codec.frame_rate = 25 * FRAME_RATE_BASE;
  548. st->codec.bit_rate = 100000;
  549. }
  550. #if 0
  551. get_be16(pb); get_be16(pb); /* */
  552. get_be16(pb); /* */
  553. get_be16(pb); /* */
  554. get_be16(pb); /* */
  555. get_be16(pb); /* */
  556. #endif
  557. if(size > 16)
  558. url_fskip(pb, size-(16+20));
  559. }
  560. #ifdef DEBUG
  561. printf("4CC= %c%c%c%c\n", *((char *)&format), ((char *)&format)[1], ((char *)&format)[2], ((char *)&format)[3]);
  562. #endif
  563. }
  564. /*
  565. if(len) {
  566. buf = av_malloc(len+1);
  567. get_buffer(pb, buf, len);
  568. buf[len] = '\0';
  569. puts(buf);
  570. av_free(buf);
  571. }
  572. */
  573. return 0;
  574. }
  575. static int parse_stco(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  576. {
  577. MOVContext *c;
  578. int entries, i;
  579. AVStream *st;
  580. MOVStreamContext *sc;
  581. #ifdef DEBUG
  582. print_atom("stco", atom_type, atom_offset, atom_size);
  583. #endif
  584. c = (MOVContext *)param;
  585. st = c->fc->streams[c->fc->nb_streams-1];
  586. sc = (MOVStreamContext *)st->priv_data;
  587. get_byte(pb); /* version */
  588. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  589. entries = get_be32(pb);
  590. sc->chunk_count = entries;
  591. sc->chunk_offsets = av_malloc(entries * sizeof(INT64));
  592. if(atom_type == MKTAG('s', 't', 'c', 'o')) {
  593. for(i=0; i<entries; i++) {
  594. sc->chunk_offsets[i] = get_be32(pb);
  595. /*printf("chunk offset=%ld\n", sc->chunk_offsets[i]);*/
  596. }
  597. } else if(atom_type == MKTAG('c', 'o', '6', '4')) {
  598. for(i=0; i<entries; i++) {
  599. sc->chunk_offsets[i] = get_be64(pb);
  600. /*printf("chunk offset=%ld\n", sc->chunk_offsets[i]);*/
  601. }
  602. } else
  603. return -1;
  604. return 0;
  605. }
  606. static int parse_stsc(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  607. {
  608. MOVContext *c;
  609. int entries, i;
  610. AVStream *st;
  611. MOVStreamContext *sc;
  612. #ifdef DEBUG
  613. print_atom("stsc", atom_type, atom_offset, atom_size);
  614. #endif
  615. c = (MOVContext *)param;
  616. st = c->fc->streams[c->fc->nb_streams-1];
  617. sc = (MOVStreamContext *)st->priv_data;
  618. get_byte(pb); /* version */
  619. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  620. entries = get_be32(pb);
  621. sc->sample_to_chunk_sz = entries;
  622. sc->sample_to_chunk = av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl));
  623. for(i=0; i<entries; i++) {
  624. sc->sample_to_chunk[i].first = get_be32(pb);
  625. sc->sample_to_chunk[i].count = get_be32(pb);
  626. sc->sample_to_chunk[i].id = get_be32(pb);
  627. #ifdef DEBUG
  628. /* 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); */
  629. #endif
  630. }
  631. return 0;
  632. }
  633. static int parse_stsz(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  634. {
  635. MOVContext *c;
  636. int entries, i;
  637. AVStream *st;
  638. MOVStreamContext *sc;
  639. #ifdef DEBUG
  640. print_atom("stsz", atom_type, atom_offset, atom_size);
  641. #endif
  642. c = (MOVContext *)param;
  643. st = c->fc->streams[c->fc->nb_streams-1];
  644. sc = (MOVStreamContext *)st->priv_data;
  645. get_byte(pb); /* version */
  646. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  647. sc->sample_size = get_be32(pb);
  648. entries = get_be32(pb);
  649. sc->sample_count = entries;
  650. #ifdef DEBUG
  651. printf("sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count);
  652. #endif
  653. if(sc->sample_size)
  654. return 0; /* there isn't any table following */
  655. sc->sample_sizes = av_malloc(entries * sizeof(long));
  656. for(i=0; i<entries; i++) {
  657. sc->sample_sizes[i] = get_be32(pb);
  658. #ifdef DEBUG
  659. /* printf("sample_sizes[]=%ld\n", sc->sample_sizes[i]); */
  660. #endif
  661. }
  662. return 0;
  663. }
  664. static int parse_stts(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  665. {
  666. MOVContext *c;
  667. int entries, i;
  668. AVStream *st;
  669. MOVStreamContext *sc;
  670. #ifdef DEBUG
  671. print_atom("stts", atom_type, atom_offset, atom_size);
  672. #endif
  673. c = (MOVContext *)param;
  674. st = c->fc->streams[c->fc->nb_streams-1];
  675. sc = (MOVStreamContext *)st->priv_data;
  676. get_byte(pb); /* version */
  677. get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
  678. entries = get_be32(pb);
  679. for(i=0; i<entries; i++) {
  680. int sample_duration;
  681. get_be32(pb);
  682. sample_duration = get_be32(pb);
  683. if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {
  684. st->codec.frame_rate = FRAME_RATE_BASE * c->streams[c->total_streams]->time_scale / sample_duration;
  685. #ifdef DEBUG
  686. printf("VIDEO FRAME RATE= %li (sd= %li)\n", st->codec.frame_rate, sample_duration);
  687. #endif
  688. }
  689. }
  690. return 0;
  691. }
  692. #ifdef CONFIG_ZLIB
  693. static int null_read_packet(void *opaque, UINT8 *buf, int buf_size)
  694. {
  695. return -1;
  696. }
  697. static int parse_cmov(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
  698. {
  699. MOVContext *c;
  700. ByteIOContext ctx;
  701. char *cmov_data;
  702. unsigned char *moov_data; /* uncompressed data */
  703. long cmov_len, moov_len;
  704. int ret;
  705. #ifdef DEBUG
  706. print_atom("cmov", atom_type, atom_offset, atom_size);
  707. #endif
  708. c = (MOVContext *)param;
  709. get_be32(pb); /* dcom atom */
  710. if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' ))
  711. return -1;
  712. if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) {
  713. puts("unknown compression for cmov atom !");
  714. return -1;
  715. }
  716. get_be32(pb); /* cmvd atom */
  717. if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' ))
  718. return -1;
  719. moov_len = get_be32(pb); /* uncompressed size */
  720. cmov_len = atom_size - 6 * 4;
  721. cmov_data = av_malloc(cmov_len);
  722. if (!cmov_data)
  723. return -1;
  724. moov_data = av_malloc(moov_len);
  725. if (!moov_data) {
  726. av_free(cmov_data);
  727. return -1;
  728. }
  729. get_buffer(pb, cmov_data, cmov_len);
  730. if(uncompress (moov_data, &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
  731. return -1;
  732. if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0)
  733. return -1;
  734. ctx.buf_end = ctx.buffer + moov_len;
  735. ret = parse_default(parse_table, &ctx, MKTAG( 'm', 'o', 'o', 'v' ), 0, moov_len, param);
  736. av_free(moov_data);
  737. av_free(cmov_data);
  738. return ret;
  739. }
  740. #endif
  741. static const MOVParseTableEntry mov_default_parse_table[] = {
  742. /* mp4 atoms */
  743. { MKTAG( 'm', 'p', '4', 'a' ), parse_default },
  744. { MKTAG( 'c', 'o', '6', '4' ), parse_stco },
  745. { MKTAG( 's', 't', 'c', 'o' ), parse_stco },
  746. { MKTAG( 'c', 'r', 'h', 'd' ), parse_default },
  747. { MKTAG( 'c', 't', 't', 's' ), parse_leaf },
  748. { MKTAG( 'c', 'p', 'r', 't' ), parse_default },
  749. { MKTAG( 'u', 'r', 'l', ' ' ), parse_leaf },
  750. { MKTAG( 'u', 'r', 'n', ' ' ), parse_leaf },
  751. { MKTAG( 'd', 'i', 'n', 'f' ), parse_default },
  752. { MKTAG( 'd', 'r', 'e', 'f' ), parse_leaf },
  753. { MKTAG( 's', 't', 'd', 'p' ), parse_default },
  754. { MKTAG( 'e', 's', 'd', 's' ), parse_default },
  755. { MKTAG( 'e', 'd', 't', 's' ), parse_default },
  756. { MKTAG( 'e', 'l', 's', 't' ), parse_leaf },
  757. { MKTAG( 'u', 'u', 'i', 'd' ), parse_default },
  758. { MKTAG( 'f', 'r', 'e', 'e' ), parse_leaf },
  759. { MKTAG( 'h', 'd', 'l', 'r' ), parse_hdlr },
  760. { MKTAG( 'h', 'm', 'h', 'd' ), parse_default },
  761. { MKTAG( 'h', 'i', 'n', 't' ), parse_leaf },
  762. { MKTAG( 'n', 'm', 'h', 'd' ), parse_leaf },
  763. { MKTAG( 'm', 'p', '4', 's' ), parse_default },
  764. { MKTAG( 'm', 'd', 'i', 'a' ), parse_default },
  765. { MKTAG( 'm', 'd', 'a', 't' ), parse_mdat },
  766. { MKTAG( 'm', 'd', 'h', 'd' ), parse_mdhd },
  767. { MKTAG( 'm', 'i', 'n', 'f' ), parse_default },
  768. { MKTAG( 'm', 'o', 'o', 'v' ), parse_moov },
  769. { MKTAG( 'm', 'v', 'h', 'd' ), parse_mvhd },
  770. { MKTAG( 'i', 'o', 'd', 's' ), parse_leaf },
  771. { MKTAG( 'o', 'd', 'h', 'd' ), parse_default },
  772. { MKTAG( 'm', 'p', 'o', 'd' ), parse_leaf },
  773. { MKTAG( 's', 't', 's', 'd' ), parse_stsd },
  774. { MKTAG( 's', 't', 's', 'z' ), parse_stsz },
  775. { MKTAG( 's', 't', 'b', 'l' ), parse_default },
  776. { MKTAG( 's', 't', 's', 'c' ), parse_stsc },
  777. { MKTAG( 's', 'd', 'h', 'd' ), parse_default },
  778. { MKTAG( 's', 't', 's', 'h' ), parse_default },
  779. { MKTAG( 's', 'k', 'i', 'p' ), parse_default },
  780. { MKTAG( 's', 'm', 'h', 'd' ), parse_leaf },
  781. { MKTAG( 'd', 'p', 'n', 'd' ), parse_leaf },
  782. { MKTAG( 's', 't', 's', 's' ), parse_leaf },
  783. { MKTAG( 's', 't', 't', 's' ), parse_stts },
  784. { MKTAG( 't', 'r', 'a', 'k' ), parse_trak },
  785. { MKTAG( 't', 'k', 'h', 'd' ), parse_tkhd },
  786. { MKTAG( 't', 'r', 'e', 'f' ), parse_default }, /* not really */
  787. { MKTAG( 'u', 'd', 't', 'a' ), parse_leaf },
  788. { MKTAG( 'v', 'm', 'h', 'd' ), parse_leaf },
  789. { MKTAG( 'm', 'p', '4', 'v' ), parse_default },
  790. /* extra mp4 */
  791. { MKTAG( 'M', 'D', 'E', 'S' ), parse_leaf },
  792. /* QT atoms */
  793. { MKTAG( 'c', 'h', 'a', 'p' ), parse_leaf },
  794. { MKTAG( 'c', 'l', 'i', 'p' ), parse_default },
  795. { MKTAG( 'c', 'r', 'g', 'n' ), parse_leaf },
  796. { MKTAG( 'k', 'm', 'a', 't' ), parse_leaf },
  797. { MKTAG( 'm', 'a', 't', 't' ), parse_default },
  798. { MKTAG( 'r', 'd', 'r', 'f' ), parse_leaf },
  799. { MKTAG( 'r', 'm', 'd', 'a' ), parse_default },
  800. { MKTAG( 'r', 'm', 'd', 'r' ), parse_leaf },
  801. //{ MKTAG( 'r', 'm', 'q', 'u' ), parse_leaf },
  802. { MKTAG( 'r', 'm', 'r', 'a' ), parse_default },
  803. { MKTAG( 's', 'c', 'p', 't' ), parse_leaf },
  804. { MKTAG( 's', 'y', 'n', 'c' ), parse_leaf },
  805. { MKTAG( 's', 's', 'r', 'c' ), parse_leaf },
  806. { MKTAG( 't', 'c', 'm', 'd' ), parse_leaf },
  807. { MKTAG( 'w', 'i', 'd', 'e' ), parse_leaf }, /* place holder */
  808. #ifdef CONFIG_ZLIB
  809. { MKTAG( 'c', 'm', 'o', 'v' ), parse_cmov },
  810. #else
  811. { MKTAG( 'c', 'm', 'o', 'v' ), parse_leaf },
  812. #endif
  813. { 0L, parse_leaf }
  814. };
  815. static void mov_free_stream_context(MOVStreamContext *sc)
  816. {
  817. if(sc) {
  818. av_free(sc->chunk_offsets);
  819. av_free(sc->sample_to_chunk);
  820. av_free(sc);
  821. }
  822. }
  823. /* XXX: is it suffisant ? */
  824. static int mov_probe(AVProbeData *p)
  825. {
  826. /* check file header */
  827. if (p->buf_size <= 12)
  828. return 0;
  829. if ((p->buf[4] == 'm' && p->buf[5] == 'o' &&
  830. p->buf[6] == 'o' && p->buf[7] == 'v') ||
  831. (p->buf[4] == 'w' && p->buf[5] == 'i' &&
  832. p->buf[6] == 'd' && p->buf[7] == 'e') ||
  833. (p->buf[4] == 'f' && p->buf[5] == 'r' &&
  834. p->buf[6] == 'e' && p->buf[7] == 'e') ||
  835. (p->buf[4] == 'm' && p->buf[5] == 'd' &&
  836. p->buf[6] == 'a' && p->buf[7] == 't'))
  837. return AVPROBE_SCORE_MAX;
  838. else
  839. return 0;
  840. }
  841. static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
  842. {
  843. MOVContext *mov = s->priv_data;
  844. ByteIOContext *pb = &s->pb;
  845. int i, j, nb, err;
  846. INT64 size;
  847. mov->fc = s;
  848. #if 0
  849. /* XXX: I think we should auto detect */
  850. if(s->iformat->name[1] == 'p')
  851. mov->mp4 = 1;
  852. #endif
  853. if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
  854. size = url_filesize(url_fileno(pb));
  855. else
  856. size = 0x7FFFFFFFFFFFFFFF;
  857. #ifdef DEBUG
  858. printf("filesz=%Ld\n", size);
  859. #endif
  860. /* check MOV header */
  861. err = parse_default(mov_default_parse_table, pb, 0L, 0LL, size, mov);
  862. if(err<0 || (!mov->found_moov || !mov->found_mdat)) {
  863. puts("header not found !!!");
  864. exit(1);
  865. }
  866. #ifdef DEBUG
  867. printf("on_parse_exit_offset=%d\n", (int) url_ftell(pb));
  868. #endif
  869. /* some cleanup : make sure we are on the mdat atom */
  870. if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset))
  871. url_fseek(pb, mov->mdat_offset, SEEK_SET);
  872. mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */
  873. #ifdef DEBUG
  874. printf("mdat_reset_offset=%d\n", (int) url_ftell(pb));
  875. #endif
  876. #ifdef DEBUG
  877. printf("streams= %d\n", s->nb_streams);
  878. #endif
  879. mov->total_streams = nb = s->nb_streams;
  880. #if 1
  881. for(i=0; i<s->nb_streams;) {
  882. if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */
  883. av_free(s->streams[i]);
  884. for(j=i+1; j<s->nb_streams; j++)
  885. s->streams[j-1] = s->streams[j];
  886. s->nb_streams--;
  887. } else
  888. i++;
  889. }
  890. for(i=0; i<s->nb_streams;i++) {
  891. MOVStreamContext *sc;
  892. sc = (MOVStreamContext *)s->streams[i]->priv_data;
  893. sc->ffindex = i;
  894. sc->is_ff_stream = 1;
  895. }
  896. #endif
  897. #ifdef DEBUG
  898. printf("real streams= %d\n", s->nb_streams);
  899. #endif
  900. return 0;
  901. }
  902. /* Yes, this is ugly... I didn't write the specs of QT :p */
  903. /* XXX:remove useless commented code sometime */
  904. static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
  905. {
  906. MOVContext *mov = s->priv_data;
  907. INT64 offset = 0x0FFFFFFFFFFFFFFF;
  908. int i;
  909. int st_id = 0, size;
  910. size = 0x0FFFFFFF;
  911. again:
  912. for(i=0; i<mov->total_streams; i++) {
  913. /* printf("%8ld ", mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk]); */
  914. if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
  915. && (mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] < offset)) {
  916. /* printf("y"); */
  917. st_id = i;
  918. offset = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk];
  919. }
  920. /* else printf("n"); */
  921. }
  922. mov->streams[st_id]->next_chunk++;
  923. if(offset==0x0FFFFFFFFFFFFFFF)
  924. return -1;
  925. if(mov->next_chunk_offset < offset) /* some meta data */
  926. url_fskip(&s->pb, (offset - mov->next_chunk_offset));
  927. if(!mov->streams[st_id]->is_ff_stream) {
  928. url_fskip(&s->pb, (offset - mov->next_chunk_offset));
  929. offset = 0x0FFFFFFFFFFFFFFF;
  930. /* puts("*"); */
  931. goto again;
  932. }
  933. /* printf("\nchunk offset = %ld\n", offset); */
  934. /* now get the chunk size... */
  935. for(i=0; i<mov->total_streams; i++) {
  936. /* printf("%ld ", mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset); */
  937. if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
  938. && ((mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset) < size)) {
  939. /* printf("y"); */
  940. size = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset;
  941. }
  942. /* else printf("n"); */
  943. }
  944. /* printf("\nchunk size = %ld\n", size); */
  945. if(size == 0x0FFFFFFF)
  946. size = mov->mdat_size + mov->mdat_offset - offset;
  947. if(size < 0)
  948. return -1;
  949. if(size == 0)
  950. return -1;
  951. av_new_packet(pkt, size);
  952. pkt->stream_index = mov->streams[st_id]->ffindex;
  953. get_buffer(&s->pb, pkt->data, pkt->size);
  954. #ifdef DEBUG
  955. /*
  956. printf("Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size);
  957. for(i=0; i<8; i++)
  958. printf("%02x ", pkt->data[i]);
  959. for(i=0; i<8; i++)
  960. printf("%c ", (pkt->data[i]) & 0x7F);
  961. puts("");
  962. */
  963. #endif
  964. mov->next_chunk_offset = offset + size;
  965. return 0;
  966. }
  967. static int mov_read_close(AVFormatContext *s)
  968. {
  969. int i;
  970. MOVContext *mov = s->priv_data;
  971. for(i=0; i<mov->total_streams; i++)
  972. mov_free_stream_context(mov->streams[i]);
  973. for(i=0; i<s->nb_streams; i++)
  974. av_free(s->streams[i]);
  975. return 0;
  976. }
  977. static AVInputFormat mov_iformat = {
  978. "mov",
  979. "QuickTime/MPEG4 format",
  980. sizeof(MOVContext),
  981. mov_probe,
  982. mov_read_header,
  983. mov_read_packet,
  984. mov_read_close,
  985. };
  986. int mov_init(void)
  987. {
  988. av_register_input_format(&mov_iformat);
  989. return 0;
  990. }