#include "qffmpeg.h"
QFFmpeg::QFFmpeg(QObject *parent) :
QObject(parent)
{
av_register_all();
//pFormatCtx = avformat_alloc_context();
avformat_network_init();
pFrame = av_frame_alloc();
pFrameRGB = av_frame_alloc();
mutex = new QMutex;
size = 0;
ret = -1;
Videostreamindex = -1;
gotpicutre = 0;
}
QFFmpeg::~QFFmpeg()
{
sws_freeContext(pSwsCtx);
av_frame_free(&pFrame);
av_frame_free(&pFrameRGB);
avcodec_close(pCodecCtx);
avformat_close_input(&pFormatCtx);
}
void QFFmpeg::init_ffmpeg()
{
int i;
char filepath[]= "D:/01.mp4";
result = 1;
// strcpy(filepath,(const char*)str.toLocal8Bit());
qDebug()<<filepath;
result = avformat_open_input(&pFormatCtx,filepath,NULL,NULL);
if(result==0)
{
qDebug()<<" open file true";
}
for(i = 0;i<pFormatCtx->nb_streams;i++)
{
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
Videostreamindex = i;
break;
}
}
qDebug()<<"Videostreamindex ="<<Videostreamindex;
pCodecCtx = pFormatCtx->streams[Videostreamindex]->codec;
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec == NULL)
{
qDebug()<<"find decoder failed";
}
qDebug()<<"codec id is"<<pCodec->id;
result=avcodec_open2(pCodecCtx,pCodec,NULL);
if(result>=0)
{
qDebug()<<"open codec ";
}
qDebug()<<"open codec result is"<<result;
Videoheight = pCodecCtx->height;
Videowidth = pCodecCtx->width;
qDebug()<<"Videowidth is"<<Videowidth;
qDebug()<<"Videoheight is"<<Videoheight;
//size = avpicture_get_size(AV_PIX_FMT_RGB24,Videowidth,Videoheight);
// qDebug()<<"size is "<<size;
buffer = (unsigned char*)av_malloc(av_image_get_buffer_size(AV_PIX_FMT_RGB24,Videowidth,Videoheight,1));
av_image_fill_arrays(pFrameRGB->data,pFrameRGB->linesize,buffer,AV_PIX_FMT_RGB24,Videowidth,Videoheight,1);
// buffer = (unsigned char*)av_malloc(size*sizeof(unsigned char));
// avpicture_fill((AVPicture*)pFrameRGB,buffer,AV_PIX_FMT_RGB24,Videowidth,Videoheight);
//avpicture_alloc(pPicture,AV_PIX_FMT_RGB24,Videowidth,Videoheight);
av_dump_format(pFormatCtx,0,filepath,0);
pSwsCtx = sws_getContext(Videowidth,Videoheight,AV_PIX_FMT_YUV420P,Videowidth,Videoheight,AV_PIX_FMT_RGB24,SWS_BICUBIC,NULL,NULL,NULL);
}
void QFFmpeg::play()
{
pPacket=(AVPacket *)av_malloc(sizeof(AVPacket));
if(av_read_frame(pFormatCtx,pPacket)>=0)
{
if(pPacket->stream_index == Videostreamindex)
{
ret=avcodec_decode_video2(pCodecCtx,pFrame,&gotpicutre,pPacket);
if(ret < 0)
{
qDebug()<<"decode ture";
}
qDebug()<<"gotpiture is"<<gotpicutre;
if(gotpicutre)
{
mutex->lock();
sws_scale(pSwsCtx,(const unsigned char* const*)pFrame->data,pFrame->linesize,0,pCodecCtx->height,
pFrameRGB->data,pFrameRGB->linesize);
QImage image((unsigned char*)pFrameRGB->data[0],Videowidth,Videoheight,QImage::Format_RGB888);
emit goimage(image);
mutex->unlock();
}
}
av_free_packet(pPacket);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于qt5.3的简单的ffmpeg视频播放
共139个文件
h:106个
a:8个
def:8个
3星 · 超过75%的资源 需积分: 10 32 下载量 53 浏览量
2016-05-17
17:30:18
上传
评论
收藏 12.36MB ZIP 举报
温馨提示
基于win版本的QT5.3和外置的ffpeg的库实现了简单的播放各种常见格式的视频文件的功能,但是下载后注意,我的视频文件没有上传,各位要自己选择一个视频文件,直接放在D盘下面就能找到了。
资源推荐
资源详情
资源评论
收起资源包目录
基于qt5.3的简单的ffmpeg视频播放 (139个子文件)
libavutil.dll.a 304KB
libavcodec.dll.a 151KB
libavformat.dll.a 112KB
libavfilter.dll.a 42KB
libswscale.dll.a 22KB
libswresample.dll.a 15KB
libavdevice.dll.a 13KB
libpostproc.dll.a 7KB
test.avi 1.14MB
qffmpeg.cpp 4KB
mainwindow.cpp 1KB
main.cpp 183B
avutil-55.def 11KB
avcodec-57.def 6KB
avformat-57.def 4KB
avfilter-6.def 2KB
swscale-4.def 756B
avdevice-57.def 554B
swresample-2.def 457B
postproc-54.def 233B
avcodec.h 200KB
avformat.h 108KB
avfilter.h 40KB
opt.h 35KB
pixfmt.h 30KB
avio.h 27KB
frame.h 24KB
swresample.h 20KB
intreadwrite.h 18KB
avdevice.h 18KB
common.h 15KB
mem.h 15KB
hwcontext.h 14KB
pixdesc.h 14KB
avstring.h 14KB
swscale.h 12KB
log.h 10KB
buffer.h 10KB
samplefmt.h 10KB
channel_layout.h 9KB
avutil.h 9KB
imgutils.h 8KB
dict.h 8KB
vdpau.h 8KB
bprint.h 8KB
parseutils.h 7KB
version.h 7KB
buffersrc.h 6KB
xvmc.h 6KB
vda.h 6KB
audio_fifo.h 6KB
fifo.h 6KB
error.h 5KB
tree.h 5KB
timecode.h 5KB
buffersink.h 5KB
eval.h 5KB
mathematics.h 5KB
cpu.h 5KB
attributes.h 4KB
vaapi.h 4KB
rational.h 4KB
dirac.h 4KB
videotoolbox.h 4KB
version.h 4KB
qsv.h 4KB
dv_profile.h 4KB
stereo3d.h 4KB
threadmessage.h 4KB
hash.h 4KB
downmix_info.h 3KB
display.h 3KB
avfft.h 3KB
version.h 3KB
postprocess.h 3KB
hmac.h 3KB
crc.h 3KB
bswap.h 3KB
d3d11va.h 3KB
xtea.h 3KB
mastering_display_metadata.h 3KB
timestamp.h 3KB
version.h 3KB
avdct.h 3KB
file.h 3KB
cast5.h 3KB
hwcontext_vaapi.h 2KB
blowfish.h 2KB
dxva2.h 2KB
vorbis_parser.h 2KB
des.h 2KB
base64.h 2KB
twofish.h 2KB
camellia.h 2KB
aes_ctr.h 2KB
avassert.h 2KB
pixelutils.h 2KB
lzo.h 2KB
tea.h 2KB
sha512.h 2KB
共 139 条
- 1
- 2
资源评论
- rootlife2016-06-11一般般, 还好吧.
- 水军总督2018-12-05并不能用。。。什么鬼
- c30609110302018-04-05下载后,报错引用的库找不到,最后自己改为绝对路径,改后可以编译过,但是运行不起来。好像是哪里越界了
sam8261360
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Java的银行客户及用户管理系统设计源码
- 免费Ollama 官方大模型服务器安装程序
- 【个人博客搭建】(5)Sqlsugar实体创建数据库数据 生成时打印的SQL语句,也可用他创建
- 基于Scrapy和Redis的分布式爬虫设计源码
- 纯HTML外贸公司通用企业html网站模板源码
- 基于Flask轻量级Web框架的Aliexpress项目设计源码
- Java毕设之ssm-079-mysql-ssm软件bug管理系统-.rar
- 基于Vue和TypeScript的移动端潮玩商城设计源码
- Java毕设之ssm-067-mysql-网约车用户服务平台-.rar
- 基于Kotlin和Java的安卓计算器应用设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功