当前位置: 技术问答>linux和unix
linux下,使用ffmpeg解码h264,出错,怎么解决???
来源: 互联网 发布时间:2017-04-28
本文导语: #include #include #include #include #include #include #include #include #define INBUF_SIZE 4096 /* * Video decoding example */ static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, cha...
#include
#include
#include
#include
#include
#include
#include
#include
#define INBUF_SIZE 4096
/*
* Video decoding example
*/
static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,
char *filename)
{
FILE *f;
int i;
f=fopen(filename,"ab+");
// fprintf(f,"P5n%d %dn%dn",xsize,ysize,255);
for(i=0;ilinesize[0],
avctx->width, avctx->height, outfilename);
pgm_save(frame->data[1], frame->linesize[1],
avctx->width/2, avctx->height/2, outfilename);
pgm_save(frame->data[2], frame->linesize[2],
avctx->width/2, avctx->height/2, outfilename);
(*frame_count)++;
}
if (pkt->data) {
pkt->size -= len;
pkt->data += len;
}
return 0;
}
static void video_decode_example(const char *outfilename, const char *filename)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int frame_count;
FILE *f;
AVFrame *frame;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
av_init_packet(&avpkt);
/* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
printf("Decode video file %s to %sn", filename, outfilename);
/* find the mpeg1 video decoder */
codec = avcodec_find_decoder(AV_CODEC_ID_H264);
if (!codec) {
fprintf(stderr, "Codec not foundn");
exit(1);
}
c = avcodec_alloc_context3(codec);
if (!c) {
fprintf(stderr, "Could not allocate video codec contextn");
exit(1);
}
if(codec->capabilities&CODEC_CAP_TRUNCATED)
c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
/* For some codecs, such as msmpeg4 and mpeg4, width and height
MUST be initialized there because this information is not
available in the bitstream. */
/* open it */
if (avcodec_open2(c, codec, NULL) 0)
if (decode_write_frame(outfilename, c, frame, &frame_count, &avpkt, 0)
#include
#include
#include
#include
#include
#include
#include
#define INBUF_SIZE 4096
/*
* Video decoding example
*/
static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,
char *filename)
{
FILE *f;
int i;
f=fopen(filename,"ab+");
// fprintf(f,"P5n%d %dn%dn",xsize,ysize,255);
for(i=0;ilinesize[0],
avctx->width, avctx->height, outfilename);
pgm_save(frame->data[1], frame->linesize[1],
avctx->width/2, avctx->height/2, outfilename);
pgm_save(frame->data[2], frame->linesize[2],
avctx->width/2, avctx->height/2, outfilename);
(*frame_count)++;
}
if (pkt->data) {
pkt->size -= len;
pkt->data += len;
}
return 0;
}
static void video_decode_example(const char *outfilename, const char *filename)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int frame_count;
FILE *f;
AVFrame *frame;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
av_init_packet(&avpkt);
/* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
printf("Decode video file %s to %sn", filename, outfilename);
/* find the mpeg1 video decoder */
codec = avcodec_find_decoder(AV_CODEC_ID_H264);
if (!codec) {
fprintf(stderr, "Codec not foundn");
exit(1);
}
c = avcodec_alloc_context3(codec);
if (!c) {
fprintf(stderr, "Could not allocate video codec contextn");
exit(1);
}
if(codec->capabilities&CODEC_CAP_TRUNCATED)
c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
/* For some codecs, such as msmpeg4 and mpeg4, width and height
MUST be initialized there because this information is not
available in the bitstream. */
/* open it */
if (avcodec_open2(c, codec, NULL) 0)
if (decode_write_frame(outfilename, c, frame, &frame_count, &avpkt, 0)