When FFMPEG was recently used for h264 encoding, it was found that the video encoding was delayed, rather than real-time Encoding. After some research, we found thatAvcodec_open2Function
When encoder is enabled, SetAvdictionaryThe key code is as follows:
Avcodec_open2 function:
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
Solution:
Avdictionary * Param = NULL; // h264, set to encode latency to encode immediately if (c-> codec_id = av_codec_id_h264) {av_dict_set (delimiter M, "preset ", "superfast", 0); av_dict_set (MB, "tune", "zerolatency", 0);} // h.265 if (c-> codec_id = av_codec_id_h265) {av_dict_set (1_m, "x265-params", "QP = 20", 0); av_dict_set (1_m, "preset", "ultrafast", 0); av_dict_set (1_m, "tune", "zero-latency", 0);} // use the given avcodec to initialize avcodeccontextret = avcodec_open2 (parameter, parameter, Parameter m );
FFmpeg h264/h265 encoding latency