From 475b9b1187de24bf8d38db31c64f26c7977c3fd8 Mon Sep 17 00:00:00 2001
From: dpt <1013505110@qq.com>
Date: 星期五, 21 二月 2025 11:40:19 +0800
Subject: [PATCH] 2.20更新

---
 Client/董澎韬/code/main.cpp            |    6 +
 /dev/null                           |    0 
 Client/董澎韬/code/qffmpeg.cpp         |   96 ++++++++++++++++++-----
 Client/董澎韬/log/日志_董澎韬_0220.doc      |    0 
 Client/董澎韬/code/facexmainwindow.cpp |   47 ++++++++++-
 Client/董澎韬/code/form.h              |   22 +++++
 Client/董澎韬/code/qffmpeg.h           |   18 +++-
 Client/董澎韬/code/facexmainwindow.h   |   14 +-
 8 files changed, 165 insertions(+), 38 deletions(-)

diff --git "a/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.cpp" "b/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.cpp"
index 4d398d3..c2e6294 100644
--- "a/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.cpp"
+++ "b/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.cpp"
@@ -8,6 +8,7 @@
 #include <QScreen>
 #include <QException>
 #include <QThread>
+#include <QWheelEvent>
 
 FaceXMainWindow::FaceXMainWindow(QWidget *parent) :
     QMainWindow(parent),
@@ -35,7 +36,7 @@
     m_videowidget->resize(ui->label_video->size());
     m_videowidget->move(ui->label_video->pos());
     m_videowidget->show();
-    ui->label_video->show();
+    ui->label_video->hide();
 
     // 杩炴帴 QFFmpeg 鐨勪俊鍙�
     connect(m_ffmpeg, &QFFmpeg::GetImage, this, &FaceXMainWindow::SetImage, Qt::QueuedConnection);
@@ -45,6 +46,9 @@
         QMessageBox::critical(this, "鎾斁閿欒", m_player->errorString());
     });
 
+    // 杩炴帴鎾斁鍣ㄧ殑浣嶇疆鏇存柊淇″彿
+    connect(m_player, &QMediaPlayer::positionChanged, this, &FaceXMainWindow::updateSliderPosition);
+    connect(ui->horizontalSlider, &QSlider::sliderMoved, this, &FaceXMainWindow::on_sliderPosition_valueChanged);
 
 }
 
@@ -161,6 +165,18 @@
     }
 }
 
+void FaceXMainWindow::playOrPause()
+{
+    isPlaying = !isPlaying;
+    if (isPlaying) {
+        m_player->play();
+        ui->btn_play->setStyleSheet("border-image: url(:/image/pause.png)");
+    } else {
+        m_player->pause();
+        ui->btn_play->setStyleSheet("border-image: url(:/image/start.png)");
+    }
+}
+
 //鎾斁鎸夐挳
 void FaceXMainWindow::on_btn_play_clicked()
 {
@@ -171,6 +187,7 @@
                 m_rtspThread->start();
             }
         }
+        playOrPause();
     } else {
         QMessageBox::critical(this, "閿欒", "鎾斁鍣ㄦ湭鍒濆鍖�");
     }
@@ -189,16 +206,36 @@
 
 void FaceXMainWindow::SetImage(const QImage &image)
 {
-    qDebug() << "鍥惧儚灏哄: " << image.width() << "x" << image.height();
-    qDebug() << "鍥惧儚鏍煎紡: " << image.format();
-    qDebug() << "鎺ユ敹鍒板浘鍍忎俊鍙�";
     if (!image.isNull()) {
         ui->label_video->setScaledContents(true); // 璁剧疆鍥惧儚鑷姩缂╂斁
         ui->label_video->setPixmap(QPixmap::fromImage(image));
         ui->label_video->adjustSize();
         ui->label_video->update();
-        qDebug() << "鍥惧儚宸叉洿鏂�";
     } else {
         qDebug() << "鎺ユ敹鍒扮殑鍥惧儚涓虹┖";
     }
 }
