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

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没有载入相关模块

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