obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

obs-ffmpeg: Fix Opus encoder bitrate and errors

Open thebitbrine opened this issue 2 months ago • 4 comments

Description

Fixes issue #12753 where the Opus encoder incorrectly allows bitrate selection up to 1024 kbps, causing confusing "Failed to open AAC codec" errors when values exceed FFmpeg libopus's 256 kbps per-channel limit.

Changes Made

  1. Added opus_properties() function: Creates Opus-specific properties with correct bitrate range (64-256 kbps)
  2. Fixed error messages: Changed hardcoded "AAC codec" to display actual codec name (enc->type)
  3. Updated opus_encoder_info: Uses new opus_properties() instead of generic enc_properties()

Technical Details

  • FFmpeg's libopus enforces a maximum of 256 kbps per channel
  • The 256 kbps limit is more than sufficient (typical WebRTC usage is 30-90 kbps)
  • Error message fix improves reporting for all FFmpeg audio encoders (AAC, ALAC, FLAC, etc.)

Testing

  • Code follows OBS coding guidelines (kernel normal form, tabs for indentation)
  • No trailing whitespace
  • All lines under 120 columns
  • Verified against existing code patterns

Related Issues

Closes #12753

thebitbrine avatar Oct 26 '25 02:10 thebitbrine

Safety verification

Ran through the codebase to check for potential compatibility issues:

Backward compatibility with old configs

If someone has bitrate=320 in their config, OBS won't crash. The frontend already has FindClosestAvailableSimpleOpusBitrate() that clamps out-of-range values. A config with 320 kbps will just get downgraded to 256.

See: audio-encoders.cpp lines 326-348

Error message change

Changed "Failed to open AAC codec" to use the actual codec name. Checked if anything parses these errors - nothing does. They just get passed through to the UI for display via obs_encoder_get_last_error().

See: obs-output.c lines 2586, 2600

Other encoders

AAC uses the same enc_properties and correctly supports up to 1024 kbps. PCM/ALAC/FLAC also use it but they're lossless so the bitrate setting gets ignored anyway (line 217 sets bit_rate=0 for lossless codecs).

Edge cases checked

  • Config with 320 kbps: clamps to 256
  • Config with 128 kbps: works as-is
  • Config with 32 kbps: clamps to 64 (minimum)

No breaking changes. Old configs handle gracefully.

thebitbrine avatar Oct 26 '25 02:10 thebitbrine

Please split the changes into separate commits.

WizardCM avatar Nov 01 '25 23:11 WizardCM

Split into two commits as requested:

  1. Fix hardcoded error message (affects all FFmpeg audio encoders)
  2. Fix Opus encoder bitrate limit (addresses #12753)

The error message fix is now separate since it benefits all codecs, not just Opus.

thebitbrine avatar Nov 02 '25 06:11 thebitbrine

Do not use merge commits to keep up with master branch history. Use git rebase instead.

RytoEX avatar Dec 09 '25 20:12 RytoEX