亲大神帮忙分析一下,程序为什么在打开编码器的时候失败了?
错误信息:
[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);
|