From fc78b6ec8fd1d3e7a9a0a1ef326bd70ce7eac511 Mon Sep 17 00:00:00 2001 From: RudyTheDev <3857299+RudyTheDev@users.noreply.github.com> Date: Sat, 20 Dec 2025 18:30:27 +0200 Subject: [PATCH] Add disable channel argument cases for subtitle and data streams --- FFMpegCore.Test/ArgumentBuilderTest.cs | 57 +++++++++++++++++++ .../Arguments/DisableChannelArgument.cs | 24 +++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 64a116b..8759e27 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -1,6 +1,7 @@ using System.Drawing; using FFMpegCore.Arguments; using FFMpegCore.Enums; +using FFMpegCore.Exceptions; using FFMpegCore.Pipes; namespace FFMpegCore.Test; @@ -141,6 +142,62 @@ public class ArgumentBuilderTest Assert.AreEqual("-i \"input.mp4\" -vn \"output.mp4\"", str); } + [TestMethod] + public void Builder_BuildString_DisableChannel_Subtitle() + { + var str = FFMpegArguments.FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.Subtitle)).Arguments; + Assert.AreEqual("-i \"input.mp4\" -sn \"output.mp4\"", str); + } + + [TestMethod] + public void Builder_BuildString_DisableChannel_Data() + { + var str = FFMpegArguments.FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.Data)).Arguments; + Assert.AreEqual("-i \"input.mp4\" -dn \"output.mp4\"", str); + } + + [TestMethod] + public void Builder_BuildString_DisableChannel_Multiple() + { + var str = FFMpegArguments.FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.Audio).DisableChannel(Channel.Video)).Arguments; + Assert.AreEqual("-i \"input.mp4\" -an -vn \"output.mp4\"", str); + } + + [TestMethod] + public void Builder_BuildString_DisableChannel_Both_InvalidChannel() + { + Assert.ThrowsExactly(() => FFMpegArguments + .FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.Both)).Arguments); + } + + [TestMethod] + public void Builder_BuildString_DisableChannel_All_InvalidChannel() + { + Assert.ThrowsExactly(() => FFMpegArguments + .FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.All)).Arguments); + } + + [TestMethod] + public void Builder_BuildString_DisableChannel_Attachments_UnsupportedChannel() + { + Assert.ThrowsExactly(() => FFMpegArguments + .FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.Attachments)).Arguments); + } + + [TestMethod] + public void Builder_BuildString_DisableChannel_VideoNoAttachedPic_UnsupportedChannel() + { + Assert.ThrowsExactly(() => FFMpegArguments + .FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.VideoNoAttachedPic)).Arguments); + } + [TestMethod] public void Builder_BuildString_AudioSamplingRate_Default() { diff --git a/FFMpegCore/FFMpeg/Arguments/DisableChannelArgument.cs b/FFMpegCore/FFMpeg/Arguments/DisableChannelArgument.cs index c6b89ea..ec96d25 100644 --- a/FFMpegCore/FFMpeg/Arguments/DisableChannelArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/DisableChannelArgument.cs @@ -4,7 +4,8 @@ using FFMpegCore.Exceptions; namespace FFMpegCore.Arguments; /// -/// Represents cpu speed parameter +/// Represents channel disabling parameter +/// Used to disable processing of all streams of a particular type so that they are not filtered, automatically selected or mapped for any input or output /// public class DisableChannelArgument : IArgument { @@ -12,9 +13,26 @@ public class DisableChannelArgument : IArgument public DisableChannelArgument(Channel channel) { + if (channel == Channel.All) + { + throw new FFMpegException(FFMpegExceptionType.Conversion, "Cannot disable all channels"); + } + if (channel == Channel.Both) { - throw new FFMpegException(FFMpegExceptionType.Conversion, "Cannot disable both channels"); + throw new FFMpegException(FFMpegExceptionType.Conversion, "Cannot disable both video and audio channels at once"); + } + + if (channel == Channel.Attachments) + { + // ffmpeg does not support disabling attachment streams + throw new FFMpegException(FFMpegExceptionType.Operation, $"{nameof(Channel.Attachments)} channel cannot be disabled"); + } + + if (channel == Channel.VideoNoAttachedPic) + { + // ffmpeg does not support disabling no-picture-filtered video steams + throw new FFMpegException(FFMpegExceptionType.Operation, $"{nameof(Channel.VideoNoAttachedPic)} channel cannot be disabled"); } Channel = channel; @@ -24,6 +42,8 @@ public class DisableChannelArgument : IArgument { Channel.Video => "-vn", Channel.Audio => "-an", + Channel.Subtitle => "-sn", + Channel.Data => "-dn", _ => string.Empty }; }