mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 00:19:20 +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) {
|
double FfmpegDecoder::SetPosition(double seconds) {
|
||||||
if (this->ioContext && this->formatContext && this->codecContext) {
|
if (this->ioContext && this->formatContext && this->codecContext) {
|
||||||
AVStream* stream = this->formatContext->streams[this->streamId];
|
AVStream* stream = this->formatContext->streams[this->streamId];
|
||||||
AVRational baseQ = { 1, AV_TIME_BASE };
|
AVRational timeBase = stream->time_base;
|
||||||
int64_t pts = av_rescale_q((int64_t)(seconds * AV_TIME_BASE), baseQ, stream->time_base);
|
int64_t seekTime = stream->start_time + av_rescale((int64_t) seconds, timeBase.den, timeBase.num);
|
||||||
avcodec_flush_buffers(this->codecContext);
|
if (av_seek_frame(this->formatContext, this->streamId, seekTime, AVSEEK_FLAG_ANY) >= 0) {
|
||||||
if (av_seek_frame(this->formatContext, this->streamId, pts, 0) >= 0) {
|
|
||||||
return seconds;
|
return seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user