ffmpeg播放视频

获取RGB32像素数据:

像素数据后的格式:AV_PIX_FMT_RGB32

	//6.读取每帧画面
    //AVPacket 保存每一帧的画面
    AVPacket *pkt=nullptr;
    //开空间
    pkt=(AVPacket*)malloc(sizeof(AVPacket));
    //一帧大小
    int OnePicsize=av_codec_Context->width*av_codec_Context->height;
    //开空间
    av_new_packet(pkt,OnePicsize);
    //保存的的像素数据
    AVFrame *picYUV=nullptr;
    picYUV=av_frame_alloc();
    picYUV->width=av_codec_Context->width;
    picYUV->height=av_codec_Context->height;
    picYUV->format=av_codec_Context->pix_fmt;//转码格式和解码格式要一样
    //转码后的像素数据
    AVFrame *pic=nullptr;
    pic=av_frame_alloc();
    pic->width=av_codec_Context->width;
    pic->height=av_codec_Context->height;
    pic->format=av_codec_Context->pix_fmt;//转码格式和解码格式要一样

    //一帧码流数据解码后的像素数据多大?
    int numByte=avpicture_get_size(AV_PIX_FMT_RGB32,av_codec_Context->width,av_codec_Context->height);
    //给AVFrame中的data数据(解码后的图像像素数据)开空间
    uint8_t *buffer=(uint8_t *)malloc(sizeof(uint8_t)*numByte);
    //填充像素数据
    //avpicture_fill((AVPicture*)pic,buffer,AV_PIX_FMT_RGB32,av_codec_Context->width,av_codec_Context->height);
    avpicture_fill((AVPicture*)picYUV,buffer,AV_PIX_FMT_RGB32,av_codec_Context->width,av_codec_Context->height);
    //压缩时图像会发生变化,解码时得恢复
    //解码的转换规则 具体的转换规则SWS_BICUBIC
    SwsContext *sws_context=nullptr;
    sws_context=sws_getContext(av_codec_Context->width,av_codec_Context->height,av_codec_Context->pix_fmt,
                               av_codec_Context->width,av_codec_Context->height,AV_PIX_FMT_RGB32,SWS_B
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值