ffmpeg如何将任意一种格式数据都转化成 vp9格式啊?

xinyao63 2014-03-19 11:25:44
下面是我根据网上的例子,改的程序,总报错,请高手给看看,这样写对不对?

void video_encode_example(const char *filename, AVFrame *picture, int width, int height)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int i, out_size, size, outbuf_size;
FILE *f;
uint8_t *outbuf, *picture_buf;

printf("Video encoding\n");
av_register_all();
codec = avcodec_find_encoder(AVCodecID::AV_CODEC_ID_VP9);
avcodec_register(codec);//这个不知道该放在哪儿?
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
c= avcodec_alloc_context3(codec);
//picture= avcodec_alloc_frame();
/* put sample parameters */
c->bit_rate = 400000;//设置采样参数,即比特率。
/* resolution must be a multiple of two */
c->width = width;//设置分辨率,必须是2的倍数。
c->height = height;//设置分辨率,必须是2的倍数。
/* frames per second */
c->time_base.num = 1;
c->time_base.den = 25;
c->gop_size = 10; /* emit one intra frame every ten frames *///该值表示每10帧会插入一个I帧(intra frame)。
c->max_b_frames=1;
c->pix_fmt = PIX_FMT_YUV420P;

/* open it */
AVDictionary *pAVDictionary=NULL;//
if (avcodec_open2(c, codec,&pAVDictionary) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}

/* the codec gives us the frame size, in samples */
fopen_s(&f,filename, "ab");//接着是打开文件,f = fopen( filename, “wb” );
if (!f) {
fprintf(stderr, "could not open %s\n", filename);
exit(1);
}
/* alloc image and output buffer */
outbuf_size = 1000000;//
outbuf = (uint8_t *)malloc(outbuf_size);
size = c->width * c->height;
picture_buf = (uint8_t *)malloc((size * 3) / 2); /* size for YUV 420 */
/* encode the image */
out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture); // 这儿不对
fwrite(outbuf, 1, out_size, f);
/* get the delayed frames */
i=0;
for(; out_size; i++) {
fflush(stdout);
printf("Ln:%d ;;out_size = %d \n",__LINE__,out_size);

out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
printf("write frame %3d (size=%5d)\n", i, out_size);
fwrite(outbuf, 1, out_size, f);
}
printf("Ln:%d \n",__LINE__);
/* add sequence end code to have a real mpeg file */
fclose(f);
free(picture_buf);
free(outbuf);

avcodec_close(c);
av_free(c);
av_free(picture);
printf("\n");
}
...全文
480 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,643

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