diff mbox

[FFmpeg-devel,v2] mov: Properly abide by the track's media duration

Message ID 1524498415-23141-1-git-send-email-derek.buitenhuis@gmail.com
State Accepted
Commit 28503c5aea5f5ecaab95e9d0c56064132e4796d3
Headers show

Commit Message

Derek Buitenhuis April 23, 2018, 3:46 p.m. UTC
The track's media duration from the mdhd atom takes precedence
over both the stts and elst atom for calculating and setting
the track's total duraion.

Technically, we shouldn't be using the stts atom at all for
calculating stream durations.

This fixes incorrect stream and final packet durations on files
with edit lists that are longer than the media duration.

The FATE changes are expected, and output is more correct (the
AAC frame is not 1028 samples).

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
---
 libavformat/mov.c                   | 6 +++---
 tests/ref/fate/adtstoasc_ticket3715 | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Derek Buitenhuis April 25, 2018, 3:07 p.m. UTC | #1
On 4/23/2018 4:46 PM, Derek Buitenhuis wrote:
> The track's media duration from the mdhd atom takes precedence
> over both the stts and elst atom for calculating and setting
> the track's total duraion.
> 
> Technically, we shouldn't be using the stts atom at all for
> calculating stream durations.
> 
> This fixes incorrect stream and final packet durations on files
> with edit lists that are longer than the media duration.
> 
> The FATE changes are expected, and output is more correct (the
> AAC frame is not 1028 samples).
> 
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
> ---
>  libavformat/mov.c                   | 6 +++---
>  tests/ref/fate/adtstoasc_ticket3715 | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)

Ping.

If there are no further comments, I plan to push tomorrow evening.

- Derek
Derek Buitenhuis April 26, 2018, 1:54 p.m. UTC | #2
On 4/25/2018 4:07 PM, Derek Buitenhuis wrote:
> Ping.
> 
> If there are no further comments, I plan to push tomorrow evening.

It's been over 10 days, and the sole comment was addressed.

Pushed.

- Derek
diff mbox

Patch

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 8fea670..1975011 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2932,7 +2932,7 @@  static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 
     st->nb_frames= total_sample_count;
     if (duration)
-        st->duration= duration;
+        st->duration= FFMIN(st->duration, duration);
     sc->track_end = duration;
     return 0;
 }
@@ -3671,8 +3671,8 @@  static void mov_fix_index(MOVContext *mov, AVStream *st)
         }
     }
 
-    // Update av stream length
-    st->duration = edit_list_dts_entry_end - start_dts;
+    // Update av stream length, if it ends up shorter than the track's media duration
+    st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts);
     msc->start_pad = st->skip_samples;
 
     // Free the old index and the old CTTS structures
diff --git a/tests/ref/fate/adtstoasc_ticket3715 b/tests/ref/fate/adtstoasc_ticket3715
index 96795a2..c5f03e4 100644
--- a/tests/ref/fate/adtstoasc_ticket3715
+++ b/tests/ref/fate/adtstoasc_ticket3715
@@ -92,4 +92,4 @@ 
 0,      83968,      83968,     1024,      465, 0xeb3ce0af
 0,      84992,      84992,     1024,      326, 0x7be4a667
 0,      86016,      86016,     1024,      339, 0x2cf4a71f
-0,      87040,      87040,     1028,      258, 0xd4007ad4
+0,      87040,      87040,     1024,      258, 0xd4007ad4