Browse Source

prioritize default audio tracks (#1178)

pull/1179/head
Jason Dove 3 years ago committed by GitHub
parent
commit
c832c8e860
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 32
      ErsatzTV.Core/FFmpeg/FFmpegStreamSelector.cs

4
CHANGELOG.md

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
 Changelog
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Streaming from disk is preferred, so every playback attempt will first check the local file system
- Use libvpl instead of libmfx to provide intel acceleration in vaapi docker images
- Search queries no longer remove duplicate results as this was causing incorrect behavior
- Prioritize audio streams that are flagged as "default" over number of audio channels
- For example, a video with a stereo commentary track and a mono "default" track will now prefer the "default" track
## [0.7.4-beta] - 2023-02-12
### Added

32
ErsatzTV.Core/FFmpeg/FFmpegStreamSelector.cs

@ -199,7 +199,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector @@ -199,7 +199,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector
private Option<MediaStream> DefaultSelectAudioStream(
MediaVersion version,
List<string> preferredLanguageCodes,
IReadOnlyCollection<string> preferredLanguageCodes,
string preferredAudioTitle)
{
var audioStreams = version.Streams.Filter(s => s.MediaStreamKind == MediaStreamKind.Audio).ToList();
@ -232,8 +232,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector @@ -232,8 +232,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector
{
if (string.IsNullOrWhiteSpace(title))
{
_logger.LogDebug("No audio title has been specified; selecting stream with most channels");
return streams.OrderByDescending(s => s.Channels).ThenByDescending(s => s.Default).Head();
return PrioritizeDefault(streams);
}
// prioritize matching titles
@ -243,18 +242,31 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector @@ -243,18 +242,31 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector
if (matchingTitle.Any())
{
_logger.LogDebug(
"Found {Count} audio streams with preferred title {Title}; selecting stream with most channels",
"Found {Count} audio streams with preferred title {Title}",
matchingTitle.Count,
title);
return matchingTitle.OrderByDescending(s => s.Channels).ThenByDescending(s => s.Default).Head();
return PrioritizeDefault(streams);
}
_logger.LogDebug("Unable to find audio stream with preferred title {Title}", title);
_logger.LogDebug(
"Unable to find audio stream with preferred title {Title}; selecting stream with most channels",
title);
return PrioritizeDefault(streams);
}
private Option<MediaStream> PrioritizeDefault(IReadOnlyCollection<MediaStream> streams)
{
var sorted = streams.OrderByDescending(s => s.Channels).ToList();
Option<MediaStream> maybeDefault = Optional(sorted.Find(s => s.Default));
foreach (MediaStream stream in maybeDefault)
{
_logger.LogDebug("Found audio stream flagged as default");
return stream;
}
_logger.LogDebug("Unable to find default audio stream; selecting stream with most channels");
return streams.OrderByDescending(s => s.Channels).ThenByDescending(s => s.Default).Head();
return streams.HeadOrNone();
}
private async Task<Option<MediaStream>> SelectEpisodeAudioStream(
@ -310,7 +322,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector @@ -310,7 +322,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector
_logger.LogDebug("Checking for JS Script at {Path}", jsScriptPath);
if (!_localFileSystem.FileExists(jsScriptPath))
{
_logger.LogWarning("Unable to locate movie audio stream selector script; falling back to built-in logic");
_logger.LogInformation("Unable to locate movie audio stream selector script; falling back to built-in logic");
return Option<MediaStream>.None;
}

Loading…
Cancel
Save