+
+//鏇存柊婊戝潡鐨勪綅缃�
+void FaceXMainWindow::updateSliderPosition()
+{
+    ui->horizontalSlider->setValue(m_player->position());
+}
+
+//鎷栧姩婊戝潡鏉ユ帶鍒舵挱鏀捐繘搴�
+void FaceXMainWindow::on_sliderPosition_valueChanged(int value)
+{
+    m_player->setPosition(value);
+}
+
+void FaceXMainWindow::on_btn_back_clicked()
+{
+    int currentPosition = m_player->position();
+    m_player->setPosition(currentPosition - 10000); // 鍚庨�� 10 绉�
+}
+
+void FaceXMainWindow::on_btn_forward_clicked()
+{
+    int currentPosition = m_player->position();
+    m_player->setPosition(currentPosition + 10000); // 鍓嶈繘 10 绉�
+}
diff --git "a/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.h" "b/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.h"
index 71a4542..da06402 100644
--- "a/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.h"
+++ "b/Client/\350\221\243\346\276\216\351\237\254/code/facexmainwindow.h"
@@ -45,22 +45,19 @@
     void mouseReleaseEvent(QMouseEvent *event)override;
     void mouseDoubleClickEvent(QMouseEvent *event)override;
 
-
 private slots:
     void on_btnSelect_clicked();
-
     void on_toolButton_clicked();
-
     void on_toolButton_3_clicked();
-
     void on_toolButton_2_clicked();
-
     void on_btn_play_clicked();
-
     void on_btn_cut_clicked();
-
     void SetImage(const QImage &image);
 
+    void updateSliderPosition();
+    void on_sliderPosition_valueChanged(int value);
+    void on_btn_back_clicked();
+    void on_btn_forward_clicked();
 
 private:
     Ui::FaceXMainWindow *ui;
@@ -76,7 +73,10 @@
     QFFmpeg *m_ffmpeg;
     RtspThread *m_rtspThread;
 
+    bool isPlaying = false;
+
     void setPlayButtonIcon(bool isPlaying);
+    void playOrPause();
 };
 
 #endif // FACEXMAINWINDOW_H
diff --git "a/Client/\350\221\243\346\276\216\351\237\254/code/form.h" "b/Client/\350\221\243\346\276\216\351\237\254/code/form.h"
new file mode 100644
index 0000000..58a60a0
--- /dev/null
+++ "b/Client/\350\221\243\346\276\216\351\237\254/code/form.h"
@@ -0,0 +1,22 @@
+#ifndef FORM_H
+#define FORM_H
+
+#include <QWidget>
+
+namespace Ui {
+class Form;
+}
+
+class Form : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit Form(QWidget *parent = 0);
+    ~Form();
+
+private:
+    Ui::Form *ui;
+};
+
+#endif // FORM_H
diff --git "a/Client/\350\221\243\346\276\216\351\237\254/code/main.cpp" "b/Client/\350\221\243\346\276\216\351\237\254/code/main.cpp"
index 168202d..2e3811b 100644
--- "a/Client/\350\221\243\346\276\216\351\237\254/code/main.cpp"
+++ "b/Client/\350\221\243\346\276\216\351\237\254/code/main.cpp"
@@ -7,5 +7,11 @@
     FaceXMainWindow w;
     w.show();
 
+    //    SDL楠岃瘉
+    //    SDL_version version;
+    //    SDL_VERSION(&version);
+    //    qDebug()<<"version major is"<<version.major;
+    //    qDebug()<<"version minor is"<<version.minor;
+
     return a.exec();
 }
diff --git "a/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.cpp" "b/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.cpp"
index 756314e..851792c 100644
--- "a/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.cpp"
+++ "b/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.cpp"
@@ -24,7 +24,6 @@
     if (pSwsContext) {
         sws_freeContext(pSwsContext);
     }
-    avpicture_free(&pAVPicture);
 }
 
 bool QFFmpeg::Init()
@@ -46,9 +45,6 @@
 
     //鑾峰彇瑙嗛娴佺储寮�
     videoStreamIndex = -1;
