Skip to content

Add bitrate configuration support#24

Merged
khamilowicz merged 3 commits into
masterfrom
add-bitrate
Jun 18, 2026
Merged

Add bitrate configuration support#24
khamilowicz merged 3 commits into
masterfrom
add-bitrate

Conversation

@khamilowicz

Copy link
Copy Markdown
Contributor

Add support for configuring bitrate settings in the transcoder plugin.

Supports both ffmpeg and Vulcan bitrate settings. For constant bitrate for ffmpeg, https://trac.ffmpeg.org/wiki/Encode/H.264#CBRConstantBitRate approach is used

@khamilowicz khamilowicz requested a review from varsill June 10, 2026 14:10
@khamilowicz khamilowicz force-pushed the add-bitrate branch 3 times, most recently from 3cd992a to e73a71c Compare June 11, 2026 09:00
to scene changes; expressed in milliseconds, defaults to 2 seconds.
"""

@type t :: %__MODULE__{bitrate: non_neg_integer(), virtual_buffer_size_ms: non_neg_integer()}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT] Perhaps instead of virtual_buffer_size_ms it would be good to have virtual_buffer_size expressed in Membrane.Time.t()?

Comment thread lib/transcoder.ex
Comment thread test/integration_test.exs
Comment thread test/integration_test.exs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a @tag :vulkan test as well

@khamilowicz khamilowicz requested a review from varsill June 16, 2026 08:57
* bitrate - desired bitrate of the stream; expressed in bits per second.
* virtual_buffer_size - virtual buffer duration for rate control smoothing;
larger values increase bitrate stability, smaller values improve responsiveness
to scene changes; expressed in nanoseconds as `Membrane.Time.t()`, defaults to 2 seconds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to scene changes; expressed in nanoseconds as `Membrane.Time.t()`, defaults to 2 seconds.
to scene changes; expressed as `Membrane.Time.t()`, defaults to 2 seconds.

(Membrane.Time's should be opaque i.e. it's internal representation shouldn't be relevant - and it can change at any time)

spikes while maintaining average bitrate constraints; expressed in bits per second.
* virtual_buffer_size - virtual buffer duration for rate control smoothing; larger values
increase bitrate stability, smaller values improve responsiveness to scene changes;
expressed in nanoseconds as `Membrane.Time.t()`, defaults to 2 seconds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expressed in nanoseconds as `Membrane.Time.t()`, defaults to 2 seconds.
expressed as `Membrane.Time.t()`, defaults to 2 seconds.

Comment thread lib/transcoder/video.ex Outdated
max_bitrate: max,
virtual_buffer_size: vbr_ns
}) do
vbr_ms = trunc(vbr_ns / 1_000_000)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
vbr_ms = trunc(vbr_ns / 1_000_000)
vbr_ms = Membrane.as_milliseconds(:round)

it also applies to the rest of places where you "manually" convert from Membrane.Time.t() to milliseconds etc. :D

…ocs, add vulkan test

- Replace manual time division with Membrane.Time.as_milliseconds/2 for
  converting Membrane.Time.t() to milliseconds in all encoder parameter
  functions (vkvideo, h264_ffmpeg, h265_x265)
- Update documentation to say 'expressed as Membrane.Time.t()' instead of
  'expressed in nanoseconds as Membrane.Time.t()' since the type is opaque
- Add @tag :vulkan test for bitrate conversion to verify Vulkan-accelerated
  transcoding works correctly with bitrate settings

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@khamilowicz khamilowicz requested a review from varsill June 16, 2026 15:42

@varsill varsill left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@khamilowicz khamilowicz merged commit e95ccee into master Jun 18, 2026
4 checks passed
@khamilowicz khamilowicz deleted the add-bitrate branch June 18, 2026 09:51
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

Successfully merging this pull request may close these issues.

2 participants