]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/movenc.c
Change sign in ff_celp_lp_synthesis_filterf(). This makes this function
[ffmpeg] / libavformat / movenc.c
index bb900e3e520ffe5bb0cb43dfca9380ab59ba5a7b..95b881aec2eb8859e74f871d8d8913ad8c8a9b8a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * MOV, 3GP, MP4 muxer
- * Copyright (c) 2003 Thomas Raivio.
- * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>.
+ * Copyright (c) 2003 Thomas Raivio
+ * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>
  *
  * This file is part of FFmpeg.
  *
@@ -69,6 +69,7 @@ typedef struct MOVIndex {
     uint8_t     *vosData;
     MOVIentry   *cluster;
     int         audio_vbr;
+    int         height; ///< active picture (w/o VBI) height for D-10/IMX
 } MOVTrack;
 
 typedef struct MOVContext {
@@ -550,7 +551,7 @@ static const AVCodecTag codec_3gp_tags[] = {
     { CODEC_ID_AAC,    MKTAG('m','p','4','a') },
     { CODEC_ID_AMR_NB, MKTAG('s','a','m','r') },
     { CODEC_ID_AMR_WB, MKTAG('s','a','w','b') },
-    { CODEC_ID_MOV_TEXT, MKTAG('t', 'x', '3', 'g') },
+    { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
     { CODEC_ID_NONE, 0 },
 };
 
@@ -568,7 +569,7 @@ static const AVCodecTag codec_ipod_tags[] = {
     { CODEC_ID_AAC,    MKTAG('m','p','4','a') },
     { CODEC_ID_ALAC,   MKTAG('a','l','a','c') },
     { CODEC_ID_AC3,    MKTAG('a','c','-','3') },
-    { CODEC_ID_MOV_TEXT, MKTAG('t', 'x', '3', 'g') },
+    { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
     { CODEC_ID_NONE, 0 },
 };
 
@@ -691,7 +692,7 @@ static int mov_write_video_tag(ByteIOContext *pb, MOVTrack *track)
         put_be32(pb, 0); /* Reserved */
     }
     put_be16(pb, track->enc->width); /* Video width */
-    put_be16(pb, track->enc->height); /* Video height */
+    put_be16(pb, track->height); /* Video height */
     put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
     put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
     put_be32(pb, 0); /* Data size (= 0) */
@@ -905,7 +906,7 @@ static int mov_write_vmhd_tag(ByteIOContext *pb)
 
 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track)
 {
-    const char *descr, *hdlr, *hdlr_type;
+    const char *hdlr, *descr = NULL, *hdlr_type = NULL;
     int64_t pos = url_ftell(pb);
 
     if (!track) { /* no media --> data handler */
@@ -917,10 +918,10 @@ static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track)
         if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
             hdlr_type = "vide";
             descr = "VideoHandler";
-        } else if (track->enc->codec_type == CODEC_TYPE_AUDIO){
+        } else if (track->enc->codec_type == CODEC_TYPE_AUDIO) {
             hdlr_type = "soun";
             descr = "SoundHandler";
-        } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE){
+        } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
             if (track->mode == MODE_IPOD) hdlr_type = "sbtl";
             else                          hdlr_type = "text";
             descr = "SubtitleHandler";
@@ -950,10 +951,8 @@ static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack *track)
     else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
         mov_write_smhd_tag(pb);
     else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
-        if (track->mode == MODE_MOV)
-            mov_write_gmhd_tag(pb);
-        else
-            mov_write_nmhd_tag(pb);
+        if (track->mode == MODE_MOV) mov_write_gmhd_tag(pb);
+        else                         mov_write_nmhd_tag(pb);
     }
     if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
         mov_write_hdlr_tag(pb, NULL);
@@ -1048,9 +1047,10 @@ static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st)
     if(track->enc->codec_type == CODEC_TYPE_VIDEO ||
        track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
         double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio);
-        if(!sample_aspect_ratio) sample_aspect_ratio = 1;
+        if(!sample_aspect_ratio || track->height != track->enc->height)
+            sample_aspect_ratio = 1;
         put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
