@ -2586,8 +2586,9 @@ namespace MediaBrowser.Controller.MediaEncoding
return 128000 * ( outputAudioChannels ? ? audioStream . Channels ? ? 2 ) ;
}
public string GetAudioVbrModeParam ( string encoder , int bitrate PerChannel )
public string GetAudioVbrModeParam ( string encoder , int bitrate , int channels )
{
var bitratePerChannel = bitrate / channels ;
if ( string . Equals ( encoder , "libfdk_aac" , StringComparison . OrdinalIgnoreCase ) )
{
return " -vbr:a " + bitratePerChannel switch
@ -2602,14 +2603,26 @@ namespace MediaBrowser.Controller.MediaEncoding
if ( string . Equals ( encoder , "libmp3lame" , StringComparison . OrdinalIgnoreCase ) )
{
return " -qscale:a " + bitratePerChannel switch
// lame's VBR is only good for a certain bitrate range
// For very low and very high bitrate, use abr mode
if ( bitratePerChannel is < 122500 and > 48000 )
{
< 48000 = > "8" ,
< 64000 = > "6" ,
< 88000 = > "4" ,
< 112000 = > "2" ,
_ = > "0"
} ;
return " -qscale:a " + bitratePerChannel switch
{
< 64000 = > "6" ,
< 88000 = > "4" ,
< 112000 = > "2" ,
_ = > "0"
} ;
}
return " -abr:a 1" + " -b:a " + bitrate ;
}
if ( string . Equals ( encoder , "aac_at" , StringComparison . OrdinalIgnoreCase ) )
{
// aac_at's CVBR mode
return " -aac_at_mode:a 2" + " -b:a " + bitrate ;
}
if ( string . Equals ( encoder , "libvorbis" , StringComparison . OrdinalIgnoreCase ) )
@ -6962,7 +6975,7 @@ namespace MediaBrowser.Controller.MediaEncoding
var bitrate = state . OutputAudioBitrate ;
if ( bitrate . HasValue & & ! LosslessAudioCodecs . Contains ( codec , StringComparison . OrdinalIgnoreCase ) )
{
var vbrParam = GetAudioVbrModeParam ( codec , bitrate . Value / ( channels ? ? 2 ) ) ;
var vbrParam = GetAudioVbrModeParam ( codec , bitrate . Value , channels ? ? 2 ) ;
if ( encodingOptions . EnableAudioVbr & & vbrParam is not null )
{
args + = vbrParam ;
@ -6993,7 +7006,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if ( bitrate . HasValue & & ! LosslessAudioCodecs . Contains ( outputCodec , StringComparison . OrdinalIgnoreCase ) )
{
var vbrParam = GetAudioVbrModeParam ( GetAudioEncoder ( state ) , bitrate . Value / ( channels ? ? 2 ) ) ;
var vbrParam = GetAudioVbrModeParam ( GetAudioEncoder ( state ) , bitrate . Value , channels ? ? 2 ) ;
if ( encodingOptions . EnableAudioVbr & & vbrParam is not null )
{
audioTranscodeParams . Add ( vbrParam ) ;