sbooth / SFBAudioEngine

A powerhouse of audio functionality for macOS, iOS, and tvOS
https://sbooth.github.io/SFBAudioEngine/
MIT License
569 stars 86 forks source link

When encoding to mp3, the bitrate is always 128kbps #221

Closed mytianer closed 2 years ago

sbooth commented 2 years ago

Could you post the encoder settings you're using?

mytianer commented 2 years ago

Could you post the encoder settings you're using?

OK, like this [.mp3TargetIsBitrate: NSNumber(value: 1), .mp3Quality: NSNumber(value: 5), .mp3Bitrate: NSNumber(value: 192), .mp3EnableCBR: NSNumber(value: 0), .mp3StereoMode: MP3StereoMode.jointStereo, .mp3CalculateReplayGain: NSNumber(value: 1)]

mytianer commented 2 years ago

I tested it again, still the same 128kbps, and the duration read through SFBAudioFile is wrong

sbooth commented 2 years ago

I do think the encoder settings are being changed but perhaps not in a way that makes the most sense based on the parameters.

Part of the problem is that the Xing header wasn't being written. That is fixed with PR #226 and should give the correct frame count.

I also think the way the settings are presented it not intuitive to the caller. I will open a new issue and PR to make the settings more similar to the CLI lame.

sbooth commented 2 years ago

I believe all of these problems are truly fixed now.

Using

encoder.settings = [
    .mp3UseVariableBitrate: true,
    .mp3VBRMinimumBitrate: 192,
    .mp3VBRQuality: 5,
    .mp3CalculateReplayGain: true
]

gives the expected result:

Encoder Version     : LAME3.100
LAME Tag Revision   : 0
VBR Method          : Variable Bitrate method2 (mtrh)
Lowpass Filter      : 17000
Radio Replay Gain   : 8.3 dB (Set automatically)
Encoding Flags      : --nspsytune --nssafejoint
ATH Type            : 5
Bitrate (Minimum)   : 192
Encoder Delay       : 576 samples
Encoder Padding     : 1017 samples
Noise Shaping       : 1
Stereo Mode         : Joint
Unwise Settings     : False
Sample Frequency    : 44.1 kHz
MP3 Gain            : 0 (+0.0 dB)
Preset              : V5
Surround Info       : None
Music Length        : 49.31 KB
Music CRC-16        : 82B5
LAME Tag CRC-16     : FA81