[2/2] flvenc: Don't copy metadata entries that are written by the muxer itself

Message ID 1316614480-10136-2-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö Sept. 21, 2011, 2:14 p.m.
This avoids duplicate, stale metadata entries if transcoding
from one flv file to another.
---
 libavformat/flvenc.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

Comments

Martin Storsjö Oct. 12, 2011, noon | #1
On Wed, 21 Sep 2011, Martin Storsjö wrote:

> This avoids duplicate, stale metadata entries if transcoding
> from one flv file to another.
> ---
> libavformat/flvenc.c |   20 ++++++++++++++++++++
> 1 files changed, 20 insertions(+), 0 deletions(-)
>

This change isn't needed any longer, now that the corresponding change has 
been done for the demuxer instead.

// Martin

Patch

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 23d19cd..d9f692f 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -181,6 +181,7 @@  static int flv_write_header(AVFormatContext *s)
     double framerate = 0.0;
     int64_t metadata_size_pos, data_size, metadata_count_pos;
     AVDictionaryEntry *tag = NULL;
+    AVDictionary *entries = NULL;
 
     for(i=0; i<s->nb_streams; i++){
         AVCodecContext *enc = s->streams[i]->codec;
@@ -241,6 +242,9 @@  static int flv_write_header(AVFormatContext *s)
     metadata_count = 5*!!video_enc + 5*!!audio_enc + 2; // +2 for duration and file size
     avio_wb32(pb, metadata_count);
 
+    av_dict_set(&entries, "duration", "", 0);
+    av_dict_set(&entries, "filesize", "", 0);
+
     put_amf_string(pb, "duration");
     flv->duration_offset= avio_tell(pb);
     put_amf_double(pb, s->duration / AV_TIME_BASE); // fill in the guessed duration, it'll be corrected later if incorrect
@@ -260,6 +264,12 @@  static int flv_write_header(AVFormatContext *s)
 
         put_amf_string(pb, "videocodecid");
         put_amf_double(pb, video_enc->codec_tag);
+
+        av_dict_set(&entries, "width", "", 0);
+        av_dict_set(&entries, "height", "", 0);
+        av_dict_set(&entries, "videodatarate", "", 0);
+        av_dict_set(&entries, "framerate", "", 0);
+        av_dict_set(&entries, "videocodecid", "", 0);
     }
 
     if(audio_enc){
@@ -277,14 +287,24 @@  static int flv_write_header(AVFormatContext *s)
 
         put_amf_string(pb, "audiocodecid");
         put_amf_double(pb, audio_enc->codec_tag);
+
+        av_dict_set(&entries, "audiodatarate", "", 0);
+        av_dict_set(&entries, "audiosamplerate", "", 0);
+        av_dict_set(&entries, "audiosamplesize", "", 0);
+        av_dict_set(&entries, "stereo", "", 0);
+        av_dict_set(&entries, "audiocodecid", "", 0);
     }
 
     while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
+        AVDictionaryEntry* entry = av_dict_get(entries, tag->key, NULL, 0);
+        if (entry)
+            continue; // Don't duplicate entries that we already write ourselves
         put_amf_string(pb, tag->key);
         avio_w8(pb, AMF_DATA_TYPE_STRING);
         put_amf_string(pb, tag->value);
         metadata_count++;
     }
+    av_dict_free(&entries);
 
     put_amf_string(pb, "filesize");
     flv->filesize_offset= avio_tell(pb);