ffmpeg学习3 最简单的视频解码

本文介绍了使用FFmpeg进行最简单视频解码的主要步骤,包括寻找解码器、初始化解析器、打开解码器、解析数据包、发送数据包以及接收帧。详细代码展示解码过程。
摘要由CSDN通过智能技术生成

参考ffmpeg 4.2中的 examples

主要步骤:

1. avcodec_find_decoder(AV_CODEC_ID_MPEG1VIDEO);

2. av_parser_init(codec->id);

3. avcodec_open2(c, codec, NULL)

4. av_parser_parse2(parser, c, &pkt->data, &pkt->size,

                                   data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);

5. avcodec_send_packet(dec_ctx, pkt);

6. avcodec_receive_frame(dec_ctx, frame);

 

代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <libavcodec/avcodec.h>
extern "C"
{
#include <libavcodec/avcodec.h>
}


#define INBUF_SIZE 4096

static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,
                     char *filename)
{
    FILE *f;
    int i;

    f = fopen(filename,"w");
    fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);
    for (i = 0; i &
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值