79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
//// FFmpegDecoder.h
|
|
#ifndef FFMPEGDECODER_H
|
|
#define FFMPEGDECODER_H
|
|
|
|
#include <QImage>
|
|
#include <QByteArray>
|
|
#include <QDebug>
|
|
#include <QThread>
|
|
#include <QLabel>
|
|
#include <QTimer>
|
|
#include <QPixmap>
|
|
#include <QMutex>
|
|
#include <QFile>
|
|
#include <QWaitCondition>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
#include <QDir>
|
|
#include <QLineEdit>
|
|
|
|
#include "RingBuffer.h"
|
|
#include "FocusWindow.h"
|
|
|
|
extern "C" {
|
|
#include <libavcodec/avcodec.h>
|
|
#include <libavformat/avformat.h>
|
|
#include <libswscale/swscale.h>
|
|
#include <libavutil/imgutils.h>
|
|
#include <libavcodec/avcodec.h>
|
|
}
|
|
|
|
#define READ_H264_FILE_TO_DISPLAY 1
|
|
|
|
class FFmpegDecoder : public QThread
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit FFmpegDecoder(QObject* parent = nullptr);
|
|
~FFmpegDecoder() override;
|
|
|
|
void initialize();
|
|
void decodeFile(const QString& videoFilePath, QLabel* videoLabel, QLineEdit* VideoResolutionEdit);
|
|
void decodeSingleFrame(const QByteArray& data, QLabel* videoLabel); // 添加 videoLabel 参数
|
|
void FFmpegDecoder::processVideo(int itemIndex);
|
|
bool initializeFFmpeg(const QString& filePath);
|
|
void cleanup();
|
|
void stopFFmpegDecoder();
|
|
|
|
protected:
|
|
void run() override;
|
|
|
|
private:
|
|
QImage avFrameToQImage(AVFrame* frame);
|
|
|
|
QMutex mutex;
|
|
QWaitCondition condition;
|
|
QString filePath;
|
|
QLabel* videoLabel;
|
|
QLabel* videoLabelTemp; // 临时存储新标签
|
|
QLineEdit* resolutionEdit;
|
|
bool videoLabelChanged = false;
|
|
bool abort;
|
|
bool restart;
|
|
bool isGotResolution = false;
|
|
|
|
AVFormatContext* formatContext;
|
|
AVCodecContext* codecContext;
|
|
AVFrame* frame;
|
|
AVPacket* packet;
|
|
SwsContext* swsContext;
|
|
int videoStreamIndex;
|
|
int FocusWindowWidth = 0;
|
|
int FocusWindowHeight = 0;
|
|
|
|
RingBuffer* ringBuffer;
|
|
};
|
|
|
|
#endif // FFMPEGDECODER_H
|