Skip to content

Commit

Permalink
更新ffmpegdemo解码
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyangqingyun committed Sep 7, 2020
1 parent 2a80cb5 commit 7b52f1b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ffmpegdemo/ffmpeg/ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ bool FFmpegThread::init()

void FFmpegThread::run()
{
//计时
QTime time;
while (!stopped) {
//根据标志位执行初始化操作
if (isPlay) {
Expand All @@ -241,16 +239,26 @@ void FFmpegThread::run()
continue;
}

time.restart();
if (av_read_frame(avFormatContext, avPacket) >= 0) {
//判断当前包是视频还是音频
int packetSize = avPacket->size;
int index = avPacket->stream_index;
if (index == videoStreamIndex) {
//解码视频流
//解码视频流 avcodec_decode_video2 方法已被废弃
#if 0
avcodec_decode_video2(videoCodec, avFrame2, &frameFinish, avPacket);
#else
frameFinish = avcodec_send_packet(videoCodec, avPacket);
if (frameFinish < 0) {
continue;
}

frameFinish = avcodec_receive_frame(videoCodec, avFrame2);
if (frameFinish < 0) {
continue;
}
#endif

if (frameFinish) {
if (frameFinish >= 0) {
//将数据转成一张图片
sws_scale(swsContext, (const uint8_t *const *)avFrame2->data, avFrame2->linesize, 0, videoHeight, avFrame3->data, avFrame3->linesize);

Expand Down Expand Up @@ -354,11 +362,11 @@ void FFmpegThread::stop()
}

//实时视频显示窗体类
FFmpegWidget::FFmpegWidget(QWidget * parent) : QWidget(parent)
FFmpegWidget::FFmpegWidget(QWidget *parent) : QWidget(parent)
{
thread = new FFmpegThread(this);
connect(thread, SIGNAL(receiveImage(QImage)), this, SLOT(updateImage(QImage)));
image = QImage();
image = QImage();
}

FFmpegWidget::~FFmpegWidget()
Expand Down

0 comments on commit 7b52f1b

Please sign in to comment.