how to improve picture quality using x264enc?

I feed 0ne stream to deepstream pipeline and add 2 sinks, one is filesink(local disk) and another is udpsink(rtsp stream).

The result is the recorded video file picture quality is better than rtsp stream(I used VLC to get the rtsp stream), how should I change the property for the x264enc element to improve the picture quality when watching it using rtsp?

below is how to create encode file bin(from deepstream_sink_bin.c):

[...]

  // set property for encoder, just one property
  g_object_set (G_OBJECT (bin->encoder), "bitrate", config->bitrate, NULL);

  [...]
  // link elements
  NVGSTDS_LINK_ELEMENT (bin->queue, bin->transform);
  NVGSTDS_LINK_ELEMENT (bin->transform, bin->cap_filter);
  NVGSTDS_LINK_ELEMENT (bin->cap_filter, sw_conv);
  NVGSTDS_LINK_ELEMENT (sw_conv, bin->encoder);
  NVGSTDS_LINK_ELEMENT (bin->encoder, bin->mux);
  NVGSTDS_LINK_ELEMENT (bin->mux, bin->sink);

below is how to create udp sink bin(from deepstream_sink_bin.c):

[...]

  // set property for encoder, many properties
  g_object_set (G_OBJECT (bin->encoder), "bitrate", config->bitrate, NULL);
  g_object_set (G_OBJECT (bin->encoder), "speed-preset", 3, NULL);
  g_object_set (G_OBJECT (bin->encoder), "intra-refresh", TRUE, NULL);
  g_object_set (G_OBJECT (bin->encoder), "ref", 1, NULL);
  g_object_set (G_OBJECT (bin->encoder), "key-int-max", 1, NULL);

  [...]

  // link elements
  NVGSTDS_LINK_ELEMENT (bin->queue, bin->transform);
  NVGSTDS_LINK_ELEMENT (bin->transform, bin->cap_filter);

  NVGSTDS_LINK_ELEMENT (bin->cap_filter, sw_conv);
  NVGSTDS_LINK_ELEMENT (sw_conv, bin->encoder);

  NVGSTDS_LINK_ELEMENT (bin->encoder, bin->enc_caps_filter);
  NVGSTDS_LINK_ELEMENT (bin->enc_caps_filter, bin->rtph264pay);
  NVGSTDS_LINK_ELEMENT (bin->rtph264pay, bin->sink);

I know I should change x264enc’s properties but I am not sure how to do that, not familiar with encode/decode with it. anybody know it? thanks.

I remove these code:

g_object_set (G_OBJECT (bin->encoder), "speed-preset", 3, NULL);
  g_object_set (G_OBJECT (bin->encoder), "intra-refresh", TRUE, NULL);
  g_object_set (G_OBJECT (bin->encoder), "ref", 1, NULL);
  g_object_set (G_OBJECT (bin->encoder), "key-int-max", 1, NULL);

now I can get high quality picture from rtsp stream.