avformat/movenc: read packet duration at the time it's needed

Reading it at the beginning of ff_mov_write_packet() means that any changes to it
that happen afterwards will not be taken into account for the remainer calculation.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2026-06-29 12:38:12 -03:00
parent 613d65d508
commit dac8b3f367
+4 -3
View File
@@ -6935,7 +6935,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
AVCodecParameters *par;
AVProducerReferenceTime *prft;
unsigned int samples_in_chunk = 0;
int64_t duration = pkt->duration;
int64_t duration;
int size = pkt->size, ret = 0, offset = 0;
size_t prft_size;
uint8_t *reformatted_data = NULL;
@@ -7309,12 +7309,13 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
sd = av_packet_side_data_get(pkt->side_data, pkt->side_data_elems, AV_PKT_DATA_SKIP_SAMPLES);
if (sd && sd->size >= 10 && trk->par->frame_size) {
duration = FFMAX(av_rescale_q(trk->par->frame_size, (AVRational){ 1, trk->par->sample_rate },
trk->st->time_base), duration);
trk->st->time_base), pkt->duration);
duration -= av_rescale_q(AV_RL32(sd->data + 4), (AVRational){ 1, trk->par->sample_rate },
trk->st->time_base);
if (duration < 0)
return AVERROR_INVALIDDATA;
}
} else
duration = pkt->duration;
trk->track_duration = pkt->dts - trk->start_dts + pkt->duration;
trk->last_sample_is_subtitle_end = 0;