Skip to content

Conversation

@thebitbrine
Copy link

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
Copy link
Author

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.

@WizardCM WizardCM added the Bug Fix Non-breaking change which fixes an issue label Nov 1, 2025
@WizardCM
Copy link
Member

WizardCM commented Nov 1, 2025

Please split the changes into separate commits.

The error message in initialize_codec() was hardcoded to say 'AAC codec'
for all audio encoder failures. This caused confusion when other codecs
like Opus failed, displaying an incorrect codec name in the error.

Changed the error message to use enc->type to display the actual codec
name that failed to initialize.
The Opus encoder was using enc_properties which allows bitrates up to
1024 kbps. However, FFmpeg's libopus enforces a maximum of 256 kbps per
channel. Selecting bitrates above 256 kbps would cause encoder
initialization to fail.

Added opus_properties() function that sets the correct bitrate range of
64-256 kbps. The 256 kbps limit is more than sufficient for Opus, as
typical WebRTC usage is only 30-90 kbps.

Fixes obsproject#12753
@thebitbrine thebitbrine force-pushed the fix-opus-encoder-bitrate branch from 211be5e to a4c5ce9 Compare November 2, 2025 06:02
@thebitbrine
Copy link
Author

Split into two commits as requested:

  1. Fix hardcoded error message (affects all FFmpeg audio encoders)
  2. Fix Opus encoder bitrate limit (addresses FFmpeg Opus audio codec supports up to 256 kbps, not 320. #12753)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Fix Non-breaking change which fixes an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FFmpeg Opus audio codec supports up to 256 kbps, not 320.

2 participants