title: Decode h264 stream with ffmpeg introduces a delay, how to avoid?
body: <p>I'm working on some code that encodes a video feed, sends it over UDP to a client that then decodes the stream. It working fine using a x264 encoder, my only problem is that when i call <code>avcodec_decode_video2</code> on the incomming frame, the decoder introduces a delay as if it has an internal buffer. How can i avoid this? What is controlling this behavior? Is it the encoder that should be changed, or is it missing settings in the decoder context? Currently i just create the decoder context with defaults <code>avcodec_get_context_defaults3</code>. </p>
  
  <p>The encoder has the following parameters:</p>
  
  <pre><code>x264_param_t param;
  x264_param_default_preset(&amp;param, preset.c_str(), "zerolatency");
  param.i_frame_reference = 1;
  
  param.i_threads = 1;
  param.b_sliced_threads = 5;
  param.i_slice_max_size = 8192;
  param.i_width = width;
  param.i_height = height;
  param.i_fps_num = 30;
  param.i_fps_den = 1;
  param.i_sync_lookahead = 0;
  
  param.i_bframe = 0;
  // Intra refres:
  param.i_keyint_max = 30;
  param.b_intra_refresh = 1;
  //Rate control:
  param.rc.i_rc_method = X264_RC_CRF;
  param.rc.i_lookahead = 0;
  param.rc.i_bitrate = bitrate;
  param.rc.i_vbv_max_bitrate = bitrate;
  param.rc.i_vbv_buffer_size = bitrate/30;
  
  //For streaming:
  param.b_repeat_headers = 1;
  param.b_annexb = 1;
  </code></pre>