-        put_be32(pb, track->enc->height*0x10000);
+        put_be32(pb, track->height*0x10000);
     }
     else {
         put_be32(pb, 0);
@@ -1656,6 +1656,16 @@ static int mov_write_header(AVFormatContext *s)
             return -1;
         }
         if(st->codec->codec_type == CODEC_TYPE_VIDEO){
+            if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') ||
+                track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') ||
+                track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) {
+                if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) {
+                    av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n");
+                    return -1;
+                }
+                track->height = track->tag>>24 == 'n' ? 486 : 576;
+            } else
+                track->height = st->codec->height;
             track->timescale = st->codec->time_base.den;
             av_set_pts_info(st, 64, 1, st->codec->time_base.den);
             if (track->mode == MODE_MOV && track->timescale > 100000)
@@ -1737,12 +1747,12 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
         /* from x264 or from bytestream h264 */
         /* nal reformating needed */
-        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
-        if (ret < 0)
-            return ret;
-        assert(pkt->size);
-        size = pkt->size;
-    } else if ((enc->codec_id == CODEC_ID_DNXHD ||
+        size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+    } else {
+        put_buffer(pb, pkt->data, size);
+    }
+
+    if ((enc->codec_id == CODEC_ID_DNXHD ||
                 enc->codec_id == CODEC_ID_AC3) && !trk->vosLen) {
         /* copy frame to create needed atoms */
         trk->vosLen = size;
@@ -1758,7 +1768,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
             return -1;
     }
 
-    trk->cluster[trk->entry].pos = url_ftell(pb);
+    trk->cluster[trk->entry].pos = url_ftell(pb) - size;
     trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
     trk->cluster[trk->entry].size = size;
     trk->cluster[trk->entry].entries = samplesInChunk;
@@ -1779,8 +1789,6 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     trk->sampleCount += samplesInChunk;
     mov->mdat_size += size;
 
-    put_buffer(pb, pkt->data, size);
-
     put_flush_packet(pb);
     return 0;
 }
@@ -1821,7 +1829,7 @@ static int mov_write_trailer(AVFormatContext *s)
     return res;
 }
 
-#ifdef CONFIG_MOV_MUXER
+#if CONFIG_MOV_MUXER
 AVOutputFormat mov_muxer = {
     "mov",
     NULL_IF_CONFIG_SMALL("MOV format"),
@@ -1837,7 +1845,7 @@ AVOutputFormat mov_muxer = {
     .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0},
 };
 #endif
-#ifdef CONFIG_TGP_MUXER
+#if CONFIG_TGP_MUXER
 AVOutputFormat tgp_muxer = {
     "3gp",
     NULL_IF_CONFIG_SMALL("3GP format"),
@@ -1853,7 +1861,7 @@ AVOutputFormat tgp_muxer = {
     .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
 };
 #endif
-#ifdef CONFIG_MP4_MUXER
+#if CONFIG_MP4_MUXER
 AVOutputFormat mp4_muxer = {
     "mp4",
     NULL_IF_CONFIG_SMALL("MP4 format"),
@@ -1869,7 +1877,7 @@ AVOutputFormat mp4_muxer = {
     .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
 };
 #endif
-#ifdef CONFIG_PSP_MUXER
+#if CONFIG_PSP_MUXER
 AVOutputFormat psp_muxer = {
     "psp",
     NULL_IF_CONFIG_SMALL("PSP MP4 format"),
@@ -1885,7 +1893,7 @@ AVOutputFormat psp_muxer = {
     .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
 };
 #endif
-#ifdef CONFIG_TG2_MUXER
+#if CONFIG_TG2_MUXER
 AVOutputFormat tg2_muxer = {
     "3g2",
     NULL_IF_CONFIG_SMALL("3GP2 format"),
@@ -1901,7 +1909,7 @@ AVOutputFormat tg2_muxer = {
     .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
 };
 #endif
-#ifdef CONFIG_IPOD_MUXER
+#if CONFIG_IPOD_MUXER
 AVOutputFormat ipod_muxer = {
     "ipod",
     NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),