From 1f83f046090cac09b7a3da7f15182d2143bccf87 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Tue, 13 Dec 2011 03:02:20 +0100
Subject: [PATCH] mp4enc: dont store durations in trun if they are unneeded.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
---
 libavformat/movenc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index de6dafb288d..31fd05d3706 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1447,8 +1447,12 @@ static int mov_write_trun_tag(AVIOContext *pb, MOVTrack *track)
     int tr_flags=0;
     int i;
 
-    tr_flags |= 0x700; //FIXME
+    tr_flags |= 0x600; //FIXME
     for(i=track->cluster_write_index; i<track->entry; i++){
+        int64_t duration = i + 1 == track->entry ?
+                track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */
+                track->cluster[i+1].dts - track->cluster[i].dts;
+        if(duration         != 1) tr_flags |= 0x100;
         if(track->cluster[i].cts) tr_flags |= 0x800;
     }
 
-- 
GitLab