WYY
2025-02-27 aeea0feedc9e25294962be52c5e1dc7e34fdb006
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef QFFMPEG_H
#define QFFMPEG_H
 
//必须加以下内容,否则编译不能通过,为了兼容C和C99标准
#ifndef INT64_C
#define INT64_C
#define UINT64_C
#endif
 
//引入ffmpeg头文件
extern "C"
{
#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>
#include <QImage>
 
class QFFmpeg : public QObject
{
    Q_OBJECT
public:
    explicit QFFmpeg(QObject *parent = 0);
    ~QFFmpeg();
 
    bool Init();        // 初始化
    void Play();        // 播放
 
    void SetUrl(QString url){this->url=url;}    // 设置视频源
 
    QString Url()const{return url;}
    int VideoWidth()const{return videoWidth;}
    int VideoHeight()const{return videoHeight;}
    void SetIndex(int x){this->index=x;}
 
private:
    QMutex mutex;
    AVPicture  pAVPicture;
    AVFormatContext *pAVFormatContext;
    AVCodecContext *pAVCodecContext;
    AVFrame *pAVFrame;
    SwsContext * pSwsContext;
    AVPacket pAVPacket;
 
    QString url;
    int videoWidth;
    int videoHeight;
    int videoStreamIndex;
    int index;
 
    // SDL相关
//    SDL_Window *sdlWindow;
//    SDL_Renderer *sdlRenderer;
//    SDL_Texture *sdlTexture;
 
signals:
    void GetImage(const QImage &image,int x);    // 发送解码后的图像信号
 
};
 
#endif // QFFMPEG_H