ffmpeg4.3
AVDictionary* options = NULL; av_dict_set(&options, "fflags", "nobuffer", 0); int re = avformat_open_input(&ic, URL, NULL, &options);
经测试发现,延时2s,使用nobuffer设置后,延时只有17帧,视屏为1080i50数据。
另外,如果是网络URL,在使用avformat_open_input打开输入流之后,那么此时就建立了连接,记录此时刻为A,那么当av_read_frame读取数据时,第一帧读到的数据是A时刻的数据。因此在两个函数之间应尽量减少执行的程序,实测如果中间有10s的程序要执行,那么视频延时在10s以上。
实测用一下方式设置解码器的参数,并不能很有效的减少延时,1080i50在设置之前延时17帧,多次测试设置之后16帧左右,每帧间隔40ms。
av_opt_set(decodec_ctx_v->priv_data, "preset", "ultrafast", 0);//superfast av_opt_set(decodec_ctx_v->priv_data, "tune", "zerolatency", 0);