Browse Source

V0.2.3
1、添加了VideoPlayer库

Apple 6 months ago
parent
commit
c48e6a401f

+ 19 - 13
common/VedioPlayer_/DecodeVedio.cpp → common/VedioPlayer/DecodeVedio.cpp

@@ -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)

+ 1 - 0
common/VedioPlayer_/DecodeVedio.h → common/VedioPlayer/DecodeVedio.h

@@ -83,6 +83,7 @@ private:
     int m_width = 0;                                /* 图像宽度 */
     int m_height = 0;                               /* 图像高度 */
     int m_frameCount = 0;                           /* 帧数 */
+    int m_fps;                                      /* 每秒的帧数 */
     qint64 m_duration = 0;                          /* 视频时长 */
     qint64 m_currentPos = 0;                        /* 当前播放位置 */
     qint64 m_startPos = 0;                          /* 起始位置,后续操作都需要在这各基础上操作 */

+ 3 - 4
common/VedioPlayer_/VideoPlayer.cpp → common/VedioPlayer/VideoPlayer.cpp

@@ -16,8 +16,7 @@ VideoPlayer::VideoPlayer(QWidget *parent) : QWidget(parent)
     m_threadDecode = new QThread(this);
     m_decodeVedio = new DecodeVedio(m_threadDecode);
 
-    m_semRefresh = new QSemaphore(30);
-    m_semRefresh->release(30);
+    m_semRefresh = new QSemaphore(0);
 
     m_timerRefreshUI.setSingleShot(false);
     /* 设置精度毫秒级 */
@@ -174,8 +173,8 @@ void VideoPlayer::setCurrentPos(quint64 pos)
         m_playStatus = true;
     }else
     {
-        /* 刷新张照片,防止第一张是跳转前的时间段 */
-        m_semRefresh->release(3);
+        /* 刷新10张照片,防止第一张是跳转前的时间段 */
+        m_semRefresh->release(10);
     }
 }
 

+ 0 - 0
common/VedioPlayer_/VideoPlayer.h → common/VedioPlayer/VideoPlayer.h