diff --git a/src/plugins/ffmpegdecoder/FfmpegDecoder.cpp b/src/plugins/ffmpegdecoder/FfmpegDecoder.cpp index d06fe4571..7c498ca03 100644 --- a/src/plugins/ffmpegdecoder/FfmpegDecoder.cpp +++ b/src/plugins/ffmpegdecoder/FfmpegDecoder.cpp @@ -166,10 +166,9 @@ void FfmpegDecoder::Release() { double FfmpegDecoder::SetPosition(double seconds) { if (this->ioContext && this->formatContext && this->codecContext) { AVStream* stream = this->formatContext->streams[this->streamId]; - AVRational baseQ = { 1, AV_TIME_BASE }; - int64_t pts = av_rescale_q((int64_t)(seconds * AV_TIME_BASE), baseQ, stream->time_base); - avcodec_flush_buffers(this->codecContext); - if (av_seek_frame(this->formatContext, this->streamId, pts, 0) >= 0) { + AVRational timeBase = stream->time_base; + int64_t seekTime = stream->start_time + av_rescale((int64_t) seconds, timeBase.den, timeBase.num); + if (av_seek_frame(this->formatContext, this->streamId, seekTime, AVSEEK_FLAG_ANY) >= 0) { return seconds; } }