大家好,又见面了,我是你们的朋友全栈君。
avcodec_find_decoder(CODEC_ID_H264)
h264_decoder,
即
函数进行解码
avctx为
AVCodecContext类型,codec为AVCodec类型,decode为一个函数指针,
decode_frame
extern AVCodec ff_h264_decoder;//在h264.c中定义
AVCodec *codec = &ff_h264_decoder;//
AVCodecContext *avctx= NULL;//AVCodecContext在AVCodec.c中定义
AVFrame *picture;
DSPContext dsp;
H264Context *h; //h264.h中定义
MpegEncContext *s //Mpegvideo.h中定义
void decode_init()
{
avcodec_init();
avctx= avcodec_alloc_context();
picture= avcodec_alloc_frame();
if(codec->capabilities&CODEC_CAP_TRUNCATED)
c->flags|= CODEC_FLAG_TRUNCATED;
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, “could not open codec\n”);
exit(1);
}
//H264Context *h = c->priv_data; //这两行为ff_h264_decode_init的头两行
//MpegEncContext *s = &h->s;
s->dsp.idct_permutation_type =1;
ff_h264_decode_init(&avctx)
dsputil_init(&dsp, avctx);
}
void decode(unsigned char* buf,int buf_size)
{
int size=buf_size;
unsigned char* inbuf_ptr=buf;
//tips for buf: set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams)
//#define INBUF_SIZE 4096
//#define FF_INPUT_BUFFER_PADDING_SIZE 16
//uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
//memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
//size = fread(inbuf, 1, INBUF_SIZE, fin);
//inbuf_ptr = inbuf;
int len=0,got_picture=0;
while (size> 0)
{
len = decode_frame(avctx, picture, &got_picture,inbuf_ptr, size);
if (len < 0)
{
fprintf(stderr, “Error while decoding frame %d\n”, frame);
exit(1);
}
if (got_picture)
{
printf(“saving frame %3d\n”, frame);
fflush(stdout);
//data
frame++;
}
size -= len;
inbuf_ptr += len;
}
len = avcodec_decode_video(c, picture, &got_picture,
inbuf_ptr, 0);
if (got_picture)
{
//
}
}
void decode_end()
{
avcodec_close(c);
av_free(c);
av_free(picture);
//int ff_h264_decode_end(avctx)
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/148844.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...