Y_h_y_
Y_h_y_
采纳率0%
2021-02-26 11:32

FFMPEG 硬编码问题

我直接从FFMPEG官网下载的sdk,我的显卡是NVIDIA.

硬编码代码如下:

int InitEncoderCodec( int iWidth, int iHeight)
{
	AVCodec *  pH264Codec = avcodec_find_encoder_by_name("h264_nvenc");
	if(NULL == pH264Codec)
	{
		printf("%s", "avcodec_find_encoder failed");
		return  -1;
	}
	outPutEncContext = avcodec_alloc_context3(pH264Codec);
	outPutEncContext->gop_size = 30;
	//outPutEncContext->framerate = 30;
	outPutEncContext->has_b_frames = 0;
	outPutEncContext->max_b_frames = 0;
	//outPutEncContext = avcodec_alloc_context3(pH264Codec);
	outPutEncContext->codec_id = pH264Codec->id;
	outPutEncContext->time_base.num =1;
	outPutEncContext->time_base.den = 25;
	outPutEncContext->pix_fmt            = *pH264Codec->pix_fmts;
	outPutEncContext->width              =  iWidth;
	outPutEncContext->height             = iHeight;
 
	AVDictionary *options = NULL;
	outPutEncContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
	
	av_opt_set(outPutEncContext->priv_data,"async_depth","1",0);
	av_opt_set(outPutEncContext->priv_data,"max_dec_frame_buffering","1",0);
	av_opt_set(outPutEncContext->priv_data,"look_ahead","0",0);
 
	int ret = avcodec_open2(outPutEncContext, pH264Codec, &options);
	AVQSVContext *qsv = (AVQSVContext *)outPutEncContext->hwaccel_context;
	if (ret < 0)
	{
		printf("%s", "open codec failed");
		return  ret;
	}
	return 1;
}

但是在最后一步出现了问题

int ret = avcodec_open2(outPutEncContext, pH264Codec, &options);

ret的返回值一直是-40

不知道是不是我从官网上下载的dll没有载入相关模块

 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • qq_40344524 书山客 2月前

    你看一下注册的编码器有问题没,我记得之前我做ffmpag软编的时候好像不是这么注册的,主要是那个编码器名字对吗?

    点赞 评论 复制链接分享
  • Y_h_y_ Y_h_y_ 2月前

    在程序运行到如下代码段时,返回值一直是-40。

    int ret = avcodec_open2(outPutEncContext, pH264Codec, &options);

    请各位大佬帮帮

    点赞 评论 复制链接分享