-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideowidget.cpp
48 lines (43 loc) · 1.09 KB
/
videowidget.cpp
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
#include "videowidget.h"
#include <QPainter>
#include <QImage>
#include<QPoint>
#include"xffmpeg.h"
#include <QDebug>
VideoWidget::VideoWidget(QWidget *p):QOpenGLWidget(p)
{
XFFmpeg::Get()->Open("/Users/xuxudong/CLionProjects/untitled/1.mp4");
startTimer(20);
}
VideoWidget::~VideoWidget()
{
}
void VideoWidget::paintEvent(QPaintEvent *e)
{
static QImage *image=NULL;
if(image==NULL)
{
uchar *buf=new uchar[width()*height()*4];
image=new QImage(buf,width(),height(),QImage::Format_ARGB32);
}
AVPacket pkt=XFFmpeg::Get()->Read();
if(pkt.stream_index!=XFFmpeg::Get()->videostream)
{
av_packet_unref(&pkt);
return;
}
if(pkt.size==0) return;
AVFrame *yuv=XFFmpeg::Get()->Decode(&pkt);
av_packet_unref(&pkt);
if(yuv==NULL) return;
XFFmpeg::Get()->ToRGB(*yuv,(char*)image->bits(),width(),height());
QPainter painter;
painter.begin(this);
//painter.drawImage(QPoint(0,0),image);
painter.drawImage(QPoint(0,0),*image);
painter.end();
}
void VideoWidget::timerEvent(QTimerEvent *e)
{
this->update();
}