mirror of
https://github.com/clangen/musikcube.git
synced 2024-12-29 00:17:49 +00:00
Updated FfmpegDecoder::SetPosition() to be seemingly more reliable
across platforms.
This commit is contained in:
parent
ccc4040213
commit
691dc7e8b1
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user