}
}
+static int get_cluster_duration(MOVTrack *track, int cluster_idx)
+{
+ int64_t next_dts;
+
+ if (cluster_idx >= track->entry)
+ return 0;
+
+ if (cluster_idx + 1 == track->entry)
+ next_dts = track->track_duration + track->start_dts;
+ else
+ next_dts = track->cluster[cluster_idx + 1].dts;
+
+ return next_dts - track->cluster[cluster_idx].dts;
+}
+
static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track)
{
int64_t pos = avio_tell(pb);
av_malloc(track->entry * sizeof(*stts_entries)) : /* worst case */
NULL;
for (i=0; i<track->entry; i++) {
- int64_t duration = i + 1 == track->entry ?
- track->track_duration - track->cluster[i].dts + track->start_dts : /* readjusting */
- track->cluster[i+1].dts - track->cluster[i].dts;
+ int duration = get_cluster_duration(track, i);
if (i && duration == stts_entries[entries].duration) {
stts_entries[entries].count++; /* compress */
} else {
int i;
for (i = 0; i < track->entry; i++) {
- int64_t duration = i + 1 == track->entry ?
- track->track_duration - track->cluster[i].dts + track->start_dts :
- track->cluster[i + 1].dts - track->cluster[i].dts;
- if (duration != track->default_duration)
+ if (get_cluster_duration(track, i) != track->default_duration)
flags |= MOV_TRUN_SAMPLE_DURATION;
if (track->cluster[i].size != track->default_size)
flags |= MOV_TRUN_SAMPLE_SIZE;
avio_wb32(pb, get_sample_flags(track, &track->cluster[0]));
for (i = 0; i < track->entry; i++) {
- int64_t duration = i + 1 == track->entry ?
- track->track_duration - track->cluster[i].dts + track->start_dts :
- track->cluster[i + 1].dts - track->cluster[i].dts;
if (flags & MOV_TRUN_SAMPLE_DURATION)
- avio_wb32(pb, duration);
+ avio_wb32(pb, get_cluster_duration(track, i));
if (flags & MOV_TRUN_SAMPLE_SIZE)
avio_wb32(pb, track->cluster[i].size);
if (flags & MOV_TRUN_SAMPLE_FLAGS)