Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions FFMpegCore.Test/ArgumentBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Drawing;
using FFMpegCore.Arguments;
using FFMpegCore.Enums;
using FFMpegCore.Exceptions;
using FFMpegCore.Pipes;

namespace FFMpegCore.Test;
Expand Down Expand Up @@ -141,6 +142,62 @@ public void Builder_BuildString_DisableChannel_Video()
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<FFMpegException>(() => FFMpegArguments
.FromFileInput("input.mp4")
.OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.Both)).Arguments);
}

[TestMethod]
public void Builder_BuildString_DisableChannel_All_InvalidChannel()
{
Assert.ThrowsExactly<FFMpegException>(() => FFMpegArguments
.FromFileInput("input.mp4")
.OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.All)).Arguments);
}

[TestMethod]
public void Builder_BuildString_DisableChannel_Attachments_UnsupportedChannel()
{
Assert.ThrowsExactly<FFMpegException>(() => FFMpegArguments
.FromFileInput("input.mp4")
.OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.Attachments)).Arguments);
}

[TestMethod]
public void Builder_BuildString_DisableChannel_VideoNoAttachedPic_UnsupportedChannel()
{
Assert.ThrowsExactly<FFMpegException>(() => FFMpegArguments
.FromFileInput("input.mp4")
.OutputToFile("output.mp4", false, opt => opt.DisableChannel(Channel.VideoNoAttachedPic)).Arguments);
}

[TestMethod]
public void Builder_BuildString_AudioSamplingRate_Default()
{
Expand Down
24 changes: 22 additions & 2 deletions FFMpegCore/FFMpeg/Arguments/DisableChannelArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@
namespace FFMpegCore.Arguments;

/// <summary>
/// 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
/// </summary>
public class DisableChannelArgument : IArgument
{
public readonly Channel Channel;

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;
Expand All @@ -24,6 +42,8 @@ public DisableChannelArgument(Channel channel)
{
Channel.Video => "-vn",
Channel.Audio => "-an",
Channel.Subtitle => "-sn",
Channel.Data => "-dn",
_ => string.Empty
};
}