diff --git a/FFMpegCore/FFMpeg/Arguments/AudioFiltersArgument.cs b/FFMpegCore/FFMpeg/Arguments/AudioFiltersArgument.cs new file mode 100644 index 0000000..834b784 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/AudioFiltersArgument.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using FFMpegCore.Enums; +using FFMpegCore.Exceptions; + +namespace FFMpegCore.Arguments +{ + public class AudioFiltersArgument : IArgument + { + public readonly AudioFilterOptions Options; + + public AudioFiltersArgument(AudioFilterOptions options) + { + Options = options; + } + + public string Text => GetText(); + + private string GetText() + { + if (!Options.Arguments.Any()) + throw new FFMpegArgumentException("No audio-filter arguments provided"); + + var arguments = Options.Arguments + .Where(arg => !string.IsNullOrEmpty(arg.Value)) + .Select(arg => + { + var escapedValue = arg.Value.Replace(",", "\\,"); + return string.IsNullOrEmpty(arg.Key) ? escapedValue : $"{arg.Key}={escapedValue}"; + }); + + return $"-af \"{string.Join(", ", arguments)}\""; + } + } + + public interface IAudioFilterArgument + { + public string Key { get; } + public string Value { get; } + } + + public class AudioFilterOptions + { + public List Arguments { get; } = new List(); + + private AudioFilterOptions WithArgument(IAudioFilterArgument argument) + { + Arguments.Add(argument); + return this; + } + } +} \ No newline at end of file diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index 41ac38c..ca6628a 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -43,6 +43,13 @@ public FFMpegArgumentOptions WithVideoFilters(Action videoFi return WithArgument(new VideoFiltersArgument(videoFilterOptionsObj)); } + public FFMpegArgumentOptions WithAudioFilters(Action audioFilterOptions) + { + var audioFilterOptionsObj = new AudioFilterOptions(); + audioFilterOptions(audioFilterOptionsObj); + return WithArgument(new AudioFiltersArgument(audioFilterOptionsObj)); + } + public FFMpegArgumentOptions WithFramerate(double framerate) => WithArgument(new FrameRateArgument(framerate)); public FFMpegArgumentOptions WithoutMetadata() => WithArgument(new RemoveMetadataArgument()); public FFMpegArgumentOptions WithSpeedPreset(Speed speed) => WithArgument(new SpeedPresetArgument(speed));