Skip to content

feat(media_publish): per-track bitrate + codec-aware encoder options#35

Open
rickstaa wants to merge 1 commit into
ja/live-runnerfrom
rs/media-publish-encoder-opts
Open

feat(media_publish): per-track bitrate + codec-aware encoder options#35
rickstaa wants to merge 1 commit into
ja/live-runnerfrom
rs/media-publish-encoder-opts

Conversation

@rickstaa

@rickstaa rickstaa commented Jul 7, 2026

Copy link
Copy Markdown
Member

Problem

The trickle output path (MediaPublish / VideoOutputConfig) had two limits:

  1. No bitrate. VideoOutputConfig has no bitrate field, so a rendition ladder can't set per-tier bitrates — the encoder picks its own default. That makes the output unpredictable and unusable for real ABR.
  2. x264-only. The encoder options were hardcoded for libx264 (preset=superfast, tune=zerolatency, forced-idr, bf) and applied to every codec, so libsvtav1 / libvpx-vp9 / *_nvenc fail at avcodec_open2 with Invalid argument.

Change

VideoOutputConfig gains three optional, backward-compatible fields:

  • bit_rate — target average video bitrate (bits/sec)
  • profile — H.264/H.265 profile ("high", "main", "baseline"); codecs without one ignore it
  • encoder_options — extra ffmpeg options merged over the per-codec defaults

Encoder options are now codec-aware (_encoder_base_options): x264/x265 keep the original low-latency set (identical behavior), other codecs start empty so they open cleanly, and callers tune via encoder_options (e.g. {"preset":"p4","tune":"ll"} for av1_nvenc). bit_rate is applied to the stream's codec context after add_stream.

Result

Unlocks bitrate control and AV1/HEVC/VP9 on the live/trickle transcode path in one change. Defaults are unchanged — existing libx264 callers see no difference.

Tests

tests/test_media_publish_encoder.py — x264 keeps its options, non-x264 get empty base options, and the new fields default to no-op / are accepted. 4 passed.

Follow-ups (not in this PR)

  • Per-codec low-latency defaults for non-x264 (kept empty here to guarantee avcodec_open2 succeeds; opt in via encoder_options).
  • Explicit gop_size from keyframe_interval_s (segmentation currently drives keyframes).

🤖 Generated with Claude Code

The trickle output path hardcoded x264-only encoder options
(preset=superfast, tune=zerolatency, forced-idr, bf) for every codec and had
no way to set a target bitrate. That made rendition ladders unusable for ABR
(the encoder picked its own bitrate) and made non-x264 encoders (libsvtav1,
libvpx-vp9, *_nvenc) fail at avcodec_open2.

VideoOutputConfig gains three optional, backward-compatible fields:
  - bit_rate: target average video bitrate (bits/sec)
  - profile:  H.264/H.265 profile (ignored by codecs without one)
  - encoder_options: extra ffmpeg options merged over the per-codec defaults

Encoder options are now codec-aware: x264/x265 keep the original low-latency
set (identical behavior); other codecs start from empty defaults so they open,
and callers tune via encoder_options (e.g. {"preset":"p4","tune":"ll"} for
av1_nvenc). bit_rate is applied to the stream's codec context after add_stream.

Unlocks bitrate control AND AV1/HEVC/VP9 on the live/trickle transcode path.
Defaults are unchanged, so existing x264 users see no difference.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CjPDUcYXLR6K2ft4g7TYbt
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2636d670-b24f-4581-90ba-dc33ad95a33e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rs/media-publish-encoder-opts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant