我是靠谱客的博主 感性星月,最近开发中收集的这篇文章主要介绍linux内核 h264,linux下,使用ffmpeg解码h264,出错,如何解决?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

当前位置:我的异常网» Linux/Unix » linux下,使用ffmpeg解码h264,出错,如何解决?

linux下,使用ffmpeg解码h264,出错,如何解决?

www.myexceptions.net  网友分享于:2013-10-22  浏览:244次

linux下,使用ffmpeg解码h264,出错,怎么解决???

#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;i

fwrite(buf + i * wrap,1,xsize,f);

fclose(f);

}

static int decode_write_frame(const char *outfilename, AVCodecContext *avctx,

AVFrame *frame, int *frame_count, AVPacket *pkt, int last)

{

int len, got_frame;

char buf[1024];

printf("as;dkfjaskdn");

len = avcodec_decode_video2(avctx, frame, &got_frame, pkt);

printf("the len is %dn",len);

if (len 

fprintf(stderr, "Error while decoding frame %dn", *frame_count);

return len;

}

if (got_frame) {

printf("Saving %sframe %3dn", last ? "last " : "", *frame_count);

fflush(stdout);

/* the picture is allocated by the decoder, no need to free it */

//snprintf(buf, sizeof(buf), outfilename, *frame_count);

pgm_save(frame->data[0], frame->linesize[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)

文章评论

最后

以上就是感性星月为你收集整理的linux内核 h264,linux下,使用ffmpeg解码h264,出错,如何解决?的全部内容,希望文章能够帮你解决linux内核 h264,linux下,使用ffmpeg解码h264,出错,如何解决?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(128)

评论列表共有 0 条评论

立即
投稿
返回
顶部