参考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 &