|
@@ -862,18 +862,37 @@ namespace MediaBrowser.Model.Dlna
|
|
|
|
|
|
if (options.AllowAudioStreamCopy)
|
|
|
{
|
|
|
- if (ContainerHelper.ContainsContainer(transcodingProfile.AudioCodec, audioCodec))
|
|
|
+ // For Audio stream, we prefer the audio codec that can be directly copied, then the codec that can otherwise satisfies
|
|
|
+ // the transcoding conditions, then the one does not satisfy the transcoding conditions.
|
|
|
+ // For example: A client can support both aac and flac, but flac only supports 2 channels while aac supports 6.
|
|
|
+ // When the source audio is 6 channel flac, we should transcode to 6 channel aac, instead of down-mix to 2 channel flac.
|
|
|
+ var transcodingAudioCodecs = ContainerHelper.Split(transcodingProfile.AudioCodec);
|
|
|
+
|
|
|
+ foreach (var transcodingAudioCodec in transcodingAudioCodecs)
|
|
|
{
|
|
|
var appliedVideoConditions = options.Profile.CodecProfiles
|
|
|
.Where(i => i.Type == CodecType.VideoAudio &&
|
|
|
- i.ContainsAnyCodec(audioCodec, container) &&
|
|
|
+ i.ContainsAnyCodec(transcodingAudioCodec, container) &&
|
|
|
i.ApplyConditions.All(applyCondition => ConditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, audioBitrate, audioSampleRate, audioBitDepth, audioProfile, false)))
|
|
|
.Select(i =>
|
|
|
i.Conditions.All(condition => ConditionProcessor.IsVideoAudioConditionSatisfied(condition, audioChannels, audioBitrate, audioSampleRate, audioBitDepth, audioProfile, false)));
|
|
|
|
|
|
// An empty appliedVideoConditions means that the codec has no conditions for the current audio stream
|
|
|
var conditionsSatisfied = appliedVideoConditions.All(satisfied => satisfied);
|
|
|
- rank.Audio = conditionsSatisfied ? 1 : 2;
|
|
|
+
|
|
|
+ var rankAudio = 3;
|
|
|
+
|
|
|
+ if (conditionsSatisfied)
|
|
|
+ {
|
|
|
+ rankAudio = string.Equals(transcodingAudioCodec, audioCodec, StringComparison.OrdinalIgnoreCase) ? 1 : 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ rank.Audio = Math.Min(rank.Audio, rankAudio);
|
|
|
+
|
|
|
+ if (rank.Audio == 1)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -963,9 +982,26 @@ namespace MediaBrowser.Model.Dlna
|
|
|
|
|
|
var audioStreamWithSupportedCodec = candidateAudioStreams.Where(stream => ContainerHelper.ContainsContainer(audioCodecs, false, stream.Codec)).FirstOrDefault();
|
|
|
|
|
|
- var directAudioStream = audioStreamWithSupportedCodec?.Channels is not null && audioStreamWithSupportedCodec.Channels.Value <= (playlistItem.TranscodingMaxAudioChannels ?? int.MaxValue) ? audioStreamWithSupportedCodec : null;
|
|
|
+ var channelsExceedsLimit = audioStreamWithSupportedCodec is not null && audioStreamWithSupportedCodec.Channels > (playlistItem.TranscodingMaxAudioChannels ?? int.MaxValue);
|
|
|
+
|
|
|
+ var directAudioStreamSatisfied = audioStreamWithSupportedCodec is not null && !channelsExceedsLimit
|
|
|
+ && options.Profile.CodecProfiles
|
|
|
+ .Where(i => i.Type == CodecType.VideoAudio
|
|
|
+ && i.ContainsAnyCodec(audioStreamWithSupportedCodec.Codec, container)
|
|
|
+ && i.ApplyConditions.All(applyCondition => ConditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioStreamWithSupportedCodec.Channels, audioStreamWithSupportedCodec.BitRate, audioStreamWithSupportedCodec.SampleRate, audioStreamWithSupportedCodec.BitDepth, audioStreamWithSupportedCodec.Profile, false)))
|
|
|
+ .Select(i => i.Conditions.All(condition =>
|
|
|
+ {
|
|
|
+ var satisfied = ConditionProcessor.IsVideoAudioConditionSatisfied(condition, audioStreamWithSupportedCodec.Channels, audioStreamWithSupportedCodec.BitRate, audioStreamWithSupportedCodec.SampleRate, audioStreamWithSupportedCodec.BitDepth, audioStreamWithSupportedCodec.Profile, false);
|
|
|
+ if (!satisfied)
|
|
|
+ {
|
|
|
+ playlistItem.TranscodeReasons |= GetTranscodeReasonForFailedCondition(condition);
|
|
|
+ }
|
|
|
+
|
|
|
+ return satisfied;
|
|
|
+ }))
|
|
|
+ .All(satisfied => satisfied);
|
|
|
|
|
|
- var channelsExceedsLimit = audioStreamWithSupportedCodec is not null && directAudioStream is null;
|
|
|
+ var directAudioStream = directAudioStreamSatisfied ? audioStreamWithSupportedCodec : null;
|
|
|
|
|
|
if (channelsExceedsLimit && playlistItem.TargetAudioStream is not null)
|
|
|
{
|