H264\u Nvenc的最佳设置以最小化延迟?(FFMPEG)

H264\u Nvenc的最佳设置以最小化延迟?(FFMPEG),ffmpeg,h.264,libavcodec,libav,nvenc,Ffmpeg,H.264,Libavcodec,Libav,Nvenc,我目前正在使用Libavcodec对使用H.264的视频帧进行编码。因为我在编码后对这些视频帧进行流式传输,所以最小化延迟对我来说至关重要。我当前的设置是: avcodec_register_all(); codec = avcodec_find_encoder(AV_CODEC_ID_H264); // allocate and set ffmpeg context context = avcodec_alloc_context3(encoder->codec); context-&g

我目前正在使用Libavcodec对使用H.264的视频帧进行编码。因为我在编码后对这些视频帧进行流式传输,所以最小化延迟对我来说至关重要。我当前的设置是:

avcodec_register_all();
codec = avcodec_find_encoder(AV_CODEC_ID_H264);

// allocate and set ffmpeg context
context = avcodec_alloc_context3(encoder->codec);
context->bit_rate = bitrate;
context->width = out_width;
context->height = out_height;
context->time_base.num = 1;
context->time_base.den = 30;
context->gop_size = 1; // send SPS/PPS headers every packet
context->max_b_frames = 0;
context->pix_fmt = AV_PIX_FMT_YUV420P;

// set encoder parameters to max performance
av_opt_set(context->priv_data, "preset", "ultrafast", 0);
av_opt_set(context->priv_data, "tune", "zerolatency", 0);

// open capture encoder
avcodec_open2(context, codec, NULL);
这些设置工作正常,但我正在尝试切换到基于硬件的编码,以减轻CPU的工作负载。我目前有一个NVIDIA GPU,因此我尝试在
h264\u nvenc
中使用以下设置:

codec = avcodec_find_encoder_by_name("h264_nvenc");

// allocate and set ffmpeg context
context = avcodec_alloc_context3(encoder->codec);
context->dct_algo = FF_DCT_FASTINT;
context->bit_rate = bitrate;
context->width = out_width;
context->height = out_height;
context->time_base.num = 1;
context->time_base.den = 30;
context->gop_size = 1; // send SPS/PPS headers every packet
context->max_b_frames = 0;
context->pix_fmt = AV_PIX_FMT_YUV420P;

// set encoder parameters to max performancen
av_opt_set(context->priv_data, "preset", "llhq", 0);
av_opt_set(context->priv_data, "tune", "zerolatency", 0);

问题是,我注意到
h264\u invenc
的延迟明显大于
AV\u CODEC\u ID\u h264
(基于软件的版本)的延迟。我认为我的
h264\n的设置或设置肯定是错误的,因为基于GPU的编码应该比基于软件的编码快。谁能给我指一下正确的方向吗?非常感谢

context->gop_size=1
-->这会将每个帧编码为帧内编码。可能,增加的编码和数据I/O都会增加延迟。
context->gop_size=1
-->这会将每个帧编码为帧内编码。可能,增加的编码和数据I/O都增加了延迟。