mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Initial audio filter implementation
This commit is contained in:
parent
e6d85eea11
commit
78a703fc93
2 changed files with 60 additions and 0 deletions
53
FFMpegCore/FFMpeg/Arguments/AudioFiltersArgument.cs
Normal file
53
FFMpegCore/FFMpeg/Arguments/AudioFiltersArgument.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,6 +43,13 @@ public FFMpegArgumentOptions WithVideoFilters(Action<VideoFilterOptions> videoFi
|
|||
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 WithoutMetadata() => WithArgument(new RemoveMetadataArgument());
|
||||
public FFMpegArgumentOptions WithSpeedPreset(Speed speed) => WithArgument(new SpeedPresetArgument(speed));
|
||||
|
|
Loading…
Reference in a new issue