Skip to content

Commit

Permalink
fix: #352 mov elst segment duration timescale
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Sep 7, 2024
1 parent 0067166 commit e03136e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions libmov/source/mov-elst.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ size_t mov_write_elst(const struct mov_t* mov)
return size;
}

void mov_apply_elst(struct mov_track_t *track)
void mov_apply_elst(struct mov_track_t *track, uint32_t timescale)
{
size_t i;

Expand All @@ -116,21 +116,21 @@ void mov_apply_elst(struct mov_track_t *track)
{
if (-1 == track->elst[i].media_time)
{
track->samples[0].dts = track->elst[i].segment_duration;
track->samples[0].dts = track->elst[i].segment_duration * track->mdhd.timescale / timescale; // movie timescale -> track timescale
track->samples[0].pts = track->samples[0].dts;
}
}
}

void mov_apply_elst_tfdt(struct mov_track_t *track)
void mov_apply_elst_tfdt(struct mov_track_t *track, uint32_t timescale)
{
size_t i;

for (i = 0; i < track->elst_count; i++)
{
if (-1 == track->elst[i].media_time)
{
track->tfdt_dts += track->elst[i].segment_duration;
track->tfdt_dts += track->elst[i].segment_duration * track->mdhd.timescale / timescale; // movie timescale -> track timescale
}
}
}
4 changes: 2 additions & 2 deletions libmov/source/mov-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ uint32_t mov_build_stts(struct mov_track_t* track);
uint32_t mov_build_ctts(struct mov_track_t* track);
uint32_t mov_build_stco(struct mov_track_t* track);
void mov_apply_stco(struct mov_track_t* track);
void mov_apply_elst(struct mov_track_t *track);
void mov_apply_elst(struct mov_track_t *track, uint32_t timescale);
void mov_apply_stts(struct mov_track_t* track);
void mov_apply_ctts(struct mov_track_t* track);
void mov_apply_stss(struct mov_track_t* track);
void mov_apply_elst_tfdt(struct mov_track_t *track);
void mov_apply_elst_tfdt(struct mov_track_t *track, uint32_t timescale);

void mov_write_size(const struct mov_t* mov, uint64_t offset, size_t size);

Expand Down
2 changes: 1 addition & 1 deletion libmov/source/mov-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int mov_read_trak(struct mov_t* mov, const struct mov_box_t* box)
if (mov->track->sample_count > 0)
{
mov_apply_stco(mov->track);
mov_apply_elst(mov->track);
mov_apply_elst(mov->track, mov->mvhd.timescale);
mov_apply_stts(mov->track);
mov_apply_ctts(mov->track);
mov_apply_stss(mov->track);
Expand Down
2 changes: 1 addition & 1 deletion libmov/source/mov-tfdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int mov_read_tfdt(struct mov_t* mov, const struct mov_box_t* box)
mov->track->tfdt_dts = mov_buffer_r32(&mov->io); /* baseMediaDecodeTime */

// baseMediaDecodeTime + ELST start offset
mov_apply_elst_tfdt(mov->track);
mov_apply_elst_tfdt(mov->track, mov->mvhd.timescale);

(void)box;
return mov_buffer_error(&mov->io);
Expand Down

0 comments on commit e03136e

Please sign in to comment.