最简单的方式是直接使用qlable实现
#ifndef QWIDEGETPLAY_H
#define QWIDEGETPLAY_H
#include <QWidget>
#include <QThread>
#include <QImage>
#include <QPainter>
#include <QDebug>
#include <QLabel>
extern "C" {
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avutil.lib")
#pragma comment(lib,"swscale.lib")
#include "libavutil/avutil.h"
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
}
QStringList ffGetStreamInfo(QString url);
class QWidegetRender : public QThread
{
Q_OBJECT
public:
QWidegetRender(QLabel* toRender,QObject *parent=0);
~QWidegetRender();
void startRender(QString playUrl);
void stopRender();
public slots:
void onImage();
void onFScreen();
signals:
void imageReady();
protected:
bool eventFilter(QObject *obj, QEvent *event);
protected:
virtual void run();
int create_swsContext(int iFFPixFmt);
int decode_packet(int *got_frame, int cached);
int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type);
static int ffInterrupt_callback(void* param);
private:
QLabel* m_Widget;
QPainter* painter;
bool m_bFullSrceen;
bool m_bStop;
AVFormatContext *fmt_ctx ;
AVCodecContext *video_dec_ctx ;
AVStream *video_stream ;
QString src_filename ;
SwsContext* sws_cxt;
uint8_t *video_dst_data[4] ;
int video_dst_linesize[4];
int video_dst_bufsize;
int video_stream_idx ;
AVFrame *frame ;
AVPacket pkt;
};
#endif // QWIDEGETPLAY_H
#include "qwidegetplay.h"
#include <QEvent>
#include "qproxyserver.h"
#include <QMessageBox>
QWidegetRender::QWidegetRender(QLabel* toRender,QObject *parent)
: QThread(parent)
{
m_bStop = true;
m_bFullSrceen = false;
painter = new QPainter(toRender);
m_Widget = toRender;
connect(this,SIGNAL(imageReady()),this,SLOT(onImage()),Qt::BlockingQueuedConnection);
//connect(m_Widget,SIGNAL(triggered()),this,SLOT(onFScre