Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'encoderBitrate configured in MediaElement.conf.ini ignored with x264` encoder #94

Open
3 tasks done
fab-sgnct opened this issue Jan 3, 2025 · 2 comments
Open
3 tasks done

Comments

@fab-sgnct
Copy link

Prerequisites

Issue description

When using x264 encoder we have the following logs:

0:02:10.861619002    17 0x7f61541de000 DEBUG             enctreebin kmsenctreebin.c:146:configure_encoder: Configure encoder: <x264enc0>
0:02:10.861714154    17 0x7f61541de000 DEBUG             enctreebin kmsenctreebin.c:494:kms_enc_tree_bin_configure:<kmsenctreebin1> Encoder plugin found: <x264enc0> for caps: video/x-h264, stream-format=(string)avc, alignment=(string)au, width=(int)[ 16, 2147483647 ], height=(int)[ 16, 2147483647 ]
0:02:10.861723736    17 0x7f61541de000 DEBUG             enctreebin kmsenctreebin.c:311:kms_enc_tree_bin_get_bitrate:<kmsenctreebin1> Bitrate = Current value: 300000
0:02:10.861745774    17 0x7f61541de000 ERROR                   glib GLib-GObject:0:: value "0" of type 'guint' is invalid or out of range for property 'bitrate' of type 'guint'
0:02:10.861754748    17 0x7f61541de000 DEBUG             enctreebin kmsenctreebin.c:370:kms_enc_tree_bin_set_target_bitrate:<x264enc0> "bitrate" set: 300

The problem is around the error log, see context below.

Context

The consequence of the above is that the bitrate setting is ignored and some max bitrate of 2Mbps is used.
Looking at the code of kurento 7.1.0 (which is the version we use) we can see this piece of code and matching it with the logs:

  • this sets new_bitrate to 300000 as expected:
  gint new_bitrate = kms_enc_tree_bin_get_bitrate (self);
  • this divides it by 1000 and sets kbps_div to 1:
    case X264:
      property_name = h264_property_name;
      kbps_div = 1;
      new_bitrate /= 1000;
      break;

so then new_bitrate value is 300

  • this tries to multiply it by 1 and divide by 1000, so as this ends up trying to set value 0:
  g_object_set (self->priv->enc, property_name, new_bitrate * kbps_div / 1000, NULL);

Indeed new_bitrate * kbps_div / 1000 is then 300 * 1 / 1000. Hence the error log and this issue report.

How to reproduce?

Configure MediaElement.conf.ini with the following content:

;; Target video bitrate for media transcoding.
;;
;; The bitrate of a video has a direct impact on its perceived image quality.
;; Higher bitrate means higher quality, but also a larger amount of bytes to
;; transmit or store. Use this parameter to set the desired average bitrate in
;; videos that are transcoded by the media server.
;;
;; This parameter is most useful for RecorderEndpoint and RtpEndpoint: when
;; media is being transcoded (either for streaming or storing on disk), the
;; resulting quality is directly controlled with this value.
;;
;; For WebRtcEndpoint, this value should be left as default, as remote WebRTC
;; receivers will already send feedback to inform the media server about what is
;; the optimal bitrate to send.
;;
;; Setting a value will only work if done before the media starts to flow.
;;
;; * Unit: bps (bits per second).
;; * Default: 300000 (300 kbps).
encoderBitrate=300000

And create a pipeline with x264 encoder and logs enabled, for example I used GST_DEBUG set to the following:

2,Kurento*:4,kms*:4,sdp*:4,webrtc*:4,*rtpendpoint:4,rtp*handler:4,rtpsynchronizer:4,agnosticbin:4,enctreebin:5,agnosticbin:5

Expected & current behavior

I got the unexpected bitrate at the end of the pipeline.

(Optional) Possible solution

Instead of setting value 300000, I can use value 300000000 in configuration and get the following logs:

0:01:39.966445444    18 0x7f09852ce000 DEBUG             enctreebin kmsenctreebin.c:146:configure_encoder: Configure encoder: <x264enc0>
0:01:39.966503485    18 0x7f09852ce000 DEBUG             enctreebin kmsenctreebin.c:494:kms_enc_tree_bin_configure:<kmsenctreebin1> Encoder plugin found: <x264enc0> for caps: video/x-h264, stream-format=(string)avc, alignment=(string)au, width=(int)[ 16, 2147483647 ], height=(int)[ 16, 2147483647 ]
0:01:39.966511233    18 0x7f09852ce000 DEBUG             enctreebin kmsenctreebin.c:311:kms_enc_tree_bin_get_bitrate:<kmsenctreebin1> Bitrate = Current value: 300000000
0:01:39.966519198    18 0x7f09852ce000 DEBUG             enctreebin kmsenctreebin.c:370:kms_enc_tree_bin_set_target_bitrate:<x264enc0> "bitrate" set: 300000

About Kurento Media Server

  • Kurento version: 7.1.0
  • Server OS: Ubuntu 24.04.1 LTS
  • Installation method:
    • [] [apt-get]
    • [Docker]
    • [] [AWS CloudFormation]
    • [] [Built from sources]

About your Application Server

  • Programming Language: Java
  • Kurento Client version: 7.1.0
@slabajo
Copy link
Member

slabajo commented Jan 13, 2025

This is a bug and it will be fixed shortly

@slabajo
Copy link
Member

slabajo commented Jan 15, 2025

We have made a fix on PR #97 , after testing it should be merged for next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants