Initial audio filter implementation

Former-commit-id: 78a703fc93
This commit is contained in:
alex6dj 2021-10-04 09:54:38 -04:00
parent feaeb7478e
commit c6f1d94a74
2 changed files with 60 additions and 0 deletions

View file

@ -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<IAudioFilterArgument> Arguments { get; } = new List<IAudioFilterArgument>();
private AudioFilterOptions WithArgument(IAudioFilterArgument argument)
{
Arguments.Add(argument);
return this;
}
}
}

View file

@ -43,6 +43,13 @@ public FFMpegArgumentOptions WithVideoFilters(Action<VideoFilterOptions> videoFi
return WithArgument(new VideoFiltersArgument(videoFilterOptionsObj)); return WithArgument(new VideoFiltersArgument(videoFilterOptionsObj));
} }
public FFMpegArgumentOptions WithAudioFilters(Action<AudioFilterOptions> audioFilterOptions)
{
var audioFilterOptionsObj = new AudioFilterOptions();
audioFilterOptions(audioFilterOptionsObj);
return WithArgument(new AudioFiltersArgument(audioFilterOptionsObj));
}
public FFMpegArgumentOptions WithFramerate(double framerate) => WithArgument(new FrameRateArgument(framerate)); public FFMpegArgumentOptions WithFramerate(double framerate) => WithArgument(new FrameRateArgument(framerate));
public FFMpegArgumentOptions WithoutMetadata() => WithArgument(new RemoveMetadataArgument()); public FFMpegArgumentOptions WithoutMetadata() => WithArgument(new RemoveMetadataArgument());
public FFMpegArgumentOptions WithSpeedPreset(Speed speed) => WithArgument(new SpeedPresetArgument(speed)); public FFMpegArgumentOptions WithSpeedPreset(Speed speed) => WithArgument(new SpeedPresetArgument(speed));