From fdbd273104f3f5ba8f311683c9107a759e60862a Mon Sep 17 00:00:00 2001 From: Joseph Tam Date: Wed, 18 Sep 2024 09:31:54 +0800 Subject: [PATCH] feat: expose stream index --- .../Program.cs | 33 +++++++++++++++++++ .../AdaptiveHlsTranscoderConfiguration.cs | 3 +- .../AdaptiveHlsTranscoder.Arguments.cs | 2 +- ...eStreamingServerNet.StreamProcessor.csproj | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/samples/LiveStreamingServerNet.AdaptiveHlsDemo/Program.cs b/samples/LiveStreamingServerNet.AdaptiveHlsDemo/Program.cs index 24068667..87cf15fe 100644 --- a/samples/LiveStreamingServerNet.AdaptiveHlsDemo/Program.cs +++ b/samples/LiveStreamingServerNet.AdaptiveHlsDemo/Program.cs @@ -1,5 +1,6 @@ using LiveStreamingServerNet.StreamProcessor.AspNetCore.Installer; using LiveStreamingServerNet.StreamProcessor.Contracts; +using LiveStreamingServerNet.StreamProcessor.Hls.Configurations; using LiveStreamingServerNet.StreamProcessor.Installer; using LiveStreamingServerNet.StreamProcessor.Utilities; using LiveStreamingServerNet.Utilities.Contracts; @@ -51,6 +52,38 @@ private static IServiceCollection AddLiveStreamingServer(this IServiceCollection options.FFmpegPath = ExecutableFinder.FindExecutableFromPATH("ffmpeg")!; options.FFprobePath = ExecutableFinder.FindExecutableFromPATH("ffprobe")!; + options.DownsamplingFilters = + [ + new DownsamplingFilter( + Name: "360p", + Height: 360, + MaxVideoBitrate: "600k", + MaxAudioBitrate: "64k" + ), + + new DownsamplingFilter( + Name: "480p", + Height: 480, + MaxVideoBitrate: "1500k", + MaxAudioBitrate: "128k" + ), + + new DownsamplingFilter( + Name: "720p", + Height: 720, + MaxVideoBitrate: "3000k", + MaxAudioBitrate: "256k" + ), + + new DownsamplingFilter( + Name: "720p_rotated", + Height: 720, + MaxVideoBitrate: "3000k", + MaxAudioBitrate: "256k", + ExtraArguments: (streamIndex) => $"-filter:v:{streamIndex} transpose=1" + ), + ]; + // Hardware acceleration // options.VideoDecodingArguments = "-hwaccel auto -c:v h264_cuvid"; // options.VideoEncodingArguments = "-c:v h264_nvenc -g 30"; diff --git a/src/LiveStreamingServerNet.StreamProcessor/Hls/Configurations/AdaptiveHlsTranscoderConfiguration.cs b/src/LiveStreamingServerNet.StreamProcessor/Hls/Configurations/AdaptiveHlsTranscoderConfiguration.cs index 201ce54f..b1b838e9 100644 --- a/src/LiveStreamingServerNet.StreamProcessor/Hls/Configurations/AdaptiveHlsTranscoderConfiguration.cs +++ b/src/LiveStreamingServerNet.StreamProcessor/Hls/Configurations/AdaptiveHlsTranscoderConfiguration.cs @@ -57,5 +57,6 @@ public record HlsOptions( string? ExtraArguments = null ); - public record DownsamplingFilter(string Name, int Height, string MaxVideoBitrate, string MaxAudioBitrate, string? ExtraArguments = null); + public delegate string ExtraFilterArguments(int streamIndex); + public record DownsamplingFilter(string Name, int Height, string MaxVideoBitrate, string MaxAudioBitrate, ExtraFilterArguments? ExtraArguments = null); } \ No newline at end of file diff --git a/src/LiveStreamingServerNet.StreamProcessor/Internal/Hls/AdaptiveTranscoding/AdaptiveHlsTranscoder.Arguments.cs b/src/LiveStreamingServerNet.StreamProcessor/Internal/Hls/AdaptiveTranscoding/AdaptiveHlsTranscoder.Arguments.cs index 52510250..e8ef262b 100644 --- a/src/LiveStreamingServerNet.StreamProcessor/Internal/Hls/AdaptiveTranscoding/AdaptiveHlsTranscoder.Arguments.cs +++ b/src/LiveStreamingServerNet.StreamProcessor/Internal/Hls/AdaptiveTranscoding/AdaptiveHlsTranscoder.Arguments.cs @@ -89,7 +89,7 @@ private static void AddDownsamplingFilters(IList downsamplin arguments.Add($"-maxrate:v:{i} {filter.MaxVideoBitrate}"); arguments.Add($"-b:a:{i} {filter.MaxAudioBitrate}"); - AddOptionalArgument(arguments, filter.ExtraArguments); + AddOptionalArgument(arguments, filter.ExtraArguments?.Invoke(i)); } } diff --git a/src/LiveStreamingServerNet.StreamProcessor/LiveStreamingServerNet.StreamProcessor.csproj b/src/LiveStreamingServerNet.StreamProcessor/LiveStreamingServerNet.StreamProcessor.csproj index f1a28300..1996fa9b 100644 --- a/src/LiveStreamingServerNet.StreamProcessor/LiveStreamingServerNet.StreamProcessor.csproj +++ b/src/LiveStreamingServerNet.StreamProcessor/LiveStreamingServerNet.StreamProcessor.csproj @@ -10,7 +10,7 @@ live-streaming;rtmp;transmuxer;transcoder;hls;dash MIT true - 0.14.2 + 0.14.3 true