[FFmpeg-devel] [PATCH] movenc: calculate track_duration without packet duration

Alfred E. Heggestad alfred.heggestad at gmail.com
Thu Jun 20 15:32:20 EEST 2019



On 19/06/2019 15:36, Derek Buitenhuis wrote:
> On 19/06/2019 06:43, Gyan wrote:
>>> setting track_duration is inconsistent; some times it includes
>>> duration and some times not.
>> It may be best to check the commits for these assignments to see if the
>> inconsistency is deliberate.
>> The track duration is written into the media header box for the track. I
>> also see it being used elsewhere to adjust dts. Do those roles remain
>> intact?
>>
>> Does FATE pass?
> 
> Wouldn't the correct fix be to fix the places where duration is *not*
> used?
> 
> Writing the track duration without taking into account the actual
> packet duration of the last packet is just wrong. That's not the
> track's duration, and is in fact very problematic for low frame
> rate files, such a slide shows; QuickTime will cut off at the
> end of the media and track duration, dropping possibly a whole
> slide, for example.
> 

I tested with this relatively innocent patch:


diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 46d314ff17..719c491869 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -5012,7 +5012,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
              if (!ff_interleaved_peek(s, i, &pkt, 1)) {
                  if (track->dts_shift != AV_NOPTS_VALUE)
                      pkt.dts += track->dts_shift;
-                track->track_duration = pkt.dts - track->start_dts;
+                track->track_duration = pkt.dts - track->start_dts + pkt.duration;
                  if (pkt.pts != AV_NOPTS_VALUE)
                      track->end_pts = pkt.pts;
                  else



but this broke the FATE test for movenc:




make fate-movenc SAMPLES=fate-suite/
LD	libavformat/tests/movenc
TEST    movenc
--- ./tests/ref/fate/movenc	2019-03-24 10:21:55.000000000 +0100
+++ tests/data/fate/movenc	2019-06-20 14:27:27.000000000 +0200
@@ -134,12 +134,12 @@
  3c2c3f98c8a047f0ecefff07570fd457 9299 large_frag
  write_data len 1231, time nopts, type header atom ftyp
  write_data len 684, time -33333, type sync atom moof
-write_data len 504, time 800000, type boundary atom moof
-write_data len 420, time 1266667, type boundary atom moof
-write_data len 668, time 1566667, type sync atom moof
-write_data len 440, time 2233333, type boundary atom moof
+write_data len 504, time 833333, type boundary atom moof
+write_data len 512, time 1300000, type boundary atom moof
+write_data len 792, time 1566667, type sync atom moof
+write_data len 488, time 2233333, type boundary atom moof
  write_data len 262, time nopts, type trailer atom -
-edd19deae2b70afcf2cd744b89b7013d 4209 vfr-noduration-interleave
+f579e7fec9c37179ed2def2f8930a093 4473 vfr-noduration-interleave
  write_data len 1231, time nopts, type header atom ftyp
  write_data len 916, time 0, type sync atom moof
  write_data len 908, time 1000000, type sync atom moof
Test movenc failed. Look at tests/data/fate/movenc.err for details.
make: *** [fate-movenc] Error 1




/alfred


More information about the ffmpeg-devel mailing list