Skip to content

Commit e03136e

Browse files
committed
fix: #352 mov elst segment duration timescale
1 parent 0067166 commit e03136e

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

libmov/source/mov-elst.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ size_t mov_write_elst(const struct mov_t* mov)
105105
return size;
106106
}
107107

108-
void mov_apply_elst(struct mov_track_t *track)
108+
void mov_apply_elst(struct mov_track_t *track, uint32_t timescale)
109109
{
110110
size_t i;
111111

@@ -116,21 +116,21 @@ void mov_apply_elst(struct mov_track_t *track)
116116
{
117117
if (-1 == track->elst[i].media_time)
118118
{
119-
track->samples[0].dts = track->elst[i].segment_duration;
119+
track->samples[0].dts = track->elst[i].segment_duration * track->mdhd.timescale / timescale; // movie timescale -> track timescale
120120
track->samples[0].pts = track->samples[0].dts;
121121
}
122122
}
123123
}
124124

125-
void mov_apply_elst_tfdt(struct mov_track_t *track)
125+
void mov_apply_elst_tfdt(struct mov_track_t *track, uint32_t timescale)
126126
{
127127
size_t i;
128128

129129
for (i = 0; i < track->elst_count; i++)
130130
{
131131
if (-1 == track->elst[i].media_time)
132132
{
133-
track->tfdt_dts += track->elst[i].segment_duration;
133+
track->tfdt_dts += track->elst[i].segment_duration * track->mdhd.timescale / timescale; // movie timescale -> track timescale
134134
}
135135
}
136136
}

libmov/source/mov-internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ uint32_t mov_build_stts(struct mov_track_t* track);
307307
uint32_t mov_build_ctts(struct mov_track_t* track);
308308
uint32_t mov_build_stco(struct mov_track_t* track);
309309
void mov_apply_stco(struct mov_track_t* track);
310-
void mov_apply_elst(struct mov_track_t *track);
310+
void mov_apply_elst(struct mov_track_t *track, uint32_t timescale);
311311
void mov_apply_stts(struct mov_track_t* track);
312312
void mov_apply_ctts(struct mov_track_t* track);
313313
void mov_apply_stss(struct mov_track_t* track);
314-
void mov_apply_elst_tfdt(struct mov_track_t *track);
314+
void mov_apply_elst_tfdt(struct mov_track_t *track, uint32_t timescale);
315315

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

libmov/source/mov-reader.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static int mov_read_trak(struct mov_t* mov, const struct mov_box_t* box)
103103
if (mov->track->sample_count > 0)
104104
{
105105
mov_apply_stco(mov->track);
106-
mov_apply_elst(mov->track);
106+
mov_apply_elst(mov->track, mov->mvhd.timescale);
107107
mov_apply_stts(mov->track);
108108
mov_apply_ctts(mov->track);
109109
mov_apply_stss(mov->track);

libmov/source/mov-tfdt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int mov_read_tfdt(struct mov_t* mov, const struct mov_box_t* box)
1717
mov->track->tfdt_dts = mov_buffer_r32(&mov->io); /* baseMediaDecodeTime */
1818

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

2222
(void)box;
2323
return mov_buffer_error(&mov->io);

0 commit comments

Comments
 (0)