-//    qDebug()<<"nb:"<<pAVFormatContext->nb_streams;
-//    qDebug()<<"type:"<<pAVFormatContext->streams[0]->codec->codec_type;
-//    qDebug()<<"AVMEDIA_TYPE_VIDEO:"<<AVMEDIA_TYPE_VIDEO;
     for (uint i = 0; i < pAVFormatContext->nb_streams; i++) {
         if (pAVFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
             videoStreamIndex = i;
@@ -67,8 +63,6 @@
     videoWidth=pAVCodecContext->width;
     videoHeight=pAVCodecContext->height;
 
-    avpicture_alloc(&pAVPicture,AV_PIX_FMT_RGB24,videoWidth,videoHeight);
-
     AVCodec *pAVCodec;
 
     //鑾峰彇瑙嗛娴佽В鐮佸櫒
@@ -79,7 +73,6 @@
     result=avcodec_open2(pAVCodecContext,pAVCodec,NULL);
     if (result<0){
         qDebug()<<"鎵撳紑瑙g爜鍣ㄥけ璐�";
-        avpicture_free(&pAVPicture);
         sws_freeContext(pSwsContext);
         avformat_close_input(&pAVFormatContext);
         return false;
@@ -91,23 +84,82 @@
 
 void QFFmpeg::Play()
 {
-    //涓�甯т竴甯ц鍙栬棰�
-    int frameFinished = 0;
-    while (av_read_frame(pAVFormatContext, &pAVPacket) >= 0) {
-        if (pAVPacket.stream_index == videoStreamIndex) {
-            qDebug() << "寮�濮嬭В鐮�" << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
-            avcodec_decode_video2(pAVCodecContext, pAVFrame, &frameFinished, &pAVPacket);
-            if (frameFinished) {
-                mutex.lock();
-                sws_scale(pSwsContext, (const uint8_t* const *)pAVFrame->data, pAVFrame->linesize, 0, videoHeight, pAVPicture.data, pAVPicture.linesize);
-                QImage image(pAVPicture.data[0], videoWidth, videoHeight, QImage::Format_RGB888);
-                QImage copyImage = image.copy(); // 娣辨嫹璐�
-                emit GetImage(copyImage, this->index);
-                qDebug() << "瑙g爜鎴愬姛锛屽彂閫佸浘鍍忎俊鍙�";
-                mutex.unlock();
+    AVPacket packet;
+    int frameFinished;
+    int videoStreamIndex = -1;
+
+    // 鎵撳紑瑙嗛鏂囦欢
+    if (avformat_open_input(&pAVFormatContext, url.toStdString().c_str(), NULL, NULL) != 0)
+        return;
+
+    // 鑾峰彇娴佷俊鎭�
+    avformat_find_stream_info(pAVFormatContext, NULL);
+
+    // 鎵惧埌瑙嗛娴佺储寮�
+    for (uint i = 0; i < pAVFormatContext->nb_streams; i++) {
+        if (pAVFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+            videoStreamIndex = i;
+            break;
+        }
+    }
+
+    // 鑾峰彇瑙g爜鍣�
+    AVCodec *codec = avcodec_find_decoder(pAVFormatContext->streams[videoStreamIndex]->codec->codec_id);
+    if (!codec) {
+        qDebug() << "鏈壘鍒拌В鐮佸櫒";
+        return;
+    }
+
+    if (avcodec_open2(pAVCodecContext, codec, NULL) < 0) {
+        qDebug() << "鎵撳紑瑙g爜鍣ㄥけ璐�";
+        return;
+    }
+
+    // 鍒濆鍖栧抚
+    pAVFrame = av_frame_alloc();
+    AVFrame *pFrameRGB = av_frame_alloc();
+    uint8_t *buffer = (uint8_t *)av_malloc(avpicture_get_size(AV_PIX_FMT_RGB24, pAVCodecContext->width, pAVCodecContext->height));
+    avpicture_fill((AVPicture *)pFrameRGB, buffer, AV_PIX_FMT_RGB24, pAVCodecContext->width, pAVCodecContext->height);
+
+    // 鍒濆鍖栫缉鏀句笂涓嬫枃
+    struct SwsContext *sws_ctx = sws_getContext(pAVCodecContext->width,
+                                                pAVCodecContext->height,
+                                                pAVCodecContext->pix_fmt,
+                                                pAVCodecContext->width,
+                                                pAVCodecContext->height,
+                                                AV_PIX_FMT_RGB24,
+                                                SWS_BILINEAR,
+                                                NULL,
+                                                NULL,
+                                                NULL);
+
+    while (av_read_frame(pAVFormatContext, &packet) >= 0) {
+        if (packet.stream_index == videoStreamIndex) {
+            avcodec_send_packet(pAVCodecContext, &packet);
+
+            while (avcodec_receive_frame(pAVCodecContext, pAVFrame) == 0) {
+                sws_scale(sws_ctx,
+                        (const uint8_t **)pAVFrame->data,
+                        pAVFrame->linesize,
+                        0,
+                        pAVCodecContext->height,
+                        pFrameRGB->data,
+                        pFrameRGB->linesize);
+
+                QImage img(pFrameRGB->data[0],
+                        pAVCodecContext->width,
+                        pAVCodecContext->height,
+                        QImage::Format_RGB888);
+
+                emit GetImage(img, 0);
             }
         }
-        av_packet_unref(&pAVPacket);
+        av_packet_unref(&packet);
     }
+
     avformat_close_input(&pAVFormatContext);
+    av_frame_free(&pAVFrame);
+    av_frame_free(&pFrameRGB);
+    av_free(buffer);
+    sws_freeContext(sws_ctx);
 }
diff --git "a/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.h" "b/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.h"
index 9085958..9f92d44 100644
--- "a/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.h"
+++ "b/Client/\350\221\243\346\276\216\351\237\254/code/qffmpeg.h"
@@ -10,12 +10,19 @@
 //寮曞叆ffmpeg澶存枃浠�
 extern "C"
 {
-#include <libavcodec/avcodec.h>
-#include <libavformat/avformat.h>
+#include <libavcodec/avcodec.h>     //瀹炵幇闊宠棰戠殑缂栬В鐮佸姛鑳�
+#include <libavformat/avformat.h>   //瀹炵幇闊宠棰戞枃浠剁殑璇诲彇鍜屽啓鍏ュ姛鑳斤紝鏀寔澶氱闊宠棰戞牸寮�
 #include <libavfilter/avfilter.h>
 #include <libswscale/swscale.h>
 #include <libavutil/frame.h>
+#include <libavutil/imgutils.h>
 }
+
+// 寮曞叆SDL2澶存枃浠�
+//extern "C"
+//{
+//   #include "SDL.h"
+//}
 
 #include <QObject>
 #include <QMutex>
@@ -53,10 +60,13 @@
     int videoStreamIndex;
     int index;
 
+    // SDL鐩稿叧
+//    SDL_Window *sdlWindow;
+//    SDL_Renderer *sdlRenderer;
+//    SDL_Texture *sdlTexture;
+
 signals:
     void GetImage(const QImage &image,int x);    // 鍙戦�佽В鐮佸悗鐨勫浘鍍忎俊鍙�
-
-public slots:
 
 };
 
diff --git "a/Client/\350\221\243\346\276\216\351\237\254/code/\345\255\230\346\224\276\344\273\243\347\240\201.txt" "b/Client/\350\221\243\346\276\216\351\237\254/code/\345\255\230\346\224\276\344\273\243\347\240\201.txt"
deleted file mode 100644
index e69de29..0000000
--- "a/Client/\350\221\243\346\276\216\351\237\254/code/\345\255\230\346\224\276\344\273\243\347\240\201.txt"
+++ /dev/null
diff --git "a/Client/\350\221\243\346\276\216\351\237\254/log/\346\227\245\345\277\227_\350\221\243\346\276\216\351\237\254_0220.doc" "b/Client/\350\221\243\346\276\216\351\237\254/log/\346\227\245\345\277\227_\350\221\243\346\276\216\351\237\254_0220.doc"
new file mode 100644
index 0000000..f72ac69
--- /dev/null
+++ "b/Client/\350\221\243\346\276\216\351\237\254/log/\346\227\245\345\277\227_\350\221\243\346\276\216\351\237\254_0220.doc"
Binary files differ

--
Gitblit v1.8.0