diff --git a/README.md b/README.md index 4751701..925659d 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,16 @@ 2. 在WidgetRender中,尽可能使用QImage::Format_RGB32和QImage::Format_ARGB32_Premultiplied图像格式。如下原因: 1. Avoid most rendering directly to most of these formats using QPainter. Rendering is best optimized to the Format_RGB32 and Format_ARGB32_Premultiplied formats, and secondarily for rendering to the Format_RGB16, Format_RGBX8888, Format_RGBA8888_Premultiplied, Format_RGBX64 and Format_RGBA64_Premultiplied formats. +### ``avformat_seek_file``,当seek的时间点小于当前时间点一些时,比如-5秒、-10秒,seek不到目标时间点 + +#### 有一种解决方法是:先``seek``到0秒,再``seek``到目标时间点。 +这个时候-5秒、-10秒的seek,效果非常好,比之前好很多,之前有时候会卡在当前时间点,无法seek到目标时间点。 + +```C++ +formatCtx->seek(0); +formatCtx->seek(position); +``` + ### Ffmpeg(5.0)在解码字幕与4.4.3不太一样 ### 解码字幕(ffmpeg-n5.0): diff --git a/examples/player/mainwindow.cpp b/examples/player/mainwindow.cpp index 82c8f5b..a0465c3 100644 --- a/examples/player/mainwindow.cpp +++ b/examples/player/mainwindow.cpp @@ -87,7 +87,6 @@ class MainWindow::MainWindowPrivate playerPtr->addEvent(eventPtr); }); new QShortcut(QKeySequence::MoveToPreviousChar, q_ptr, q_ptr, [this] { - // Todo : seek 不准确 Ffmpeg::EventPtr eventPtr(new Ffmpeg::SeekRelativeEvent(-5)); playerPtr->addEvent(eventPtr); }); diff --git a/ffmpeg/player.cpp b/ffmpeg/player.cpp index a48ca3e..4d1417c 100644 --- a/ffmpeg/player.cpp +++ b/ffmpeg/player.cpp @@ -347,7 +347,9 @@ class Player::PlayerPrivate subtitleDecoder->addEvent(eventPtr); auto position = seekEvent->position(); seekEvent->wait(); - + // before add this line, seek position less than current position, it wiil not accurate, + // and now first seek to 0, then seek to position, it will be very good + formatCtx->seek(0); formatCtx->seek(position); if (audioInfo->isIndexVaild()) { audioInfo->codecCtx()->flush();