fix: skip disposable pictures during local seek preroll

This commit is contained in:
2026-10-18 20:11:39 +02:00
parent 2e61bd7864
commit ddf53ea606
5 changed files with 97 additions and 3 deletions
+12
View File
@@ -468,6 +468,7 @@ struct Player {
for (auto &track : tracks) {
if (!track.codec) continue;
avcodec_flush_buffers(track.codec);
track.codec->skip_frame = AVDISCARD_DEFAULT;
track.drainSent = track.drained = false;
track.firstPacket = true;
av_packet_unref(track.packet);
@@ -1151,6 +1152,17 @@ struct Player {
"Preparing video decoder preroll");
track.firstPacket = false;
}
if (slot == 1) {
// Preroll needs reference pictures, not disposable pictures before
// the target. Restore full decoding before the target packet and
// for exact frame stepping; never guess when timestamps are absent.
const auto *packet = track.packet;
const bool preroll = !network && !stepping && !previewShown && seekTarget > 0 &&
packet->pts != AV_NOPTS_VALUE &&
packet->duration > 0 &&
(double(packet->pts) + packet->duration) * av_q2d(track.stream()->time_base) - origin < seekTarget;
track.codec->skip_frame = preroll ? AVDISCARD_NONREF : AVDISCARD_DEFAULT;
}
const int result = avcodec_send_packet(track.codec, track.packet);
if (result != AVERROR(EAGAIN)) {
check(result, "Sending media packet to decoder");