mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 01:55:45 +00:00
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
namespace FFMpegCore.Arguments;
|
|
|
|
internal class OutputTeeArgument : IOutputArgument
|
|
{
|
|
private readonly FFMpegMultiOutputOptions _options;
|
|
|
|
public OutputTeeArgument(FFMpegMultiOutputOptions options)
|
|
{
|
|
if (options.Outputs.Count == 0)
|
|
{
|
|
throw new ArgumentException("Atleast one output must be specified.", nameof(options));
|
|
}
|
|
|
|
_options = options;
|
|
}
|
|
|
|
public string Text => $"-f tee \"{string.Join("|", _options.Outputs.Select(MapOptions))}\"";
|
|
|
|
public Task During(CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public void Post()
|
|
{
|
|
}
|
|
|
|
public void Pre()
|
|
{
|
|
}
|
|
|
|
private static string MapOptions(FFMpegArgumentOptions option)
|
|
{
|
|
var optionPrefix = string.Empty;
|
|
if (option.Arguments.Count > 1)
|
|
{
|
|
var options = option.Arguments.Take(option.Arguments.Count - 1);
|
|
optionPrefix = $"[{string.Join(":", options.Select(MapArgument))}]";
|
|
}
|
|
|
|
var output = option.Arguments.OfType<IOutputArgument>().Single();
|
|
return $"{optionPrefix}{output.Text.Trim('"')}";
|
|
}
|
|
|
|
private static string MapArgument(IArgument argument)
|
|
{
|
|
if (argument is MapStreamArgument map)
|
|
{
|
|
return map.Text.Replace("-map ", "select=\\'") + "\\'";
|
|
}
|
|
|
|
if (argument is BitStreamFilterArgument bitstreamFilter)
|
|
{
|
|
return bitstreamFilter.Text.Replace("-bsf:", "bsfs/").Replace(' ', '=');
|
|
}
|
|
|
|
return argument.Text.TrimStart('-').Replace(' ', '=');
|
|
}
|
|
}
|