Skip to content

Commit fbe8653

Browse files
committed
Handle non-compliant files
Blackmagic Design DaVinci Resolve Studio can write mp4 file with `ctts version 1` but mark it as `ctts version 0`. Always interpreting the `sample_offset` as signed is safe even if we have `ctts version 0`. We need offset >= 6.6 hours (a frame, after being decoded, should wait 6.6 hours before being displayed) for getting overflow.
1 parent 30270d0 commit fbe8653

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

core/box.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,12 +2724,11 @@ void isom_update_cache_timestamp
27242724
static inline uint64_t isom_make_cts
27252725
(
27262726
uint64_t dts,
2727-
uint32_t sample_offset,
2728-
int32_t ctd_shift
2727+
uint32_t sample_offset
27292728
)
27302729
{
27312730
if( sample_offset != ISOM_NON_OUTPUT_SAMPLE_OFFSET )
2732-
return ctd_shift ? (dts + (int32_t)sample_offset) : (dts + sample_offset);
2731+
return dts + (int32_t)sample_offset;
27332732
else
27342733
return LSMASH_TIMESTAMP_UNDEFINED;
27352734
}
@@ -2744,7 +2743,7 @@ static inline uint64_t isom_make_cts_adjust
27442743
)
27452744
{
27462745
if( sample_offset != ISOM_NON_OUTPUT_SAMPLE_OFFSET )
2747-
return ctd_shift ? (dts + (int32_t)sample_offset + ctd_shift) : (dts + sample_offset);
2746+
return dts + (int32_t)sample_offset + ctd_shift;
27482747
else
27492748
return LSMASH_TIMESTAMP_UNDEFINED;
27502749
}

core/timeline.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static int isom_get_cts_from_info_list( isom_timeline_t *timeline, uint32_t samp
436436
isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number );
437437
if( !info )
438438
return LSMASH_ERR_NAMELESS;
439-
*cts = isom_make_cts( *cts, info->offset, timeline->ctd_shift );
439+
*cts = isom_make_cts( *cts, info->offset );
440440
return 0;
441441
}
442442

@@ -530,7 +530,7 @@ static lsmash_sample_t *isom_get_lpcm_sample_from_media_timeline( isom_timeline_
530530
return NULL;
531531
/* Get sample info. */
532532
sample->dts = timeline->last_accessed_lpcm_bunch_dts + sample_number_offset * bunch->duration;
533-
sample->cts = isom_make_cts( sample->dts, bunch->offset, timeline->ctd_shift );
533+
sample->cts = isom_make_cts( sample->dts, bunch->offset );
534534
sample->pos = sample_pos;
535535
sample->length = bunch->length;
536536
sample->index = bunch->index;
@@ -553,7 +553,7 @@ static lsmash_sample_t *isom_get_sample_from_media_timeline( isom_timeline_t *ti
553553
return NULL;
554554
/* Get sample info. */
555555
sample->dts = dts;
556-
sample->cts = isom_make_cts( dts, info->offset, timeline->ctd_shift );
556+
sample->cts = isom_make_cts( dts, info->offset );
557557
sample->pos = info->pos;
558558
sample->length = info->length;
559559
sample->index = info->index;
@@ -568,7 +568,7 @@ static int isom_get_lpcm_sample_info_from_media_timeline( isom_timeline_t *timel
568568
return LSMASH_ERR_NAMELESS;
569569
uint64_t sample_number_offset = sample_number - timeline->last_accessed_lpcm_bunch_first_sample_number;
570570
sample->dts = timeline->last_accessed_lpcm_bunch_dts + sample_number_offset * bunch->duration;
571-
sample->cts = isom_make_cts( sample->dts, bunch->offset, timeline->ctd_shift );
571+
sample->cts = isom_make_cts( sample->dts, bunch->offset );
572572
sample->pos = bunch->pos + sample_number_offset * bunch->length;
573573
sample->length = bunch->length;
574574
sample->index = bunch->index;
@@ -586,7 +586,7 @@ static int isom_get_sample_info_from_media_timeline( isom_timeline_t *timeline,
586586
if( !info )
587587
return LSMASH_ERR_NAMELESS;
588588
sample->dts = dts;
589-
sample->cts = isom_make_cts( dts, info->offset, timeline->ctd_shift );
589+
sample->cts = isom_make_cts( dts, info->offset );
590590
sample->pos = info->pos;
591591
sample->length = info->length;
592592
sample->index = info->index;
@@ -1993,7 +1993,7 @@ int lsmash_get_media_timestamps( lsmash_root_t *root, uint32_t track_ID, lsmash_
19931993
return LSMASH_ERR_NAMELESS;
19941994
}
19951995
ts[i].dts = dts;
1996-
ts[i].cts = isom_make_cts( dts, info->offset, timeline->ctd_shift );
1996+
ts[i].cts = isom_make_cts( dts, info->offset );
19971997
dts += info->duration;
19981998
++i;
19991999
}
@@ -2009,7 +2009,7 @@ int lsmash_get_media_timestamps( lsmash_root_t *root, uint32_t track_ID, lsmash_
20092009
for( uint32_t j = 0; j < bunch->sample_count; j++ )
20102010
{
20112011
ts[i].dts = dts;
2012-
ts[i].cts = isom_make_cts( dts, bunch->offset, timeline->ctd_shift );
2012+
ts[i].cts = isom_make_cts( dts, bunch->offset );
20132013
dts += bunch->duration;
20142014
++i;
20152015
}

0 commit comments

Comments
 (0)