ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 20840|回复: 2

[源码] avcodec_open2编码器打开失败???

[复制链接]
发表于 2013-12-21 21:47:35 | 显示全部楼层 |阅读模式


亲大神帮忙分析一下,程序为什么在打开编码器的时候失败了?
错误信息:
[NULL @ 0xa614020] No codec provided to avcodec_open2()
Could not open video codec: Invalid argument



[C] 纯文本查看 复制代码
   int ret;
	AVCodec *audio_codec, *video_codec;
	AVCodecContext *c;
	AVFrame *frame;
	AVPacket pkt;
	int got_output;

    /* Initialize libavcodec, and register all codecs and formats. */
    av_register_all();
	avcodec_register_all();
	//avdevice_register_all();

	video_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
	c = avcodec_alloc_context3(video_codec);

	c->width = 352;
	c->height = 288;
	c->bit_rate = 400000; // 400K
	c->time_base = (AVRational){1,25};
	c->pix_fmt = AV_PIX_FMT_YUV420P;

/*
	c->sample_fmt = AV_SAMPLE_FMT_S16;
	c->sample_rate = 44100;
	c->channels = 2;
	c->channel_layout = AV_CH_LAYOUT_STEREO;
	c->bit_rate = 64000;
*/

	av_opt_set(c->priv_data, "preset","slow",0);
	av_opt_set(c->priv_data, "profile","main",0);
	av_opt_set(c->priv_data, "level","2.0",0);

	/* open the codec */
	ret = avcodec_open2(c, video_codec, NULL);
    if (ret < 0) {
        fprintf(stderr, "Could not open video codec: %s\n", av_err2str(ret));
        exit(1);
    }

	/* allocate and init a re-usable frame */
	frame = avcodec_alloc_frame();
    if (!frame) {
        fprintf(stderr, "Could not allocate video frame\n");
        exit(1);
    }

    /* Allocate the encoded raw picture. */
    ret = avpicture_alloc(&dst_picture, c->pix_fmt, c->width, c->height);
    if (ret < 0) {
        fprintf(stderr, "Could not allocate picture: %s\n", av_err2str(ret));
        exit(1);
    }
    /* copy data and linesize picture pointers to frame */
    *((AVPicture *)frame) = dst_picture;

	frame->format = c->pix_fmt;
	frame->width = c->width;
	frame->height = c->height;

	//av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);

	av_init_packet(&pkt);


回复

使用道具 举报

发表于 2013-12-21 21:50:06 | 显示全部楼层
ffmpeg编译的时候包含了libx264了吗
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-22 16:15:10 | 显示全部楼层
T-Bagwell 发表于 2013-12-21 21:50
ffmpeg编译的时候包含了libx264了吗

没有,谢谢提醒
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-5-9 01:42 , Processed in 0.066361 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表