From 431d83df2592ee8c550a80cdc77e8613cb12ad08 Mon Sep 17 00:00:00 2001
From: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Date: Wed, 24 Oct 2007 14:20:15 +0000
Subject: [PATCH] Prevent mov muxer from writing empty udta atoms.

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@10852 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
---
 libavformat/movenc.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index b4fb2347b..a29ad1fca 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1220,8 +1220,23 @@ static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov,
 static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
                               AVFormatContext *s)
 {
+    int i, req = 0;
+
+    /* Requirements */
+    for (i=0; i<mov->nb_streams; i++) {
+        if(mov->tracks[i].entry <= 0) continue;
+        if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC ||
+            mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) {
+            req = 1;
+            break;
+        }
+    }
+
+    if (s->title[0]   || s->author[0] || s->album[0] || s->year ||
+        s->comment[0] || s->genre[0]  || s->track ||
+       (mov->mode == MODE_MOV &&
+      ((mov->tracks[0].enc && !mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT) || req))) {
     offset_t pos = url_ftell(pb);
-    int i;
 
     put_be32(pb, 0); /* size */
     put_tag(pb, "udta");
@@ -1231,14 +1246,8 @@ static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
 
     if(mov->mode == MODE_MOV){ // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4
         /* Requirements */
-        for (i=0; i<mov->nb_streams; i++) {
-            if(mov->tracks[i].entry <= 0) continue;
-            if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC ||
-                mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) {
+        if (req)
                 mov_write_string_tag(pb, "\251req", "QuickTime 6.0 or greater", 0);
-                break;
-            }
-        }
 
         mov_write_string_tag(pb, "\251nam", s->title         , 0);
         mov_write_string_tag(pb, "\251aut", s->author        , 0);
@@ -1251,6 +1260,9 @@ static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
     }
 
     return updateSize(pb, pos);
+    }
+
+    return 0;
 }
 
 static int utf8len(uint8_t *b){
-- 
2.25.4