]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mov.c
Attempt to better document AVFMT_NOFILE.
[ffmpeg] / libavformat / mov.c
index 3a856e368be67aac4b4cf6474051e63578849b44..1658b6d2442f2e9933dabf1c293868cdfbbf1ed5 100644 (file)
@@ -102,6 +102,7 @@ static const CodecTag mov_video_tags[] = {
     { CODEC_ID_8BPS, MKTAG('8', 'B', 'P', 'S') }, /* Planar RGB (8BPS) */
     { CODEC_ID_SMC, MKTAG('s', 'm', 'c', ' ') }, /* Apple Graphics (SMC) */
     { CODEC_ID_QTRLE, MKTAG('r', 'l', 'e', ' ') }, /* Apple Animation (RLE) */
+    { CODEC_ID_MSRLE, MKTAG('W', 'R', 'L', 'E') },
     { CODEC_ID_QDRAW, MKTAG('q', 'd', 'r', 'w') }, /* QuickDraw */
     { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, /* AVC-1/H.264 */
     { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') }, /* MPEG2 produced by Sony HD camera */
@@ -120,6 +121,9 @@ static const CodecTag mov_video_tags[] = {
     { CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') }, /* Truevision Targa */
     { CODEC_ID_TIFF, MKTAG('t', 'i', 'f', 'f') }, /* TIFF embedded in MOV */
     { CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') }, /* UNCOMPRESSED 8BIT 4:2:2 */
+    { CODEC_ID_VC1,  MKTAG('v', 'c', '-', '1') }, /* SMPTE RP 2025 */
+    { CODEC_ID_WMV3, MKTAG('v', 'c', '-', '1') }, /* SMPTE RP 2025 */
+    { CODEC_ID_PNG,  MKTAG('p', 'n', 'g', ' ') },
     { CODEC_ID_NONE, 0 },
 };
 
@@ -262,7 +266,6 @@ typedef struct MOVStreamContext {
 } MOVStreamContext;
 
 typedef struct MOVContext {
-    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) */
     AVFormatContext *fc;
     int time_scale;
     int64_t duration; /* duration of the longest track */
@@ -286,6 +289,7 @@ typedef struct MOVContext {
     int mdat_count;
     DVDemuxContext *dv_demux;
     AVFormatContext *dv_fctx;
+    int isom; /* 1 if file is ISO Media (mp4/3gp) */
 } MOVContext;
 
 
@@ -394,7 +398,6 @@ static int mov_read_ctab(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 {
     AVStream *st = c->fc->streams[c->fc->nb_streams-1];
-    int len = 0;
     uint32_t type;
     uint32_t ctype;
 
@@ -407,31 +410,24 @@ static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 
     dprintf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype);
     dprintf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
-    if(ctype == MKTAG('m', 'h', 'l', 'r')) /* MOV */
-        c->mp4 = 0;
-    else if(ctype == 0)
-        c->mp4 = 1;
+    if(!ctype)
+        c->isom = 1;
     if(type == MKTAG('v', 'i', 'd', 'e'))
         st->codec->codec_type = CODEC_TYPE_VIDEO;
     else if(type == MKTAG('s', 'o', 'u', 'n'))
         st->codec->codec_type = CODEC_TYPE_AUDIO;
+    else if(type == MKTAG('m', '1', 'a', ' '))
+        st->codec->codec_id = CODEC_ID_MP2;
+    else if(type == MKTAG('s', 'u', 'b', 'p')) {
+        st->codec->codec_type = CODEC_TYPE_SUBTITLE;
+        st->codec->codec_id = CODEC_ID_DVD_SUBTITLE;
+    }
     get_be32(pb); /* component  manufacture */
     get_be32(pb); /* component flags */
     get_be32(pb); /* component flags mask */
 
     if(atom.size <= 24)
         return 0; /* nothing left to read */
-    /* XXX: MP4 uses a C string, not a pascal one */
-    /* component name */
-
-    if(c->mp4) {
-        /* .mp4: C string */
-        while(get_byte(pb) && (++len < (atom.size - 24)));
-    } else {
-        /* .mov: PASCAL string */
-        len = get_byte(pb);
-        url_fskip(pb, len);
-    }
 
     url_fskip(pb, atom.size - (url_ftell(pb) - atom.offset));
     return 0;
@@ -523,26 +519,9 @@ static int mov_read_ftyp(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 {
     uint32_t type = get_le32(pb);
 
-    /* from mplayer */
-    switch (type) {
-    case MKTAG('i', 's', 'o', 'm'):
-    case MKTAG('m', 'p', '4', '1'):
-    case MKTAG('m', 'p', '4', '2'):
-    case MKTAG('3', 'g', 'p', '1'):
-    case MKTAG('3', 'g', 'p', '2'):
-    case MKTAG('3', 'g', '2', 'a'):
-    case MKTAG('3', 'g', 'p', '3'):
-    case MKTAG('3', 'g', 'p', '4'):
-    case MKTAG('3', 'g', 'p', '5'):
-    case MKTAG('m', 'm', 'p', '4'): /* Mobile MP4 */
-    case MKTAG('M', '4', 'A', ' '): /* Apple iTunes AAC-LC Audio */
-    case MKTAG('M', '4', 'P', ' '): /* Apple iTunes AAC-LC Protected Audio */
-    case MKTAG('m', 'j', 'p', '2'): /* Motion Jpeg 2000 */
-        c->mp4 = 1;
-    case MKTAG('q', 't', ' ', ' '):
-    default:
-        av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
-    }
+    if (type != MKTAG('q','t',' ',' '))
+        c->isom = 1;
+    av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
     get_be32(pb); /* minor version */
     url_fskip(pb, atom.size - 8);
     return 0;
@@ -834,9 +813,10 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 
         st->codec->codec_tag = format;
         id = codec_get_id(mov_audio_tags, format);
-        if (id > 0) {
+        if (st->codec->codec_type != CODEC_TYPE_VIDEO && id > 0) {
             st->codec->codec_type = CODEC_TYPE_AUDIO;
-        } else if (format && format != MKTAG('m', 'p', '4', 's')) { /* skip old asf mpeg4 tag */
+        } else if (st->codec->codec_type != CODEC_TYPE_AUDIO && /* do not overwrite codec type */
+                   format && format != MKTAG('m', 'p', '4', 's')) { /* skip old asf mpeg4 tag */
             id = codec_get_id(mov_video_tags, format);
             if (id <= 0)
                 id = codec_get_id(codec_bmp_tags, format);
@@ -982,21 +962,23 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
             }
 
             //Read QT version 1 fields. In version 0 theese dont exist
-            dprintf("version =%d mp4=%d\n",version,c->mp4);
-            if(version==1) {
-                sc->sample_size_v1.den = get_be32(pb); /* samples per packet */
-                get_be32(pb); /* bytes per packet */
-                sc->sample_size_v1.num = get_be32(pb); /* bytes per frame */
-                get_be32(pb); /* bytes per sample */
-            } else if(version==2) {
-                get_be32(pb); /* sizeof struct only */
-                st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */
-                st->codec->channels = get_be32(pb);
-                get_be32(pb); /* always 0x7F000000 */
-                get_be32(pb); /* bits per channel if sound is uncompressed */
-                get_be32(pb); /* lcpm format specific flag */
-                get_be32(pb); /* bytes per audio packet if constant */
-                get_be32(pb); /* lpcm frames per audio packet if constant */
+            dprintf("version =%d, isom =%d\n",version,c->isom);
+            if(!c->isom) {
+                if(version==1) {
+                    sc->sample_size_v1.den = get_be32(pb); /* samples per packet */
+                    get_be32(pb); /* bytes per packet */
+                    sc->sample_size_v1.num = get_be32(pb); /* bytes per frame */
+                    get_be32(pb); /* bytes per sample */
+                } else if(version==2) {
+                    get_be32(pb); /* sizeof struct only */
+                    st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */
+                    st->codec->channels = get_be32(pb);
+                    get_be32(pb); /* always 0x7F000000 */
+                    get_be32(pb); /* bits per channel if sound is uncompressed */
+                    get_be32(pb); /* lcpm format specific flag */
+                    get_be32(pb); /* bytes per audio packet if constant */
+                    get_be32(pb); /* lpcm frames per audio packet if constant */
+                }
             }
 
             bits_per_sample = av_get_bits_per_sample(st->codec->codec_id);
@@ -1034,7 +1016,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
         st->codec->width= 0; /* let decoder init width/height */
         st->codec->height= 0;
         break;
-#ifdef CONFIG_FAAD
+#ifdef CONFIG_LIBFAAD
     case CODEC_ID_AAC:
 #endif
 #ifdef CONFIG_VORBIS_DECODER
@@ -1065,6 +1047,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
         st->codec->channels= 1; /* really needed */
         break;
     case CODEC_ID_MP2:
+        st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */
         st->need_parsing = 1;
         break;
     default:
@@ -1464,7 +1447,7 @@ static int mov_probe(AVProbeData *p)
         /* ignore invalid offset */
         if ((offset + 8) > (unsigned int)p->buf_size)
             return score;
-        tag = LE_32(p->buf + offset + 4);
+        tag = AV_RL32(p->buf + offset + 4);
         switch(tag) {
         /* check for obvious tags */
         case MKTAG( 'j', 'P', ' ', ' ' ): /* jpeg 2000 signature */
@@ -1482,7 +1465,7 @@ static int mov_probe(AVProbeData *p)
         case MKTAG( 'f', 't', 'y', 'p' ):
         case MKTAG( 's', 'k', 'i', 'p' ):
         case MKTAG( 'u', 'u', 'i', 'd' ):
-            offset = BE_32(p->buf+offset) + offset;
+            offset = AV_RB32(p->buf+offset) + offset;
             /* if we only find those cause probedata is too small at least rate them */
             score = AVPROBE_SCORE_MAX - 50;
             break;
@@ -1523,7 +1506,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
                         stss_index++;
                 }
                 sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample];
-                dprintf("AVIndex stream %d, sample %d, offset %llx, dts %lld, size %d, distance %d, keyframe %d\n",
+                dprintf("AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", size %d, distance %d, keyframe %d\n",
                         st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe);
                 av_add_index_entry(st, current_offset, current_dts, sample_size, distance, keyframe ? AVINDEX_KEYFRAME : 0);
                 current_offset += sample_size;
@@ -1568,7 +1551,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
                 /* check for last chunk */
                 if (chunk_size == INT_MAX)
                     for (j = 0; j < mov->mdat_count; j++) {
-                        dprintf("mdat %d, offset %llx, size %lld, current offset %llx\n",
+                        dprintf("mdat %d, offset %"PRIx64", size %"PRId64", current offset %"PRIx64"\n",
                                 j, mov->mdat_list[j].offset, mov->mdat_list[j].size, current_offset);
                         if (mov->mdat_list[j].offset <= current_offset && mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset)
                             chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset;
@@ -1594,7 +1577,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
                     }
                 }
             }
-            dprintf("AVIndex stream %d, chunk %d, offset %llx, dts %lld, size %d, duration %d\n",
+            dprintf("AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, duration %d\n",
                     st->index, i, current_offset, current_dts, chunk_size, chunk_duration);
             assert(chunk_duration % sc->time_rate == 0);
             current_dts += chunk_duration / sc->time_rate;
@@ -1678,7 +1661,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
             AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample];
             int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale);
 
-            dprintf("stream %d, sample %ld, dts %lld\n", i, msc->current_sample, dts);
+            dprintf("stream %d, sample %ld, dts %"PRId64"\n", i, msc->current_sample, dts);
             if (dts < best_dts) {
                 sample = current_sample;
                 best_dts = dts;
@@ -1726,7 +1709,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
     }
     pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0;
     pkt->pos = sample->pos;
-    dprintf("stream %d, pts %lld, dts %lld, pos 0x%llx, duration %d\n", pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration);
+    dprintf("stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n", pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration);
     return 0;
 }
 
@@ -1737,7 +1720,7 @@ static int mov_seek_stream(AVStream *st, int64_t timestamp, int flags)
     int i;
 
     sample = av_index_search_timestamp(st, timestamp, flags);
-    dprintf("stream %d, timestamp %lld, sample %d\n", st->index, timestamp, sample);
+    dprintf("stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample);
     if (sample < 0) /* not sure what to do */
         return -1;
     sc->current_sample = sample;