简体   繁体   English

流x264时如何减少延迟

[英]How to reduce latency when streaming x264

I would like to produce a zerolatency live video stream and play it in VLC player with as little latency as possible. 我想产生一个zerolatency实时视频流,并在VLC播放器中以尽可能小的延迟播放它。

This are the settings I currently use: 这是我当前使用的设置:

x264_param_default_preset( &m_Params, "veryfast", "zerolatency" );

m_Params.i_threads              =   2;
m_Params.b_sliced_threads       =   true;
m_Params.i_width                =   m_SourceWidth;
m_Params.i_height               =   m_SourceHeight;

m_Params.b_intra_refresh        =   1;

m_Params.b_vfr_input            =   true;
m_Params.i_timebase_num         =   1;
m_Params.i_timebase_den         =   1000;

m_Params.i_fps_num              =   1;
m_Params.i_fps_den              =   60;

m_Params.rc.i_vbv_max_bitrate   =   512;
m_Params.rc.i_vbv_buffer_size   =   256;
m_Params.rc.f_vbv_buffer_init   =   1.1f;

m_Params.rc.i_rc_method         =   X264_RC_CRF;
m_Params.rc.f_rf_constant       =   24;
m_Params.rc.f_rf_constant_max   =   35;

m_Params.b_annexb               =   0;
m_Params.b_repeat_headers       =   0;
m_Params.b_aud                  =   0;

x264_param_apply_profile( &m_Params, "high" );

Using those settings, I have the following issues: 使用这些设置,我遇到以下问题:

  • VLC shows lots of missing frames (see screenshot, "verloren"). VLC显示很多丢失的帧(请参见屏幕截图“ verloren”)。 I am not sure if this is an issue. 我不确定这是否是一个问题。
  • If I set a value <200ms for the network stream delay in VLC, VLC renders a few frames and than stops to decode/render frames. 如果我为VLC中的网络流延迟设置<200ms的值,则VLC会渲染一些帧,然后停止解码/渲染帧。
  • If I set a value >= 200ms for the network stream delay in VLC, everything looks good so far but the latency is, obviously, 200ms, which is too high. 如果我为VLC中的网络流延迟设置一个值> = 200ms,那么到目前为止一切都看起来不错,但是延迟显然是200ms,这太高了。

Question: Which settings (x264lib and VLC) should I use in order to encode and stream with as little latency as possible? 问题:我应该使用哪些设置(x264lib和VLC)以尽可能少的延迟进行编码和流传输?

在此处输入图片说明

On your x264 settings: many are redundant ie already contained in "zerolatency". 在您的x264设置上:许多是多余的,即已经包含在“ zerolatency”中。 However, as best as I can tell, your encoding latency is nevertheless zero frames, ie you put one frame in and you immediately (as soon as your CPU has finished encoding it, anyway) get one frame out. 但是,据我所知,您的编码延迟仍然是零帧,也就是说,您放入一帧,然后立即(无论如何,一旦CPU完成编码)就得到一帧。 It never waits for a newer frame in order to give an encoded older frame (the way it would with lookahead, for example). 它从不等待新的帧来提供编码的旧帧(例如,采用超前的方式)。

On why vlc pauses unless you give it a large network delay: The problem is that your combination of rate control and vbv settings when encoding is not ideal. 关于为什么vlc会暂停,除非您给它带来较大的网络延迟:问题是编码时速率控制和vbv设置的组合不理想。 What you want to do for low latency encode is to use CBR, and set the VBV buffer to the size of one frame, exactly. 对于低延迟编码,您要做的是使用CBR,并将VBV缓冲区的大小精确设置为一帧。 This enables a special VBV calculation, if you look in the x264 source. 如果您查看x264源代码,这将启用特殊的VBV计算。

You may also try not setting anything timing related whatsoever (no fps, no vbv) and use CRF with zerolatency. 您也可以尝试不设置任何与计时相关的东西(无fps,无vbv),并使用零延迟的CRF。 The results would depend on what container the video is packaged in for streaming. 结果将取决于视频打包在哪个容器中以进行流传输。

Read this for more info: http://x264dev.multimedia.cx/archives/249 请阅读以获取更多信息: http : //x264dev.multimedia.cx/archives/249

If you want to have the fastest possible encoding, then delete everything after 如果您想获得最快的编码,请在之后删除所有内容

x264_param_default_preset( &m_Params, "veryfast", "zerolatency" );

and change veryfast to ultrafast. 并迅速变为超快。 The rest is because of network delay + decoding. 其余的是由于网络延迟+解码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM