|
|
|
@ -86,6 +86,16 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|
|
|
|
{ "truehd", 6 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static readonly string[] LosslessAudioCodecs = new string[]
|
|
|
|
|
{
|
|
|
|
|
"alac",
|
|
|
|
|
"ape",
|
|
|
|
|
"flac",
|
|
|
|
|
"mlp",
|
|
|
|
|
"truehd",
|
|
|
|
|
"wavpack"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public EncodingHelper(
|
|
|
|
|
IApplicationPaths appPaths,
|
|
|
|
|
IMediaEncoder mediaEncoder,
|
|
|
|
@ -2149,17 +2159,6 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.Equals(audioCodec, "flac", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|| string.Equals(audioCodec, "alac", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
if (inputChannels >= 6)
|
|
|
|
|
{
|
|
|
|
|
return Math.Min(3584000, bitrate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Math.Min(1536000, bitrate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|| string.Equals(audioCodec, "dca", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
@ -2172,20 +2171,10 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.Equals(audioCodec, "truehd", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return (inputChannels, outputChannels) switch
|
|
|
|
|
{
|
|
|
|
|
(> 0, > 0) => Math.Min(outputChannels * 768000, bitrate),
|
|
|
|
|
(> 0, _) => Math.Min(inputChannels * 768000, bitrate),
|
|
|
|
|
(_, _) => Math.Min(768000, bitrate)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty bitrate area is not allow on iOS
|
|
|
|
|
// Default audio bitrate to 128K per channel if we don't have codec specific defaults
|
|
|
|
|
// https://ffmpeg.org/ffmpeg-codecs.html#toc-Codec-Options
|
|
|
|
|
return 128000 * (outputAudioChannels ?? audioStream.Channels ?? 1);
|
|
|
|
|
return 128000 * (outputAudioChannels ?? audioStream.Channels ?? 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetAudioVbrModeParam(string encoder, int bitratePerChannel)
|
|
|
|
@ -5867,8 +5856,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bitrate = state.OutputAudioBitrate;
|
|
|
|
|
|
|
|
|
|
if (bitrate.HasValue)
|
|
|
|
|
if (bitrate.HasValue && !LosslessAudioCodecs.Contains(codec, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var vbrParam = GetAudioVbrModeParam(codec, bitrate.Value / (channels ?? 2));
|
|
|
|
|
if (encodingOptions.EnableAudioVbr && vbrParam is not null)
|
|
|
|
@ -5897,10 +5885,11 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|
|
|
|
|
|
|
|
|
var bitrate = state.OutputAudioBitrate;
|
|
|
|
|
var channels = state.OutputAudioChannels;
|
|
|
|
|
var outputCodec = state.OutputAudioCodec;
|
|
|
|
|
|
|
|
|
|
if (bitrate.HasValue)
|
|
|
|
|
if (bitrate.HasValue && !LosslessAudioCodecs.Contains(outputCodec, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var vbrParam = GetAudioVbrModeParam(state.OutputAudioCodec, bitrate.Value / (channels ?? 2));
|
|
|
|
|
var vbrParam = GetAudioVbrModeParam(outputCodec, bitrate.Value / (channels ?? 2));
|
|
|
|
|
if (encodingOptions.EnableAudioVbr && vbrParam is not null)
|
|
|
|
|
{
|
|
|
|
|
audioTranscodeParams.Add(vbrParam);
|
|
|
|
@ -5916,12 +5905,12 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|
|
|
|
audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(state.OutputAudioCodec))
|
|
|
|
|
if (!string.IsNullOrEmpty(outputCodec))
|
|
|
|
|
{
|
|
|
|
|
audioTranscodeParams.Add("-acodec " + GetAudioEncoder(state));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.Equals(state.OutputAudioCodec, "opus", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
if (!string.Equals(outputCodec, "opus", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
// opus only supports specific sampling rates
|
|
|
|
|
var sampleRate = state.OutputAudioSampleRate;
|
|
|
|
|