]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/flvdec.c
Fix AMR block length for no data mode when muxing mov.
[ffmpeg] / libavformat / flvdec.c
index ef487a694f6ca0ac2f940451d87b2c03f7e0dfd7..7efe15666612c2f136818e5526208c7b0c9253b5 100644 (file)
@@ -139,6 +139,18 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
     int64_t *filepositions = NULL;
     int ret = AVERROR(ENOSYS);
     int64_t initial_pos = avio_tell(ioc);
+    AVDictionaryEntry *creator = av_dict_get(s->metadata, "metadatacreator",
+                                             NULL, 0);
+
+    if (creator && !strcmp(creator->value, "MEGA")) {
+        /* Files with this metadatacreator tag seem to have filepositions
+         * pointing at the 4 trailer bytes of the previous packet,
+         * which isn't the norm (nor what we expect here, nor what
+         * jwplayer + lighttpd expect, nor what flvtool2 produces).
+         * Just ignore the index in this case, instead of risking trying
+         * to adjust it to something that might or might not work. */
+        return 0;
+    }
 
     while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
         int64_t** current_array;
@@ -264,17 +276,35 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
         acodec = astream ? astream->codec : NULL;
         vcodec = vstream ? vstream->codec : NULL;
 
+        if (amf_type == AMF_DATA_TYPE_NUMBER) {
+            if (!strcmp(key, "duration"))
+                s->duration = num_val * AV_TIME_BASE;
+            else if (!strcmp(key, "videodatarate") && vcodec && 0 <= (int)(num_val * 1024.0))
+                vcodec->bit_rate = num_val * 1024.0;
+            else if (!strcmp(key, "audiodatarate") && acodec && 0 <= (int)(num_val * 1024.0))
+                acodec->bit_rate = num_val * 1024.0;
+        }
+
+        if (!strcmp(key, "duration")        ||
+            !strcmp(key, "filesize")        ||
+            !strcmp(key, "width")           ||
+            !strcmp(key, "height")          ||
+            !strcmp(key, "videodatarate")   ||
+            !strcmp(key, "framerate")       ||
+            !strcmp(key, "videocodecid")    ||
+            !strcmp(key, "audiodatarate")   ||
+            !strcmp(key, "audiosamplerate") ||
+            !strcmp(key, "audiosamplesize") ||
+            !strcmp(key, "stereo")          ||
+            !strcmp(key, "audiocodecid"))
+            return 0;
+
         if(amf_type == AMF_DATA_TYPE_BOOL) {
             av_strlcpy(str_val, num_val > 0 ? "true" : "false", sizeof(str_val));
             av_dict_set(&s->metadata, key, str_val, 0);
         } else if(amf_type == AMF_DATA_TYPE_NUMBER) {
             snprintf(str_val, sizeof(str_val), "%.f", num_val);
             av_dict_set(&s->metadata, key, str_val, 0);
-            if(!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE;
-            else if(!strcmp(key, "videodatarate") && vcodec && 0 <= (int)(num_val * 1024.0))
-                vcodec->bit_rate = num_val * 1024.0;
-            else if(!strcmp(key, "audiodatarate") && acodec && 0 <= (int)(num_val * 1024.0))
-                acodec->bit_rate = num_val * 1024.0;
         } else if(amf_type == AMF_DATA_TYPE_OBJECT){
             if(s->nb_streams==1 && ((!acodec && !strcmp(key, "audiocodecid")) || (!vcodec && !strcmp(key, "videocodecid")))){
                 s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
@@ -505,7 +535,8 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
             if (flv->wrong_dts)
                 dts = AV_NOPTS_VALUE;
         }
-        if (type == 0) {
+
+        if (type == 0 && !st->codec->extradata) {
             if ((ret = flv_get_extradata(s, st, size)) < 0)
                 return ret;
             if (st->codec->codec_id == CODEC_ID_AAC) {