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.

1740 lines
59KB

  1. /*
  2. * MOV demuxer
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <limits.h>
  22. //#define DEBUG
  23. #include "avformat.h"
  24. #include "riff.h"
  25. #include "isom.h"
  26. #include "dv.h"
  27. #ifdef CONFIG_ZLIB
  28. #include <zlib.h>
  29. #endif
  30. /*
  31. * First version by Francois Revol revol@free.fr
  32. * Seek function by Gael Chardon gael.dev@4now.net
  33. *
  34. * Features and limitations:
  35. * - reads most of the QT files I have (at least the structure),
  36. * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html
  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/documentation/QuickTime/QTFF/
  46. * http://developer.apple.com/documentation/QuickTime/QTFF/qtff.pdf
  47. * QuickTime is a trademark of Apple (AFAIK :))
  48. */
  49. #include "qtpalette.h"
  50. #undef NDEBUG
  51. #include <assert.h>
  52. /* the QuickTime file format is quite convoluted...
  53. * it has lots of index tables, each indexing something in another one...
  54. * Here we just use what is needed to read the chunks
  55. */
  56. typedef struct {
  57. int first;
  58. int count;
  59. int id;
  60. } MOV_stsc_t;
  61. typedef struct {
  62. uint32_t type;
  63. char *path;
  64. } MOV_dref_t;
  65. typedef struct {
  66. uint32_t type;
  67. int64_t offset;
  68. int64_t size; /* total size (excluding the size and type fields) */
  69. } MOV_atom_t;
  70. struct MOVParseTableEntry;
  71. typedef struct MOVStreamContext {
  72. ByteIOContext *pb;
  73. int ffindex; /* the ffmpeg stream id */
  74. int next_chunk;
  75. unsigned int chunk_count;
  76. int64_t *chunk_offsets;
  77. unsigned int stts_count;
  78. MOV_stts_t *stts_data;
  79. unsigned int ctts_count;
  80. MOV_stts_t *ctts_data;
  81. unsigned int edit_count; /* number of 'edit' (elst atom) */
  82. unsigned int sample_to_chunk_sz;
  83. MOV_stsc_t *sample_to_chunk;
  84. int sample_to_ctime_index;
  85. int sample_to_ctime_sample;
  86. unsigned int sample_size;
  87. unsigned int sample_count;
  88. int *sample_sizes;
  89. unsigned int keyframe_count;
  90. int *keyframes;
  91. int time_scale;
  92. int time_rate;
  93. int current_sample;
  94. unsigned int bytes_per_frame;
  95. unsigned int samples_per_frame;
  96. int dv_audio_container;
  97. int pseudo_stream_id;
  98. int16_t audio_cid; ///< stsd audio compression id
  99. unsigned drefs_count;
  100. MOV_dref_t *drefs;
  101. int dref_id;
  102. } MOVStreamContext;
  103. typedef struct MOVContext {
  104. AVFormatContext *fc;
  105. int time_scale;
  106. int64_t duration; /* duration of the longest track */
  107. int found_moov; /* when both 'moov' and 'mdat' sections has been found */
  108. int found_mdat; /* we suppose we have enough data to read the file */
  109. AVPaletteControl palette_control;
  110. DVDemuxContext *dv_demux;
  111. AVFormatContext *dv_fctx;
  112. int isom; /* 1 if file is ISO Media (mp4/3gp) */
  113. } MOVContext;
  114. /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
  115. /* those functions parse an atom */
  116. /* return code:
  117. 1: found what I wanted, exit
  118. 0: continue to parse next atom
  119. -1: error occured, exit
  120. */
  121. /* links atom IDs to parse functions */
  122. typedef struct MOVParseTableEntry {
  123. uint32_t type;
  124. int (*parse)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom);
  125. } MOVParseTableEntry;
  126. static const MOVParseTableEntry mov_default_parse_table[];
  127. static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  128. {
  129. int64_t total_size = 0;
  130. MOV_atom_t a;
  131. int i;
  132. int err = 0;
  133. a.offset = atom.offset;
  134. if (atom.size < 0)
  135. atom.size = INT64_MAX;
  136. while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) {
  137. a.size = atom.size;
  138. a.type=0;
  139. if(atom.size >= 8) {
  140. a.size = get_be32(pb);
  141. a.type = get_le32(pb);
  142. }
  143. total_size += 8;
  144. a.offset += 8;
  145. dprintf(c->fc, "type: %08x %.4s sz: %"PRIx64" %"PRIx64" %"PRIx64"\n",
  146. a.type, (char*)&a.type, a.size, atom.size, total_size);
  147. if (a.size == 1) { /* 64 bit extended size */
  148. a.size = get_be64(pb) - 8;
  149. a.offset += 8;
  150. total_size += 8;
  151. }
  152. if (a.size == 0) {
  153. a.size = atom.size - total_size;
  154. if (a.size <= 8)
  155. break;
  156. }
  157. a.size -= 8;
  158. if(a.size < 0)
  159. break;
  160. a.size = FFMIN(a.size, atom.size - total_size);
  161. for (i = 0; mov_default_parse_table[i].type != 0
  162. && mov_default_parse_table[i].type != a.type; i++)
  163. /* empty */;
  164. if (mov_default_parse_table[i].type == 0) { /* skip leaf atoms data */
  165. url_fskip(pb, a.size);
  166. } else {
  167. offset_t start_pos = url_ftell(pb);
  168. int64_t left;
  169. err = mov_default_parse_table[i].parse(c, pb, a);
  170. if (c->found_moov && c->found_mdat)
  171. break;
  172. left = a.size - url_ftell(pb) + start_pos;
  173. if (left > 0) /* skip garbage at atom end */
  174. url_fskip(pb, left);
  175. }
  176. a.offset += a.size;
  177. total_size += a.size;
  178. }
  179. if (!err && total_size < atom.size && atom.size < 0x7ffff) {
  180. url_fskip(pb, atom.size - total_size);
  181. }
  182. return err;
  183. }
  184. static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  185. {
  186. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  187. MOVStreamContext *sc = st->priv_data;
  188. int entries, i, j;
  189. get_be32(pb); // version + flags
  190. entries = get_be32(pb);
  191. if (entries >= UINT_MAX / sizeof(*sc->drefs))
  192. return -1;
  193. sc->drefs_count = entries;
  194. sc->drefs = av_mallocz(entries * sizeof(*sc->drefs));
  195. for (i = 0; i < sc->drefs_count; i++) {
  196. MOV_dref_t *dref = &sc->drefs[i];
  197. uint32_t size = get_be32(pb);
  198. offset_t next = url_ftell(pb) + size - 4;
  199. dref->type = get_le32(pb);
  200. get_be32(pb); // version + flags
  201. dprintf(c->fc, "type %.4s size %d\n", (char*)&dref->type, size);
  202. if (dref->type == MKTAG('a','l','i','s') && size > 150) {
  203. /* macintosh alias record */
  204. uint16_t volume_len, len;
  205. char volume[28];
  206. int16_t type;
  207. url_fskip(pb, 10);
  208. volume_len = get_byte(pb);
  209. volume_len = FFMIN(volume_len, 27);
  210. get_buffer(pb, volume, 27);
  211. volume[volume_len] = 0;
  212. av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", volume, volume_len);
  213. url_fskip(pb, 112);
  214. for (type = 0; type != -1 && url_ftell(pb) < next; ) {
  215. type = get_be16(pb);
  216. len = get_be16(pb);
  217. av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);
  218. if (len&1)
  219. len += 1;
  220. if (type == 2) { // absolute path
  221. av_free(dref->path);
  222. dref->path = av_mallocz(len+1);
  223. if (!dref->path)
  224. return AVERROR(ENOMEM);
  225. get_buffer(pb, dref->path, len);
  226. if (len > volume_len && !strncmp(dref->path, volume, volume_len)) {
  227. len -= volume_len;
  228. memmove(dref->path, dref->path+volume_len, len);
  229. dref->path[len] = 0;
  230. }
  231. for (j = 0; j < len; j++)
  232. if (dref->path[j] == ':')
  233. dref->path[j] = '/';
  234. av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path);
  235. } else
  236. url_fskip(pb, len);
  237. }
  238. }
  239. url_fseek(pb, next, SEEK_SET);
  240. }
  241. return 0;
  242. }
  243. static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  244. {
  245. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  246. uint32_t type;
  247. uint32_t ctype;
  248. get_byte(pb); /* version */
  249. get_be24(pb); /* flags */
  250. /* component type */
  251. ctype = get_le32(pb);
  252. type = get_le32(pb); /* component subtype */
  253. dprintf(c->fc, "ctype= %c%c%c%c (0x%08x)\n", *((char *)&ctype), ((char *)&ctype)[1],
  254. ((char *)&ctype)[2], ((char *)&ctype)[3], (int) ctype);
  255. dprintf(c->fc, "stype= %c%c%c%c\n",
  256. *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
  257. if(!ctype)
  258. c->isom = 1;
  259. if(type == MKTAG('v', 'i', 'd', 'e'))
  260. st->codec->codec_type = CODEC_TYPE_VIDEO;
  261. else if(type == MKTAG('s', 'o', 'u', 'n'))
  262. st->codec->codec_type = CODEC_TYPE_AUDIO;
  263. else if(type == MKTAG('m', '1', 'a', ' '))
  264. st->codec->codec_id = CODEC_ID_MP2;
  265. else if(type == MKTAG('s', 'u', 'b', 'p')) {
  266. st->codec->codec_type = CODEC_TYPE_SUBTITLE;
  267. }
  268. get_be32(pb); /* component manufacture */
  269. get_be32(pb); /* component flags */
  270. get_be32(pb); /* component flags mask */
  271. if(atom.size <= 24)
  272. return 0; /* nothing left to read */
  273. url_fskip(pb, atom.size - (url_ftell(pb) - atom.offset));
  274. return 0;
  275. }
  276. static int mp4_read_descr_len(ByteIOContext *pb)
  277. {
  278. int len = 0;
  279. int count = 4;
  280. while (count--) {
  281. int c = get_byte(pb);
  282. len = (len << 7) | (c & 0x7f);
  283. if (!(c & 0x80))
  284. break;
  285. }
  286. return len;
  287. }
  288. static int mp4_read_descr(MOVContext *c, ByteIOContext *pb, int *tag)
  289. {
  290. int len;
  291. *tag = get_byte(pb);
  292. len = mp4_read_descr_len(pb);
  293. dprintf(c->fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
  294. return len;
  295. }
  296. #define MP4ESDescrTag 0x03
  297. #define MP4DecConfigDescrTag 0x04
  298. #define MP4DecSpecificDescrTag 0x05
  299. static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  300. {
  301. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  302. int tag, len;
  303. get_be32(pb); /* version + flags */
  304. len = mp4_read_descr(c, pb, &tag);
  305. if (tag == MP4ESDescrTag) {
  306. get_be16(pb); /* ID */
  307. get_byte(pb); /* priority */
  308. } else
  309. get_be16(pb); /* ID */
  310. len = mp4_read_descr(c, pb, &tag);
  311. if (tag == MP4DecConfigDescrTag) {
  312. int object_type_id = get_byte(pb);
  313. get_byte(pb); /* stream type */
  314. get_be24(pb); /* buffer size db */
  315. get_be32(pb); /* max bitrate */
  316. get_be32(pb); /* avg bitrate */
  317. st->codec->codec_id= codec_get_id(ff_mp4_obj_type, object_type_id);
  318. dprintf(c->fc, "esds object type id %d\n", object_type_id);
  319. len = mp4_read_descr(c, pb, &tag);
  320. if (tag == MP4DecSpecificDescrTag) {
  321. dprintf(c->fc, "Specific MPEG4 header len=%d\n", len);
  322. if((uint64_t)len > (1<<30))
  323. return -1;
  324. st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
  325. if (!st->codec->extradata)
  326. return AVERROR(ENOMEM);
  327. get_buffer(pb, st->codec->extradata, len);
  328. st->codec->extradata_size = len;
  329. /* from mplayer */
  330. if ((*st->codec->extradata >> 3) == 29) {
  331. st->codec->codec_id = CODEC_ID_MP3ON4;
  332. }
  333. }
  334. }
  335. return 0;
  336. }
  337. /* this atom contains actual media data */
  338. static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  339. {
  340. if(atom.size == 0) /* wrong one (MP4) */
  341. return 0;
  342. c->found_mdat=1;
  343. if(c->found_moov)
  344. return 1; /* found both, just go */
  345. url_fskip(pb, atom.size);
  346. return 0; /* now go for moov */
  347. }
  348. static int mov_read_ftyp(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  349. {
  350. uint32_t type = get_le32(pb);
  351. if (type != MKTAG('q','t',' ',' '))
  352. c->isom = 1;
  353. av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
  354. get_be32(pb); /* minor version */
  355. url_fskip(pb, atom.size - 8);
  356. return 0;
  357. }
  358. /* this atom should contain all header atoms */
  359. static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  360. {
  361. if (mov_read_default(c, pb, atom) < 0)
  362. return -1;
  363. /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
  364. /* so we don't parse the whole file if over a network */
  365. c->found_moov=1;
  366. if(c->found_mdat)
  367. return 1; /* found both, just go */
  368. return 0; /* now go for mdat */
  369. }
  370. static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  371. {
  372. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  373. MOVStreamContext *sc = st->priv_data;
  374. int version = get_byte(pb);
  375. int lang;
  376. if (version > 1)
  377. return 1; /* unsupported */
  378. get_be24(pb); /* flags */
  379. if (version == 1) {
  380. get_be64(pb);
  381. get_be64(pb);
  382. } else {
  383. get_be32(pb); /* creation time */
  384. get_be32(pb); /* modification time */
  385. }
  386. sc->time_scale = get_be32(pb);
  387. st->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */
  388. lang = get_be16(pb); /* language */
  389. ff_mov_lang_to_iso639(lang, st->language);
  390. get_be16(pb); /* quality */
  391. return 0;
  392. }
  393. static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  394. {
  395. int version = get_byte(pb); /* version */
  396. get_be24(pb); /* flags */
  397. if (version == 1) {
  398. get_be64(pb);
  399. get_be64(pb);
  400. } else {
  401. get_be32(pb); /* creation time */
  402. get_be32(pb); /* modification time */
  403. }
  404. c->time_scale = get_be32(pb); /* time scale */
  405. dprintf(c->fc, "time scale = %i\n", c->time_scale);
  406. c->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */
  407. get_be32(pb); /* preferred scale */
  408. get_be16(pb); /* preferred volume */
  409. url_fskip(pb, 10); /* reserved */
  410. url_fskip(pb, 36); /* display matrix */
  411. get_be32(pb); /* preview time */
  412. get_be32(pb); /* preview duration */
  413. get_be32(pb); /* poster time */
  414. get_be32(pb); /* selection time */
  415. get_be32(pb); /* selection duration */
  416. get_be32(pb); /* current time */
  417. get_be32(pb); /* next track ID */
  418. return 0;
  419. }
  420. static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  421. {
  422. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  423. if((uint64_t)atom.size > (1<<30))
  424. return -1;
  425. // currently SVQ3 decoder expect full STSD header - so let's fake it
  426. // this should be fixed and just SMI header should be passed
  427. av_free(st->codec->extradata);
  428. st->codec->extradata = av_mallocz(atom.size + 0x5a + FF_INPUT_BUFFER_PADDING_SIZE);
  429. if (!st->codec->extradata)
  430. return AVERROR(ENOMEM);
  431. st->codec->extradata_size = 0x5a + atom.size;
  432. memcpy(st->codec->extradata, "SVQ3", 4); // fake
  433. get_buffer(pb, st->codec->extradata + 0x5a, atom.size);
  434. dprintf(c->fc, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a);
  435. return 0;
  436. }
  437. static int mov_read_enda(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  438. {
  439. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  440. int little_endian = get_be16(pb);
  441. if (little_endian) {
  442. switch (st->codec->codec_id) {
  443. case CODEC_ID_PCM_S24BE:
  444. st->codec->codec_id = CODEC_ID_PCM_S24LE;
  445. break;
  446. case CODEC_ID_PCM_S32BE:
  447. st->codec->codec_id = CODEC_ID_PCM_S32LE;
  448. break;
  449. default:
  450. break;
  451. }
  452. }
  453. return 0;
  454. }
  455. /* FIXME modify qdm2/svq3/h264 decoders to take full atom as extradata */
  456. static int mov_read_extradata(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  457. {
  458. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  459. uint64_t size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE;
  460. uint8_t *buf;
  461. if(size > INT_MAX || (uint64_t)atom.size > INT_MAX)
  462. return -1;
  463. buf= av_realloc(st->codec->extradata, size);
  464. if(!buf)
  465. return -1;
  466. st->codec->extradata= buf;
  467. buf+= st->codec->extradata_size;
  468. st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE;
  469. AV_WB32( buf , atom.size + 8);
  470. AV_WL32( buf + 4, atom.type);
  471. get_buffer(pb, buf + 8, atom.size);
  472. return 0;
  473. }
  474. static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  475. {
  476. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  477. if((uint64_t)atom.size > (1<<30))
  478. return -1;
  479. if (st->codec->codec_id == CODEC_ID_QDM2) {
  480. // pass all frma atom to codec, needed at least for QDM2
  481. av_free(st->codec->extradata);
  482. st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE);
  483. if (!st->codec->extradata)
  484. return AVERROR(ENOMEM);
  485. st->codec->extradata_size = atom.size;
  486. get_buffer(pb, st->codec->extradata, atom.size);
  487. } else if (atom.size > 8) { /* to read frma, esds atoms */
  488. if (mov_read_default(c, pb, atom) < 0)
  489. return -1;
  490. } else
  491. url_fskip(pb, atom.size);
  492. return 0;
  493. }
  494. /**
  495. * This function reads atom content and puts data in extradata without tag
  496. * nor size unlike mov_read_extradata.
  497. */
  498. static int mov_read_glbl(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  499. {
  500. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  501. if((uint64_t)atom.size > (1<<30))
  502. return -1;
  503. av_free(st->codec->extradata);
  504. st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE);
  505. if (!st->codec->extradata)
  506. return AVERROR(ENOMEM);
  507. st->codec->extradata_size = atom.size;
  508. get_buffer(pb, st->codec->extradata, atom.size);
  509. return 0;
  510. }
  511. static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  512. {
  513. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  514. MOVStreamContext *sc = st->priv_data;
  515. unsigned int i, entries;
  516. get_byte(pb); /* version */
  517. get_be24(pb); /* flags */
  518. entries = get_be32(pb);
  519. if(entries >= UINT_MAX/sizeof(int64_t))
  520. return -1;
  521. sc->chunk_count = entries;
  522. sc->chunk_offsets = av_malloc(entries * sizeof(int64_t));
  523. if (!sc->chunk_offsets)
  524. return -1;
  525. if (atom.type == MKTAG('s', 't', 'c', 'o')) {
  526. for(i=0; i<entries; i++) {
  527. sc->chunk_offsets[i] = get_be32(pb);
  528. }
  529. } else if (atom.type == MKTAG('c', 'o', '6', '4')) {
  530. for(i=0; i<entries; i++) {
  531. sc->chunk_offsets[i] = get_be64(pb);
  532. }
  533. } else
  534. return -1;
  535. return 0;
  536. }
  537. static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  538. {
  539. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  540. MOVStreamContext *sc = st->priv_data;
  541. int entries, frames_per_sample;
  542. uint32_t format;
  543. uint8_t codec_name[32];
  544. /* for palette traversal */
  545. unsigned int color_depth;
  546. unsigned int color_start;
  547. unsigned int color_count;
  548. unsigned int color_end;
  549. int color_index;
  550. int color_dec;
  551. int color_greyscale;
  552. const uint8_t *color_table;
  553. int j, pseudo_stream_id;
  554. unsigned char r, g, b;
  555. get_byte(pb); /* version */
  556. get_be24(pb); /* flags */
  557. entries = get_be32(pb);
  558. for(pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) { //Parsing Sample description table
  559. enum CodecID id;
  560. int dref_id;
  561. MOV_atom_t a = { 0, 0, 0 };
  562. offset_t start_pos = url_ftell(pb);
  563. int size = get_be32(pb); /* size */
  564. format = get_le32(pb); /* data format */
  565. get_be32(pb); /* reserved */
  566. get_be16(pb); /* reserved */
  567. dref_id = get_be16(pb);
  568. if (st->codec->codec_tag &&
  569. (c->fc->video_codec_id ? codec_get_id(codec_movvideo_tags, format) != c->fc->video_codec_id
  570. : st->codec->codec_tag != MKTAG('j', 'p', 'e', 'g'))
  571. ){
  572. /* Multiple fourcc, we skip JPEG. This is not correct, we should
  573. * export it as a separate AVStream but this needs a few changes
  574. * in the MOV demuxer, patch welcome. */
  575. url_fskip(pb, size - (url_ftell(pb) - start_pos));
  576. continue;
  577. }
  578. sc->pseudo_stream_id= pseudo_stream_id;
  579. sc->dref_id= dref_id;
  580. st->codec->codec_tag = format;
  581. id = codec_get_id(codec_movaudio_tags, format);
  582. if (id<=0 && (format&0xFFFF) == 'm' + ('s'<<8))
  583. id = codec_get_id(codec_wav_tags, bswap_32(format)&0xFFFF);
  584. if (st->codec->codec_type != CODEC_TYPE_VIDEO && id > 0) {
  585. st->codec->codec_type = CODEC_TYPE_AUDIO;
  586. } else if (st->codec->codec_type != CODEC_TYPE_AUDIO && /* do not overwrite codec type */
  587. format && format != MKTAG('m', 'p', '4', 's')) { /* skip old asf mpeg4 tag */
  588. id = codec_get_id(codec_movvideo_tags, format);
  589. if (id <= 0)
  590. id = codec_get_id(codec_bmp_tags, format);
  591. if (id > 0)
  592. st->codec->codec_type = CODEC_TYPE_VIDEO;
  593. else if(st->codec->codec_type == CODEC_TYPE_DATA){
  594. id = codec_get_id(ff_codec_movsubtitle_tags, format);
  595. if(id > 0)
  596. st->codec->codec_type = CODEC_TYPE_SUBTITLE;
  597. }
  598. }
  599. dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size,
  600. (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,
  601. (format >> 24) & 0xff, st->codec->codec_type);
  602. if(st->codec->codec_type==CODEC_TYPE_VIDEO) {
  603. st->codec->codec_id = id;
  604. get_be16(pb); /* version */
  605. get_be16(pb); /* revision level */
  606. get_be32(pb); /* vendor */
  607. get_be32(pb); /* temporal quality */
  608. get_be32(pb); /* spatial quality */
  609. st->codec->width = get_be16(pb); /* width */
  610. st->codec->height = get_be16(pb); /* height */
  611. get_be32(pb); /* horiz resolution */
  612. get_be32(pb); /* vert resolution */
  613. get_be32(pb); /* data size, always 0 */
  614. frames_per_sample = get_be16(pb); /* frames per samples */
  615. dprintf(c->fc, "frames/samples = %d\n", frames_per_sample);
  616. get_buffer(pb, codec_name, 32); /* codec name, pascal string (FIXME: true for mp4?) */
  617. if (codec_name[0] <= 31) {
  618. memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]);
  619. st->codec->codec_name[codec_name[0]] = 0;
  620. }
  621. st->codec->bits_per_sample = get_be16(pb); /* depth */
  622. st->codec->color_table_id = get_be16(pb); /* colortable id */
  623. dprintf(c->fc, "depth %d, ctab id %d\n",
  624. st->codec->bits_per_sample, st->codec->color_table_id);
  625. /* figure out the palette situation */
  626. color_depth = st->codec->bits_per_sample & 0x1F;
  627. color_greyscale = st->codec->bits_per_sample & 0x20;
  628. /* if the depth is 2, 4, or 8 bpp, file is palettized */
  629. if ((color_depth == 2) || (color_depth == 4) ||
  630. (color_depth == 8)) {
  631. if (color_greyscale) {
  632. /* compute the greyscale palette */
  633. st->codec->bits_per_sample = color_depth;
  634. color_count = 1 << color_depth;
  635. color_index = 255;
  636. color_dec = 256 / (color_count - 1);
  637. for (j = 0; j < color_count; j++) {
  638. r = g = b = color_index;
  639. c->palette_control.palette[j] =
  640. (r << 16) | (g << 8) | (b);
  641. color_index -= color_dec;
  642. if (color_index < 0)
  643. color_index = 0;
  644. }
  645. } else if (st->codec->color_table_id & 0x08) {
  646. /* if flag bit 3 is set, use the default palette */
  647. color_count = 1 << color_depth;
  648. if (color_depth == 2)
  649. color_table = ff_qt_default_palette_4;
  650. else if (color_depth == 4)
  651. color_table = ff_qt_default_palette_16;
  652. else
  653. color_table = ff_qt_default_palette_256;
  654. for (j = 0; j < color_count; j++) {
  655. r = color_table[j * 4 + 0];
  656. g = color_table[j * 4 + 1];
  657. b = color_table[j * 4 + 2];
  658. c->palette_control.palette[j] =
  659. (r << 16) | (g << 8) | (b);
  660. }
  661. } else {
  662. /* load the palette from the file */
  663. color_start = get_be32(pb);
  664. color_count = get_be16(pb);
  665. color_end = get_be16(pb);
  666. if ((color_start <= 255) &&
  667. (color_end <= 255)) {
  668. for (j = color_start; j <= color_end; j++) {
  669. /* each R, G, or B component is 16 bits;
  670. * only use the top 8 bits; skip alpha bytes
  671. * up front */
  672. get_byte(pb);
  673. get_byte(pb);
  674. r = get_byte(pb);
  675. get_byte(pb);
  676. g = get_byte(pb);
  677. get_byte(pb);
  678. b = get_byte(pb);
  679. get_byte(pb);
  680. c->palette_control.palette[j] =
  681. (r << 16) | (g << 8) | (b);
  682. }
  683. }
  684. }
  685. st->codec->palctrl = &c->palette_control;
  686. st->codec->palctrl->palette_changed = 1;
  687. } else
  688. st->codec->palctrl = NULL;
  689. } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) {
  690. int bits_per_sample;
  691. uint16_t version = get_be16(pb);
  692. st->codec->codec_id = id;
  693. get_be16(pb); /* revision level */
  694. get_be32(pb); /* vendor */
  695. st->codec->channels = get_be16(pb); /* channel count */
  696. dprintf(c->fc, "audio channels %d\n", st->codec->channels);
  697. st->codec->bits_per_sample = get_be16(pb); /* sample size */
  698. sc->audio_cid = get_be16(pb);
  699. get_be16(pb); /* packet size = 0 */
  700. st->codec->sample_rate = ((get_be32(pb) >> 16));
  701. switch (st->codec->codec_id) {
  702. case CODEC_ID_PCM_S8:
  703. case CODEC_ID_PCM_U8:
  704. if (st->codec->bits_per_sample == 16)
  705. st->codec->codec_id = CODEC_ID_PCM_S16BE;
  706. break;
  707. case CODEC_ID_PCM_S16LE:
  708. case CODEC_ID_PCM_S16BE:
  709. if (st->codec->bits_per_sample == 8)
  710. st->codec->codec_id = CODEC_ID_PCM_S8;
  711. else if (st->codec->bits_per_sample == 24)
  712. st->codec->codec_id = CODEC_ID_PCM_S24BE;
  713. break;
  714. /* set values for old format before stsd version 1 appeared */
  715. case CODEC_ID_MACE3:
  716. sc->samples_per_frame = 6;
  717. sc->bytes_per_frame = 2*st->codec->channels;
  718. break;
  719. case CODEC_ID_MACE6:
  720. sc->samples_per_frame = 6;
  721. sc->bytes_per_frame = 1*st->codec->channels;
  722. break;
  723. case CODEC_ID_ADPCM_IMA_QT:
  724. sc->samples_per_frame = 64;
  725. sc->bytes_per_frame = 34*st->codec->channels;
  726. break;
  727. default:
  728. break;
  729. }
  730. //Read QT version 1 fields. In version 0 these do not exist.
  731. dprintf(c->fc, "version =%d, isom =%d\n",version,c->isom);
  732. if(!c->isom) {
  733. if(version==1) {
  734. sc->samples_per_frame = get_be32(pb);
  735. get_be32(pb); /* bytes per packet */
  736. sc->bytes_per_frame = get_be32(pb);
  737. get_be32(pb); /* bytes per sample */
  738. } else if(version==2) {
  739. get_be32(pb); /* sizeof struct only */
  740. st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */
  741. st->codec->channels = get_be32(pb);
  742. get_be32(pb); /* always 0x7F000000 */
  743. get_be32(pb); /* bits per channel if sound is uncompressed */
  744. get_be32(pb); /* lcpm format specific flag */
  745. get_be32(pb); /* bytes per audio packet if constant */
  746. get_be32(pb); /* lpcm frames per audio packet if constant */
  747. }
  748. }
  749. bits_per_sample = av_get_bits_per_sample(st->codec->codec_id);
  750. if (bits_per_sample) {
  751. st->codec->bits_per_sample = bits_per_sample;
  752. sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;
  753. }
  754. } else if(st->codec->codec_type==CODEC_TYPE_SUBTITLE){
  755. st->codec->codec_id= id;
  756. } else {
  757. /* other codec type, just skip (rtp, mp4s, tmcd ...) */
  758. url_fskip(pb, size - (url_ftell(pb) - start_pos));
  759. }
  760. /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */
  761. a.size = size - (url_ftell(pb) - start_pos);
  762. if (a.size > 8) {
  763. if (mov_read_default(c, pb, a) < 0)
  764. return -1;
  765. } else if (a.size > 0)
  766. url_fskip(pb, a.size);
  767. }
  768. if(st->codec->codec_type==CODEC_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)
  769. st->codec->sample_rate= sc->time_scale;
  770. /* special codec parameters handling */
  771. switch (st->codec->codec_id) {
  772. #ifdef CONFIG_DV_DEMUXER
  773. case CODEC_ID_DVAUDIO:
  774. c->dv_fctx = av_alloc_format_context();
  775. c->dv_demux = dv_init_demux(c->dv_fctx);
  776. if (!c->dv_demux) {
  777. av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n");
  778. return -1;
  779. }
  780. sc->dv_audio_container = 1;
  781. st->codec->codec_id = CODEC_ID_PCM_S16LE;
  782. break;
  783. #endif
  784. /* no ifdef since parameters are always those */
  785. case CODEC_ID_AMR_WB:
  786. st->codec->sample_rate= 16000;
  787. st->codec->channels= 1; /* really needed */
  788. break;
  789. case CODEC_ID_AMR_NB:
  790. st->codec->sample_rate= 8000;
  791. st->codec->channels= 1; /* really needed */
  792. break;
  793. case CODEC_ID_MP2:
  794. case CODEC_ID_MP3:
  795. st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */
  796. st->need_parsing = AVSTREAM_PARSE_FULL;
  797. break;
  798. case CODEC_ID_ADPCM_MS:
  799. case CODEC_ID_ADPCM_IMA_WAV:
  800. st->codec->block_align = sc->bytes_per_frame;
  801. break;
  802. default:
  803. break;
  804. }
  805. return 0;
  806. }
  807. static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  808. {
  809. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  810. MOVStreamContext *sc = st->priv_data;
  811. unsigned int i, entries;
  812. get_byte(pb); /* version */
  813. get_be24(pb); /* flags */
  814. entries = get_be32(pb);
  815. if(entries >= UINT_MAX / sizeof(MOV_stsc_t))
  816. return -1;
  817. dprintf(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
  818. sc->sample_to_chunk_sz = entries;
  819. sc->sample_to_chunk = av_malloc(entries * sizeof(MOV_stsc_t));
  820. if (!sc->sample_to_chunk)
  821. return -1;
  822. for(i=0; i<entries; i++) {
  823. sc->sample_to_chunk[i].first = get_be32(pb);
  824. sc->sample_to_chunk[i].count = get_be32(pb);
  825. sc->sample_to_chunk[i].id = get_be32(pb);
  826. }
  827. return 0;
  828. }
  829. static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  830. {
  831. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  832. MOVStreamContext *sc = st->priv_data;
  833. unsigned int i, entries;
  834. get_byte(pb); /* version */
  835. get_be24(pb); /* flags */
  836. entries = get_be32(pb);
  837. if(entries >= UINT_MAX / sizeof(int))
  838. return -1;
  839. sc->keyframe_count = entries;
  840. dprintf(c->fc, "keyframe_count = %d\n", sc->keyframe_count);
  841. sc->keyframes = av_malloc(entries * sizeof(int));
  842. if (!sc->keyframes)
  843. return -1;
  844. for(i=0; i<entries; i++) {
  845. sc->keyframes[i] = get_be32(pb);
  846. //dprintf(c->fc, "keyframes[]=%d\n", sc->keyframes[i]);
  847. }
  848. return 0;
  849. }
  850. static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  851. {
  852. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  853. MOVStreamContext *sc = st->priv_data;
  854. unsigned int i, entries, sample_size;
  855. get_byte(pb); /* version */
  856. get_be24(pb); /* flags */
  857. sample_size = get_be32(pb);
  858. if (!sc->sample_size) /* do not overwrite value computed in stsd */
  859. sc->sample_size = sample_size;
  860. entries = get_be32(pb);
  861. if(entries >= UINT_MAX / sizeof(int))
  862. return -1;
  863. sc->sample_count = entries;
  864. if (sample_size)
  865. return 0;
  866. dprintf(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, sc->sample_count);
  867. sc->sample_sizes = av_malloc(entries * sizeof(int));
  868. if (!sc->sample_sizes)
  869. return -1;
  870. for(i=0; i<entries; i++) {
  871. sc->sample_sizes[i] = get_be32(pb);
  872. dprintf(c->fc, "sample_sizes[]=%d\n", sc->sample_sizes[i]);
  873. }
  874. return 0;
  875. }
  876. static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  877. {
  878. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  879. MOVStreamContext *sc = st->priv_data;
  880. unsigned int i, entries;
  881. int64_t duration=0;
  882. int64_t total_sample_count=0;
  883. get_byte(pb); /* version */
  884. get_be24(pb); /* flags */
  885. entries = get_be32(pb);
  886. if(entries >= UINT_MAX / sizeof(MOV_stts_t))
  887. return -1;
  888. sc->stts_count = entries;
  889. sc->stts_data = av_malloc(entries * sizeof(MOV_stts_t));
  890. if (!sc->stts_data)
  891. return -1;
  892. dprintf(c->fc, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
  893. sc->time_rate=0;
  894. for(i=0; i<entries; i++) {
  895. int sample_duration;
  896. int sample_count;
  897. sample_count=get_be32(pb);
  898. sample_duration = get_be32(pb);
  899. sc->stts_data[i].count= sample_count;
  900. sc->stts_data[i].duration= sample_duration;
  901. sc->time_rate= ff_gcd(sc->time_rate, sample_duration);
  902. dprintf(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
  903. duration+=(int64_t)sample_duration*sample_count;
  904. total_sample_count+=sample_count;
  905. }
  906. st->nb_frames= total_sample_count;
  907. if(duration)
  908. st->duration= duration;
  909. return 0;
  910. }
  911. static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  912. {
  913. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  914. MOVStreamContext *sc = st->priv_data;
  915. unsigned int i, entries;
  916. get_byte(pb); /* version */
  917. get_be24(pb); /* flags */
  918. entries = get_be32(pb);
  919. if(entries >= UINT_MAX / sizeof(MOV_stts_t))
  920. return -1;
  921. sc->ctts_count = entries;
  922. sc->ctts_data = av_malloc(entries * sizeof(MOV_stts_t));
  923. if (!sc->ctts_data)
  924. return -1;
  925. dprintf(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
  926. for(i=0; i<entries; i++) {
  927. int count =get_be32(pb);
  928. int duration =get_be32(pb);
  929. if (duration < 0) {
  930. av_log(c->fc, AV_LOG_ERROR, "negative ctts, ignoring\n");
  931. sc->ctts_count = 0;
  932. url_fskip(pb, 8 * (entries - i - 1));
  933. break;
  934. }
  935. sc->ctts_data[i].count = count;
  936. sc->ctts_data[i].duration= duration;
  937. sc->time_rate= ff_gcd(sc->time_rate, duration);
  938. }
  939. return 0;
  940. }
  941. static void mov_build_index(MOVContext *mov, AVStream *st);
  942. static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  943. {
  944. AVStream *st;
  945. MOVStreamContext *sc;
  946. int ret;
  947. st = av_new_stream(c->fc, c->fc->nb_streams);
  948. if (!st) return -2;
  949. sc = av_mallocz(sizeof(MOVStreamContext));
  950. if (!sc) {
  951. av_free(st);
  952. return -1;
  953. }
  954. st->priv_data = sc;
  955. st->codec->codec_type = CODEC_TYPE_DATA;
  956. st->start_time = 0; /* XXX: check */
  957. if ((ret = mov_read_default(c, pb, atom)) < 0)
  958. return ret;
  959. /* sanity checks */
  960. if(!sc->stts_count || !sc->chunk_count || !sc->sample_to_chunk_sz ||
  961. (!sc->sample_size && !sc->sample_count)){
  962. av_log(c->fc, AV_LOG_ERROR, "missing mandatory atoms, broken header\n");
  963. sc->sample_count = 0; //ignore track
  964. return 0;
  965. }
  966. if(!sc->time_rate)
  967. sc->time_rate=1;
  968. if(!sc->time_scale)
  969. sc->time_scale= c->time_scale;
  970. av_set_pts_info(st, 64, sc->time_rate, sc->time_scale);
  971. if (st->codec->codec_type == CODEC_TYPE_AUDIO && sc->stts_count == 1)
  972. st->codec->frame_size = av_rescale(sc->time_rate, st->codec->sample_rate, sc->time_scale);
  973. if(st->duration != AV_NOPTS_VALUE){
  974. assert(st->duration % sc->time_rate == 0);
  975. st->duration /= sc->time_rate;
  976. }
  977. sc->ffindex = st->index;
  978. mov_build_index(c, st);
  979. if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {
  980. if (url_fopen(&sc->pb, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0)
  981. av_log(c->fc, AV_LOG_ERROR, "stream %d, error opening external essence: %s\n",
  982. st->index, strerror(errno));
  983. } else
  984. sc->pb = c->fc->pb;
  985. switch (st->codec->codec_id) {
  986. #ifdef CONFIG_H261_DECODER
  987. case CODEC_ID_H261:
  988. #endif
  989. #ifdef CONFIG_H263_DECODER
  990. case CODEC_ID_H263:
  991. #endif
  992. #ifdef CONFIG_MPEG4_DECODER
  993. case CODEC_ID_MPEG4:
  994. #endif
  995. st->codec->width= 0; /* let decoder init width/height */
  996. st->codec->height= 0;
  997. break;
  998. #ifdef CONFIG_LIBFAAD
  999. case CODEC_ID_AAC:
  1000. #endif
  1001. #ifdef CONFIG_VORBIS_DECODER
  1002. case CODEC_ID_VORBIS:
  1003. #endif
  1004. case CODEC_ID_MP3ON4:
  1005. st->codec->sample_rate= 0; /* let decoder init parameters properly */
  1006. break;
  1007. }
  1008. return 0;
  1009. }
  1010. static void mov_parse_udta_string(ByteIOContext *pb, char *str, int size)
  1011. {
  1012. uint16_t str_size = get_be16(pb); /* string length */;
  1013. get_be16(pb); /* skip language */
  1014. get_buffer(pb, str, FFMIN(size, str_size));
  1015. }
  1016. static int mov_read_udta(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1017. {
  1018. uint64_t end = url_ftell(pb) + atom.size;
  1019. while (url_ftell(pb) + 8 < end) {
  1020. uint32_t tag_size = get_be32(pb);
  1021. uint32_t tag = get_le32(pb);
  1022. uint64_t next = url_ftell(pb) + tag_size - 8;
  1023. if (next > end) // stop if tag_size is wrong
  1024. break;
  1025. switch (tag) {
  1026. case MKTAG(0xa9,'n','a','m'):
  1027. mov_parse_udta_string(pb, c->fc->title, sizeof(c->fc->title));
  1028. break;
  1029. case MKTAG(0xa9,'w','r','t'):
  1030. mov_parse_udta_string(pb, c->fc->author, sizeof(c->fc->author));
  1031. break;
  1032. case MKTAG(0xa9,'c','p','y'):
  1033. mov_parse_udta_string(pb, c->fc->copyright, sizeof(c->fc->copyright));
  1034. break;
  1035. case MKTAG(0xa9,'i','n','f'):
  1036. mov_parse_udta_string(pb, c->fc->comment, sizeof(c->fc->comment));
  1037. break;
  1038. default:
  1039. break;
  1040. }
  1041. url_fseek(pb, next, SEEK_SET);
  1042. }
  1043. return 0;
  1044. }
  1045. static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1046. {
  1047. AVStream *st = c->fc->streams[c->fc->nb_streams-1];
  1048. int version = get_byte(pb);
  1049. get_be24(pb); /* flags */
  1050. /*
  1051. MOV_TRACK_ENABLED 0x0001
  1052. MOV_TRACK_IN_MOVIE 0x0002
  1053. MOV_TRACK_IN_PREVIEW 0x0004
  1054. MOV_TRACK_IN_POSTER 0x0008
  1055. */
  1056. if (version == 1) {
  1057. get_be64(pb);
  1058. get_be64(pb);
  1059. } else {
  1060. get_be32(pb); /* creation time */
  1061. get_be32(pb); /* modification time */
  1062. }
  1063. st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
  1064. get_be32(pb); /* reserved */
  1065. st->start_time = 0; /* check */
  1066. (version == 1) ? get_be64(pb) : get_be32(pb); /* highlevel (considering edits) duration in movie timebase */
  1067. get_be32(pb); /* reserved */
  1068. get_be32(pb); /* reserved */
  1069. get_be16(pb); /* layer */
  1070. get_be16(pb); /* alternate group */
  1071. get_be16(pb); /* volume */
  1072. get_be16(pb); /* reserved */
  1073. url_fskip(pb, 36); /* display matrix */
  1074. /* those are fixed-point */
  1075. get_be32(pb); /* track width */
  1076. get_be32(pb); /* track height */
  1077. return 0;
  1078. }
  1079. /* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */
  1080. /* like the files created with Adobe Premiere 5.0, for samples see */
  1081. /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */
  1082. static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1083. {
  1084. int err;
  1085. if (atom.size < 8)
  1086. return 0; /* continue */
  1087. if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
  1088. url_fskip(pb, atom.size - 4);
  1089. return 0;
  1090. }
  1091. atom.type = get_le32(pb);
  1092. atom.offset += 8;
  1093. atom.size -= 8;
  1094. if (atom.type != MKTAG('m', 'd', 'a', 't')) {
  1095. url_fskip(pb, atom.size);
  1096. return 0;
  1097. }
  1098. err = mov_read_mdat(c, pb, atom);
  1099. return err;
  1100. }
  1101. static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1102. {
  1103. #ifdef CONFIG_ZLIB
  1104. ByteIOContext ctx;
  1105. uint8_t *cmov_data;
  1106. uint8_t *moov_data; /* uncompressed data */
  1107. long cmov_len, moov_len;
  1108. int ret;
  1109. get_be32(pb); /* dcom atom */
  1110. if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' ))
  1111. return -1;
  1112. if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) {
  1113. av_log(NULL, AV_LOG_ERROR, "unknown compression for cmov atom !");
  1114. return -1;
  1115. }
  1116. get_be32(pb); /* cmvd atom */
  1117. if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' ))
  1118. return -1;
  1119. moov_len = get_be32(pb); /* uncompressed size */
  1120. cmov_len = atom.size - 6 * 4;
  1121. cmov_data = av_malloc(cmov_len);
  1122. if (!cmov_data)
  1123. return -1;
  1124. moov_data = av_malloc(moov_len);
  1125. if (!moov_data) {
  1126. av_free(cmov_data);
  1127. return -1;
  1128. }
  1129. get_buffer(pb, cmov_data, cmov_len);
  1130. if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
  1131. return -1;
  1132. if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
  1133. return -1;
  1134. atom.type = MKTAG( 'm', 'o', 'o', 'v' );
  1135. atom.offset = 0;
  1136. atom.size = moov_len;
  1137. #ifdef DEBUG
  1138. // { int fd = open("/tmp/uncompheader.mov", O_WRONLY | O_CREAT); write(fd, moov_data, moov_len); close(fd); }
  1139. #endif
  1140. ret = mov_read_default(c, &ctx, atom);
  1141. av_free(moov_data);
  1142. av_free(cmov_data);
  1143. return ret;
  1144. #else
  1145. av_log(c->fc, AV_LOG_ERROR, "this file requires zlib support compiled in\n");
  1146. return -1;
  1147. #endif
  1148. }
  1149. /* edit list atom */
  1150. static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
  1151. {
  1152. MOVStreamContext *sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
  1153. int i, edit_count;
  1154. get_byte(pb); /* version */
  1155. get_be24(pb); /* flags */
  1156. edit_count= sc->edit_count = get_be32(pb); /* entries */
  1157. for(i=0; i<edit_count; i++){
  1158. int time;
  1159. get_be32(pb); /* Track duration */
  1160. time = get_be32(pb); /* Media time */
  1161. get_be32(pb); /* Media rate */
  1162. if (time != 0)
  1163. av_log(c->fc, AV_LOG_WARNING, "edit list not starting at 0, "
  1164. "a/v desync might occur, patch welcome\n");
  1165. }
  1166. dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, sc->edit_count);
  1167. return 0;
  1168. }
  1169. static const MOVParseTableEntry mov_default_parse_table[] = {
  1170. /* mp4 atoms */
  1171. { MKTAG( 'c', 'o', '6', '4' ), mov_read_stco },
  1172. { MKTAG( 'c', 't', 't', 's' ), mov_read_ctts }, /* composition time to sample */
  1173. { MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default },
  1174. { MKTAG( 'd', 'r', 'e', 'f' ), mov_read_dref },
  1175. { MKTAG( 'e', 'd', 't', 's' ), mov_read_default },
  1176. { MKTAG( 'e', 'l', 's', 't' ), mov_read_elst },
  1177. { MKTAG( 'e', 'n', 'd', 'a' ), mov_read_enda },
  1178. { MKTAG( 'f', 'i', 'e', 'l' ), mov_read_extradata },
  1179. { MKTAG( 'f', 't', 'y', 'p' ), mov_read_ftyp },
  1180. { MKTAG( 'g', 'l', 'b', 'l' ), mov_read_glbl },
  1181. { MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr },
  1182. { MKTAG( 'j', 'p', '2', 'h' ), mov_read_extradata },
  1183. { MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat },
  1184. { MKTAG( 'm', 'd', 'h', 'd' ), mov_read_mdhd },
  1185. { MKTAG( 'm', 'd', 'i', 'a' ), mov_read_default },
  1186. { MKTAG( 'm', 'i', 'n', 'f' ), mov_read_default },
  1187. { MKTAG( 'm', 'o', 'o', 'v' ), mov_read_moov },
  1188. { MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd },
  1189. { MKTAG( 'S', 'M', 'I', ' ' ), mov_read_smi }, /* Sorenson extension ??? */
  1190. { MKTAG( 'a', 'l', 'a', 'c' ), mov_read_extradata }, /* alac specific atom */
  1191. { MKTAG( 'a', 'v', 'c', 'C' ), mov_read_glbl },
  1192. { MKTAG( 's', 't', 'b', 'l' ), mov_read_default },
  1193. { MKTAG( 's', 't', 'c', 'o' ), mov_read_stco },
  1194. { MKTAG( 's', 't', 's', 'c' ), mov_read_stsc },
  1195. { MKTAG( 's', 't', 's', 'd' ), mov_read_stsd }, /* sample description */
  1196. { MKTAG( 's', 't', 's', 's' ), mov_read_stss }, /* sync sample */
  1197. { MKTAG( 's', 't', 's', 'z' ), mov_read_stsz }, /* sample size */
  1198. { MKTAG( 's', 't', 't', 's' ), mov_read_stts },
  1199. { MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */
  1200. { MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak },
  1201. { MKTAG( 'u', 'd', 't', 'a' ), mov_read_udta },
  1202. { MKTAG( 'w', 'a', 'v', 'e' ), mov_read_wave },
  1203. { MKTAG( 'e', 's', 'd', 's' ), mov_read_esds },
  1204. { MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */
  1205. { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov },
  1206. { 0, NULL }
  1207. };
  1208. /* XXX: is it sufficient ? */
  1209. static int mov_probe(AVProbeData *p)
  1210. {
  1211. unsigned int offset;
  1212. uint32_t tag;
  1213. int score = 0;
  1214. /* check file header */
  1215. offset = 0;
  1216. for(;;) {
  1217. /* ignore invalid offset */
  1218. if ((offset + 8) > (unsigned int)p->buf_size)
  1219. return score;
  1220. tag = AV_RL32(p->buf + offset + 4);
  1221. switch(tag) {
  1222. /* check for obvious tags */
  1223. case MKTAG( 'j', 'P', ' ', ' ' ): /* jpeg 2000 signature */
  1224. case MKTAG( 'm', 'o', 'o', 'v' ):
  1225. case MKTAG( 'm', 'd', 'a', 't' ):
  1226. case MKTAG( 'p', 'n', 'o', 't' ): /* detect movs with preview pics like ew.mov and april.mov */
  1227. case MKTAG( 'u', 'd', 't', 'a' ): /* Packet Video PVAuthor adds this and a lot of more junk */
  1228. return AVPROBE_SCORE_MAX;
  1229. /* those are more common words, so rate then a bit less */
  1230. case MKTAG( 'e', 'd', 'i', 'w' ): /* xdcam files have reverted first tags */
  1231. case MKTAG( 'w', 'i', 'd', 'e' ):
  1232. case MKTAG( 'f', 'r', 'e', 'e' ):
  1233. case MKTAG( 'j', 'u', 'n', 'k' ):
  1234. case MKTAG( 'p', 'i', 'c', 't' ):
  1235. return AVPROBE_SCORE_MAX - 5;
  1236. case MKTAG(0x82,0x82,0x7f,0x7d ):
  1237. case MKTAG( 'f', 't', 'y', 'p' ):
  1238. case MKTAG( 's', 'k', 'i', 'p' ):
  1239. case MKTAG( 'u', 'u', 'i', 'd' ):
  1240. offset = AV_RB32(p->buf+offset) + offset;
  1241. /* if we only find those cause probedata is too small at least rate them */
  1242. score = AVPROBE_SCORE_MAX - 50;
  1243. break;
  1244. default:
  1245. /* unrecognized tag */
  1246. return score;
  1247. }
  1248. }
  1249. return score;
  1250. }
  1251. static void mov_build_index(MOVContext *mov, AVStream *st)
  1252. {
  1253. MOVStreamContext *sc = st->priv_data;
  1254. offset_t current_offset;
  1255. int64_t current_dts = 0;
  1256. unsigned int stts_index = 0;
  1257. unsigned int stsc_index = 0;
  1258. unsigned int stss_index = 0;
  1259. unsigned int i, j;
  1260. if (sc->sample_sizes || st->codec->codec_type == CODEC_TYPE_VIDEO ||
  1261. sc->audio_cid == -2) {
  1262. unsigned int current_sample = 0;
  1263. unsigned int stts_sample = 0;
  1264. unsigned int keyframe, sample_size;
  1265. unsigned int distance = 0;
  1266. int key_off = sc->keyframes && sc->keyframes[0] == 1;
  1267. st->nb_frames = sc->sample_count;
  1268. for (i = 0; i < sc->chunk_count; i++) {
  1269. current_offset = sc->chunk_offsets[i];
  1270. if (stsc_index + 1 < sc->sample_to_chunk_sz &&
  1271. i + 1 == sc->sample_to_chunk[stsc_index + 1].first)
  1272. stsc_index++;
  1273. for (j = 0; j < sc->sample_to_chunk[stsc_index].count; j++) {
  1274. if (current_sample >= sc->sample_count) {
  1275. av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n");
  1276. goto out;
  1277. }
  1278. keyframe = !sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index];
  1279. if (keyframe) {
  1280. distance = 0;
  1281. if (stss_index + 1 < sc->keyframe_count)
  1282. stss_index++;
  1283. }
  1284. sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample];
  1285. dprintf(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
  1286. "size %d, distance %d, keyframe %d\n", st->index, current_sample,
  1287. current_offset, current_dts, sample_size, distance, keyframe);
  1288. if(sc->sample_to_chunk[stsc_index].id - 1 == sc->pseudo_stream_id)
  1289. av_add_index_entry(st, current_offset, current_dts, sample_size, distance,
  1290. keyframe ? AVINDEX_KEYFRAME : 0);
  1291. current_offset += sample_size;
  1292. assert(sc->stts_data[stts_index].duration % sc->time_rate == 0);
  1293. current_dts += sc->stts_data[stts_index].duration / sc->time_rate;
  1294. distance++;
  1295. stts_sample++;
  1296. current_sample++;
  1297. if (stts_index + 1 < sc->stts_count && stts_sample == sc->stts_data[stts_index].count) {
  1298. stts_sample = 0;
  1299. stts_index++;
  1300. }
  1301. }
  1302. }
  1303. } else { /* read whole chunk */
  1304. unsigned int chunk_samples, chunk_size, chunk_duration;
  1305. unsigned int frames = 1;
  1306. for (i = 0; i < sc->chunk_count; i++) {
  1307. current_offset = sc->chunk_offsets[i];
  1308. if (stsc_index + 1 < sc->sample_to_chunk_sz &&
  1309. i + 1 == sc->sample_to_chunk[stsc_index + 1].first)
  1310. stsc_index++;
  1311. chunk_samples = sc->sample_to_chunk[stsc_index].count;
  1312. /* get chunk size, beware of alaw/ulaw/mace */
  1313. if (sc->samples_per_frame > 0 &&
  1314. (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) {
  1315. if (sc->samples_per_frame < 1024)
  1316. chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
  1317. else {
  1318. chunk_size = sc->bytes_per_frame;
  1319. frames = chunk_samples / sc->samples_per_frame;
  1320. chunk_samples = sc->samples_per_frame;
  1321. }
  1322. } else if (sc->sample_size > 1 || st->codec->bits_per_sample == 8) {
  1323. chunk_size = chunk_samples * sc->sample_size;
  1324. } else {
  1325. av_log(mov->fc, AV_LOG_ERROR, "could not determine chunk size, report problem\n");
  1326. goto out;
  1327. }
  1328. for (j = 0; j < frames; j++) {
  1329. av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME);
  1330. /* get chunk duration */
  1331. chunk_duration = 0;
  1332. while (chunk_samples > 0) {
  1333. if (chunk_samples < sc->stts_data[stts_index].count) {
  1334. chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
  1335. sc->stts_data[stts_index].count -= chunk_samples;
  1336. break;
  1337. } else {
  1338. chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
  1339. chunk_samples -= sc->stts_data[stts_index].count;
  1340. if (stts_index + 1 < sc->stts_count)
  1341. stts_index++;
  1342. }
  1343. }
  1344. current_offset += sc->bytes_per_frame;
  1345. dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, "
  1346. "duration %d\n", st->index, i, current_offset, current_dts, chunk_size, chunk_duration);
  1347. assert(chunk_duration % sc->time_rate == 0);
  1348. current_dts += chunk_duration / sc->time_rate;
  1349. }
  1350. }
  1351. }
  1352. out:
  1353. /* adjust sample count to avindex entries */
  1354. sc->sample_count = st->nb_index_entries;
  1355. }
  1356. static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
  1357. {
  1358. MOVContext *mov = s->priv_data;
  1359. ByteIOContext *pb = s->pb;
  1360. int i, err;
  1361. MOV_atom_t atom = { 0, 0, 0 };
  1362. mov->fc = s;
  1363. if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
  1364. atom.size = url_fsize(pb);
  1365. else
  1366. atom.size = INT64_MAX;
  1367. /* check MOV header */
  1368. err = mov_read_default(mov, pb, atom);
  1369. if (err<0 || (!mov->found_moov && !mov->found_mdat)) {
  1370. av_log(s, AV_LOG_ERROR, "mov: header not found !!! (err:%d, moov:%d, mdat:%d) pos:%"PRId64"\n",
  1371. err, mov->found_moov, mov->found_mdat, url_ftell(pb));
  1372. return -1;
  1373. }
  1374. dprintf(mov->fc, "on_parse_exit_offset=%d\n", (int) url_ftell(pb));
  1375. for(i=0; i<s->nb_streams; i++) {
  1376. MOVStreamContext *sc = s->streams[i]->priv_data;
  1377. /* Do not need those anymore. */
  1378. av_freep(&sc->chunk_offsets);
  1379. av_freep(&sc->sample_to_chunk);
  1380. av_freep(&sc->sample_sizes);
  1381. av_freep(&sc->keyframes);
  1382. av_freep(&sc->stts_data);
  1383. }
  1384. return 0;
  1385. }
  1386. static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
  1387. {
  1388. MOVContext *mov = s->priv_data;
  1389. MOVStreamContext *sc = 0;
  1390. AVIndexEntry *sample = 0;
  1391. int64_t best_dts = INT64_MAX;
  1392. int i;
  1393. for (i = 0; i < s->nb_streams; i++) {
  1394. AVStream *st = s->streams[i];
  1395. MOVStreamContext *msc = st->priv_data;
  1396. if (st->discard != AVDISCARD_ALL && msc->pb && msc->current_sample < msc->sample_count) {
  1397. AVIndexEntry *current_sample = &st->index_entries[msc->current_sample];
  1398. int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate,
  1399. AV_TIME_BASE, msc->time_scale);
  1400. dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
  1401. if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) ||
  1402. (!url_is_streamed(s->pb) &&
  1403. ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb &&
  1404. ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
  1405. (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) {
  1406. sample = current_sample;
  1407. best_dts = dts;
  1408. sc = msc;
  1409. }
  1410. }
  1411. }
  1412. if (!sample)
  1413. return -1;
  1414. /* must be done just before reading, to avoid infinite loop on sample */
  1415. sc->current_sample++;
  1416. if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
  1417. av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n",
  1418. sc->ffindex, sample->pos);
  1419. return -1;
  1420. }
  1421. av_get_packet(sc->pb, pkt, sample->size);
  1422. #ifdef CONFIG_DV_DEMUXER
  1423. if (mov->dv_demux && sc->dv_audio_container) {
  1424. dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size);
  1425. av_free(pkt->data);
  1426. pkt->size = 0;
  1427. if (dv_get_packet(mov->dv_demux, pkt) < 0)
  1428. return -1;
  1429. }
  1430. #endif
  1431. pkt->stream_index = sc->ffindex;
  1432. pkt->dts = sample->timestamp;
  1433. if (sc->ctts_data) {
  1434. assert(sc->ctts_data[sc->sample_to_ctime_index].duration % sc->time_rate == 0);
  1435. pkt->pts = pkt->dts + sc->ctts_data[sc->sample_to_ctime_index].duration / sc->time_rate;
  1436. /* update ctts context */
  1437. sc->sample_to_ctime_sample++;
  1438. if (sc->sample_to_ctime_index < sc->ctts_count &&
  1439. sc->ctts_data[sc->sample_to_ctime_index].count == sc->sample_to_ctime_sample) {
  1440. sc->sample_to_ctime_index++;
  1441. sc->sample_to_ctime_sample = 0;
  1442. }
  1443. } else {
  1444. pkt->pts = pkt->dts;
  1445. }
  1446. pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0;
  1447. pkt->pos = sample->pos;
  1448. dprintf(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n",
  1449. pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration);
  1450. return 0;
  1451. }
  1452. static int mov_seek_stream(AVStream *st, int64_t timestamp, int flags)
  1453. {
  1454. MOVStreamContext *sc = st->priv_data;
  1455. int sample, time_sample;
  1456. int i;
  1457. sample = av_index_search_timestamp(st, timestamp, flags);
  1458. dprintf(st->codec, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample);
  1459. if (sample < 0) /* not sure what to do */
  1460. return -1;
  1461. sc->current_sample = sample;
  1462. dprintf(st->codec, "stream %d, found sample %d\n", st->index, sc->current_sample);
  1463. /* adjust ctts index */
  1464. if (sc->ctts_data) {
  1465. time_sample = 0;
  1466. for (i = 0; i < sc->ctts_count; i++) {
  1467. int next = time_sample + sc->ctts_data[i].count;
  1468. if (next > sc->current_sample) {
  1469. sc->sample_to_ctime_index = i;
  1470. sc->sample_to_ctime_sample = sc->current_sample - time_sample;
  1471. break;
  1472. }
  1473. time_sample = next;
  1474. }
  1475. }
  1476. return sample;
  1477. }
  1478. static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
  1479. {
  1480. AVStream *st;
  1481. int64_t seek_timestamp, timestamp;
  1482. int sample;
  1483. int i;
  1484. if (stream_index >= s->nb_streams)
  1485. return -1;
  1486. st = s->streams[stream_index];
  1487. sample = mov_seek_stream(st, sample_time, flags);
  1488. if (sample < 0)
  1489. return -1;
  1490. /* adjust seek timestamp to found sample timestamp */
  1491. seek_timestamp = st->index_entries[sample].timestamp;
  1492. for (i = 0; i < s->nb_streams; i++) {
  1493. st = s->streams[i];
  1494. if (stream_index == i || st->discard == AVDISCARD_ALL)
  1495. continue;
  1496. timestamp = av_rescale_q(seek_timestamp, s->streams[stream_index]->time_base, st->time_base);
  1497. mov_seek_stream(st, timestamp, flags);
  1498. }
  1499. return 0;
  1500. }
  1501. static int mov_read_close(AVFormatContext *s)
  1502. {
  1503. int i, j;
  1504. MOVContext *mov = s->priv_data;
  1505. for(i=0; i<s->nb_streams; i++) {
  1506. MOVStreamContext *sc = s->streams[i]->priv_data;
  1507. av_freep(&sc->ctts_data);
  1508. for (j=0; j<sc->drefs_count; j++)
  1509. av_freep(&sc->drefs[j].path);
  1510. av_freep(&sc->drefs);
  1511. if (sc->pb && sc->pb != s->pb)
  1512. url_fclose(sc->pb);
  1513. }
  1514. if(mov->dv_demux){
  1515. for(i=0; i<mov->dv_fctx->nb_streams; i++){
  1516. av_freep(&mov->dv_fctx->streams[i]->codec);
  1517. av_freep(&mov->dv_fctx->streams[i]);
  1518. }
  1519. av_freep(&mov->dv_fctx);
  1520. av_freep(&mov->dv_demux);
  1521. }
  1522. return 0;
  1523. }
  1524. AVInputFormat mov_demuxer = {
  1525. "mov,mp4,m4a,3gp,3g2,mj2",
  1526. "QuickTime/MPEG4/Motion JPEG 2000 format",
  1527. sizeof(MOVContext),
  1528. mov_probe,
  1529. mov_read_header,
  1530. mov_read_packet,
  1531. mov_read_close,
  1532. mov_read_seek,
  1533. };