From 2891aa5cdd114ce556c401310c161e19591e9bf5 Mon Sep 17 00:00:00 2001 From: Prakash Duggaraju Date: Mon, 21 Aug 2023 17:36:16 -0700 Subject: [PATCH] Fix failures when text track has both VTT and CMFT. Use VTT over CMFT since shaka supports CMFT. --- transform/BasePackager.cs | 34 ++++++++++++++++------------------ transform/ShakaPackager.cs | 3 ++- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/transform/BasePackager.cs b/transform/BasePackager.cs index 40601f5..5867e37 100644 --- a/transform/BasePackager.cs +++ b/transform/BasePackager.cs @@ -54,6 +54,21 @@ abstract class BasePackager : IPackager public IDictionary> FileToTrackMap => _fileToTrackMap; + public static bool IsTextTrackSupported(Track track, Manifest manifest) + { + return !track.IsMultiFile && (track.Source.EndsWith(VTT_FILE) || track.Parameters.Any(t => t.Name == TRANSCRIPT_SOURCE)); + } + + public static bool IsLiveTextTrackSupported(Track track, ClientManifest clientManifest) + { + return track.IsMultiFile && + // Choose the text track with a list of fragblobs for close captions. + clientManifest!.Streams.Any( + stream => (stream.Type == StreamType.Text && + stream.SubType == "SUBT") && + stream.Name == track.TrackName); + } + public BasePackager(AssetDetails assetDetails, TransMuxer transMuxer, ILogger logger) { _assetDetails = assetDetails; @@ -65,24 +80,7 @@ public BasePackager(AssetDetails assetDetails, TransMuxer transMuxer, ILogger lo SelectedTracks = manifest.Tracks.Where(t => { if (t is TextTrack) - { - bool pickThisTextTrack = !t.IsMultiFile && (t.Source.EndsWith(VTT_FILE) || t.Parameters.Any(t => t.Name == TRANSCRIPT_SOURCE)); - - if (manifest.IsLiveArchive) - { - pickThisTextTrack = false; - - if (t.IsMultiFile) - { - // Choose the text track with a list of fragblobs for close captions. - pickThisTextTrack = assetDetails.ClientManifest!.Streams.Any( - stream => (stream.Type == StreamType.Text && - stream.SubType == "SUBT") && - stream.Name == t.TrackName); - } - } - return pickThisTextTrack; - } + return manifest.IsLiveArchive && IsLiveTextTrackSupported(t, assetDetails.ClientManifest!) || IsTextTrackSupported(t, manifest); return true; }).ToList(); diff --git a/transform/ShakaPackager.cs b/transform/ShakaPackager.cs index 7c40a5b..8c952c7 100644 --- a/transform/ShakaPackager.cs +++ b/transform/ShakaPackager.cs @@ -112,8 +112,9 @@ private IEnumerable GetArguments(IList inputs, IList out List arguments = new(SelectedTracks.Select((t, i) => { + var source = t.Parameters.SingleOrDefault(p => p.Name == TRANSCRIPT_SOURCE)?.Value ?? t.Source; var ext = t.IsMultiFile ? (t is TextTrack ? VTT_FILE : MEDIA_FILE) : string.Empty; - var file = $"{t.Source}{ext}"; + var file = $"{source}{ext}"; var index = Inputs.IndexOf(file); var multiTrack = TransmuxedSmooth && FileToTrackMap[file].Count > 1; var inputFile = multiTrack ?