|
@@ -91,17 +91,23 @@ void DecodeVedio::stopDecodeVedio()
|
|
|
|
|
|
}
|
|
|
|
|
|
-/* 设置当前播放位置,单位是微秒 */
|
|
|
+/**
|
|
|
+ * @brief 设置当前播放位置,单位是微秒
|
|
|
+ * 这里需要去掉队列中已有的图片数目对应的时长
|
|
|
+ *
|
|
|
+ * @param pos
|
|
|
+ */
|
|
|
void DecodeVedio::setCurrentPos(quint64 pos)
|
|
|
{
|
|
|
- // AV_TIME_BASE
|
|
|
- qint64 target_pos = m_startPos + pos;
|
|
|
- SPDLOG_DEBUG("设置播放位置:{}",target_pos);
|
|
|
+
|
|
|
/* 暂停解码 */
|
|
|
m_pauseDecode = true;
|
|
|
-
|
|
|
+ /* 去掉队列中已有的图片数目对应的时长 */
|
|
|
+ int queueNumFPS = m_queueImage.count() * 1000.0 / m_fps;
|
|
|
+ qint64 target_pos = m_startPos + pos - queueNumFPS;
|
|
|
+ SPDLOG_DEBUG("设置播放位置:{}",target_pos);
|
|
|
/* 第二个参数设置为-1,表示所有流都跳转 */
|
|
|
- int ret = av_seek_frame(m_pFormatContext, -1, target_pos, AVSEEK_FLAG_ANY);
|
|
|
+ int ret = av_seek_frame(m_pFormatContext, -1, target_pos, AVSEEK_FLAG_BACKWARD);
|
|
|
if(ret < 0)
|
|
|
{
|
|
|
SPDLOG_WARN("跳转失败...");
|
|
@@ -119,10 +125,11 @@ void DecodeVedio::setCurrentPos(quint64 pos)
|
|
|
|
|
|
}
|
|
|
m_mutexQueue.unlock();
|
|
|
- SPDLOG_INFO("跳转完成 , queue {}", m_queueImage.count());
|
|
|
+ m_condQueueNoFull.wakeAll();
|
|
|
+ SPDLOG_INFO("跳转完成 , queue count {}", m_queueImage.count());
|
|
|
/* 继续解码 */
|
|
|
m_pauseDecode = false;
|
|
|
-
|
|
|
+ // SPDLOG_DEBUG("继续解码... {}", m_pauseDecode.load());
|
|
|
}
|
|
|
|
|
|
/* 获取当前播放位置 */
|
|
@@ -204,13 +211,12 @@ int DecodeVedio::getFrameCount()
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- int fps = 0;
|
|
|
/* 获取视频格式是hevc还是h.264 */
|
|
|
enum AVCodecID codecID = pFormatCtx->streams[videoStreamIndex]->codecpar->codec_id;
|
|
|
if (codecID == AV_CODEC_ID_HEVC)
|
|
|
{
|
|
|
SPDLOG_DEBUG("视频格式是HEVC");
|
|
|
- fps = -2;
|
|
|
+ m_fps = -2;
|
|
|
// AVPacket packet;
|
|
|
// int frameCount = 0;
|
|
|
// double timeBase = av_q2d(pFormatCtx->streams[videoStreamIndex]->time_base);
|
|
@@ -236,16 +242,16 @@ int DecodeVedio::getFrameCount()
|
|
|
SPDLOG_DEBUG("视频格式是H.264");
|
|
|
/* 获取到分子和分母,一除就是帧率 */
|
|
|
AVRational frameRate = pFormatCtx->streams[videoStreamIndex]->avg_frame_rate;
|
|
|
- fps = frameRate.num*1.0 / frameRate.den;
|
|
|
+ m_fps = frameRate.num*1.0 / frameRate.den;
|
|
|
// SPDLOG_DEBUG("分子:{} 分母:{} 帧率:{}",frameRate.num, frameRate.den, fps);
|
|
|
}else
|
|
|
{
|
|
|
- fps = 30;
|
|
|
+ m_fps = 30;
|
|
|
}
|
|
|
|
|
|
avformat_close_input(&pFormatCtx);
|
|
|
|
|
|
- return fps;
|
|
|
+ return m_fps;
|
|
|
}
|
|
|
|
|
|
void DecodeVedio::setVideoSize(int width, int height)
|