mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-15 18:45:44 +00:00
Run code cleanup
This commit is contained in:
parent
c60e217a2f
commit
0956870875
7 changed files with 232 additions and 199 deletions
|
|
@ -1,15 +1,16 @@
|
|||
using FFMpegCore.Exceptions;
|
||||
|
||||
namespace FFMpegCore.Arguments
|
||||
namespace FFMpegCore.Arguments;
|
||||
|
||||
/// <summary>
|
||||
/// Represents output parameter
|
||||
/// </summary>
|
||||
public class OutputSegmentArgument : IOutputArgument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents output parameter
|
||||
/// </summary>
|
||||
public class OutputSegmentArgument : IOutputArgument
|
||||
{
|
||||
public readonly string SegmentPattern;
|
||||
public readonly bool Overwrite;
|
||||
public readonly SegmentArgumentOptions Options;
|
||||
public readonly bool Overwrite;
|
||||
public readonly string SegmentPattern;
|
||||
|
||||
public OutputSegmentArgument(SegmentArgument segmentArgument)
|
||||
{
|
||||
SegmentPattern = segmentArgument.SegmentPattern;
|
||||
|
|
@ -31,12 +32,18 @@ namespace FFMpegCore.Arguments
|
|||
throw new FFMpegException(FFMpegExceptionType.Process, "Parameter SegmentWrap cannot equal to zero");
|
||||
}
|
||||
}
|
||||
public Task During(CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
|
||||
public Task During(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Post()
|
||||
{
|
||||
}
|
||||
|
||||
public string Text => GetText();
|
||||
|
||||
private string GetText()
|
||||
{
|
||||
var arguments = Options.Arguments
|
||||
|
|
@ -48,35 +55,55 @@ namespace FFMpegCore.Arguments
|
|||
|
||||
return $"-f segment {string.Join(" ", arguments)} \"{SegmentPattern}\"{(Overwrite ? " -y" : string.Empty)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISegmentArgument
|
||||
{
|
||||
public interface ISegmentArgument
|
||||
{
|
||||
public string Key { get; }
|
||||
public string Value { get; }
|
||||
}
|
||||
}
|
||||
|
||||
public class SegmentArgumentOptions
|
||||
{
|
||||
public class SegmentArgumentOptions
|
||||
{
|
||||
public List<ISegmentArgument> Arguments { get; } = new();
|
||||
|
||||
public SegmentArgumentOptions ResetTimeStamps(bool resetTimestamps = true) => WithArgument(new SegmentResetTimeStampsArgument(resetTimestamps));
|
||||
public SegmentArgumentOptions Strftime(bool enable = false) => WithArgument(new SegmentStrftimeArgument(enable));
|
||||
public SegmentArgumentOptions Time(int time = 60) => WithArgument(new SegmentTimeArgument(time));
|
||||
public SegmentArgumentOptions Wrap(int limit = -1) => WithArgument(new SegmentWrapArgument(limit));
|
||||
public SegmentArgumentOptions WithCustomArgument(string argument) => WithArgument(new SegmentCustomArgument(argument));
|
||||
public SegmentArgumentOptions ResetTimeStamps(bool resetTimestamps = true)
|
||||
{
|
||||
return WithArgument(new SegmentResetTimeStampsArgument(resetTimestamps));
|
||||
}
|
||||
|
||||
public SegmentArgumentOptions Strftime(bool enable = false)
|
||||
{
|
||||
return WithArgument(new SegmentStrftimeArgument(enable));
|
||||
}
|
||||
|
||||
public SegmentArgumentOptions Time(int time = 60)
|
||||
{
|
||||
return WithArgument(new SegmentTimeArgument(time));
|
||||
}
|
||||
|
||||
public SegmentArgumentOptions Wrap(int limit = -1)
|
||||
{
|
||||
return WithArgument(new SegmentWrapArgument(limit));
|
||||
}
|
||||
|
||||
public SegmentArgumentOptions WithCustomArgument(string argument)
|
||||
{
|
||||
return WithArgument(new SegmentCustomArgument(argument));
|
||||
}
|
||||
|
||||
private SegmentArgumentOptions WithArgument(ISegmentArgument argument)
|
||||
{
|
||||
Arguments.Add(argument);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SegmentArgument
|
||||
{
|
||||
public readonly string SegmentPattern;
|
||||
public readonly bool Overwrite;
|
||||
public class SegmentArgument
|
||||
{
|
||||
public readonly Action<SegmentArgumentOptions> Options;
|
||||
public readonly bool Overwrite;
|
||||
public readonly string SegmentPattern;
|
||||
|
||||
public SegmentArgument(string segmentPattern, bool overwrite, Action<SegmentArgumentOptions> options)
|
||||
{
|
||||
|
|
@ -84,5 +111,4 @@ namespace FFMpegCore.Arguments
|
|||
Overwrite = overwrite;
|
||||
Options = options;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
namespace FFMpegCore.Arguments
|
||||
namespace FFMpegCore.Arguments;
|
||||
|
||||
public class SegmentCustomArgument : ISegmentArgument
|
||||
{
|
||||
public class SegmentCustomArgument : ISegmentArgument
|
||||
{
|
||||
public readonly string Argument;
|
||||
|
||||
public SegmentCustomArgument(string argument)
|
||||
{
|
||||
Argument = argument;
|
||||
}
|
||||
|
||||
public string Key => "custom";
|
||||
public string Value => Argument ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
namespace FFMpegCore.Arguments
|
||||
namespace FFMpegCore.Arguments;
|
||||
|
||||
/// <summary>
|
||||
/// Represents reset_timestamps parameter
|
||||
/// </summary>
|
||||
public class SegmentResetTimeStampsArgument : ISegmentArgument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents reset_timestamps parameter
|
||||
/// </summary>
|
||||
public class SegmentResetTimeStampsArgument : ISegmentArgument
|
||||
{
|
||||
public readonly bool ResetTimestamps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents reset_timestamps parameter
|
||||
/// </summary>
|
||||
|
|
@ -14,7 +15,7 @@
|
|||
{
|
||||
ResetTimestamps = resetTimestamps;
|
||||
}
|
||||
|
||||
public string Key { get; } = "reset_timestamps";
|
||||
public string Value => ResetTimestamps ? $"-reset_timestamps 1" : string.Empty;
|
||||
}
|
||||
public string Value => ResetTimestamps ? "-reset_timestamps 1" : string.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,23 @@
|
|||
namespace FFMpegCore.Arguments
|
||||
namespace FFMpegCore.Arguments;
|
||||
|
||||
/// <summary>
|
||||
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a
|
||||
/// strftime function template. Default value is 0.
|
||||
/// </summary>
|
||||
public class SegmentStrftimeArgument : ISegmentArgument
|
||||
{
|
||||
/// <summary>
|
||||
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a strftime function template. Default value is 0.
|
||||
/// </summary>
|
||||
public class SegmentStrftimeArgument : ISegmentArgument
|
||||
{
|
||||
public readonly bool Enable;
|
||||
|
||||
/// <summary>
|
||||
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a strftime function template. Default value is 0.
|
||||
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a
|
||||
/// strftime function template. Default value is 0.
|
||||
/// </summary>
|
||||
/// <param name="enable">true to enable strftime</param>
|
||||
public SegmentStrftimeArgument(bool enable)
|
||||
{
|
||||
Enable = enable;
|
||||
}
|
||||
|
||||
public string Key { get; } = "strftime";
|
||||
public string Value => Enable ? $"-strftime 1" : string.Empty;
|
||||
}
|
||||
public string Value => Enable ? "-strftime 1" : string.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
namespace FFMpegCore.Arguments
|
||||
namespace FFMpegCore.Arguments;
|
||||
|
||||
/// <summary>
|
||||
/// Represents segment_time parameter
|
||||
/// </summary>
|
||||
public class SegmentTimeArgument : ISegmentArgument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents segment_time parameter
|
||||
/// </summary>
|
||||
public class SegmentTimeArgument : ISegmentArgument
|
||||
{
|
||||
public readonly int Time;
|
||||
|
||||
/// <summary>
|
||||
/// Represents segment_time parameter
|
||||
/// </summary>
|
||||
|
|
@ -14,7 +15,7 @@
|
|||
{
|
||||
Time = time;
|
||||
}
|
||||
|
||||
public string Key { get; } = "segment_time";
|
||||
public string Value => Time <= 0 ? string.Empty : $"-segment_time {Time}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
namespace FFMpegCore.Arguments
|
||||
namespace FFMpegCore.Arguments;
|
||||
|
||||
/// <summary>
|
||||
/// Represents segment_wrap parameter
|
||||
/// </summary>
|
||||
public class SegmentWrapArgument : ISegmentArgument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents segment_wrap parameter
|
||||
/// </summary>
|
||||
public class SegmentWrapArgument : ISegmentArgument
|
||||
{
|
||||
public readonly int Limit;
|
||||
|
||||
/// <summary>
|
||||
/// Represents segment_wrap parameter
|
||||
/// </summary>
|
||||
|
|
@ -14,7 +15,7 @@
|
|||
{
|
||||
Limit = limit;
|
||||
}
|
||||
|
||||
public string Key { get; } = "segment_wrap";
|
||||
public string Value => Limit <= 0 ? string.Empty : $"-segment_wrap {Limit}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
using System.Text.Json.Serialization;
|
||||
using FFMpegCore.Enums;
|
||||
|
||||
namespace FFMpegCore
|
||||
namespace FFMpegCore;
|
||||
|
||||
public class FFOptions : ICloneable
|
||||
{
|
||||
public class FFOptions : ICloneable
|
||||
{
|
||||
/// <summary>
|
||||
/// Working directory for the ffmpeg/ffprobe instance
|
||||
/// </summary>
|
||||
|
|
@ -22,7 +22,7 @@ namespace FFMpegCore
|
|||
public string TemporaryFilesFolder { get; set; } = Path.GetTempPath();
|
||||
|
||||
/// <summary>
|
||||
/// Encoding web name used to persist encoding <see cref="Encoding"/>
|
||||
/// Encoding web name used to persist encoding <see cref="Encoding" />
|
||||
/// </summary>
|
||||
public string EncodingWebName { get; set; } = Encoding.Default.WebName;
|
||||
|
||||
|
|
@ -46,24 +46,25 @@ namespace FFMpegCore
|
|||
public FFMpegLogLevel? LogLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExtensionOverrides { get; set; } = new()
|
||||
{
|
||||
{ "mpegts", ".ts" },
|
||||
};
|
||||
public Dictionary<string, string> ExtensionOverrides { get; set; } = new() { { "mpegts", ".ts" } };
|
||||
|
||||
/// <summary>
|
||||
/// Whether to cache calls to get ffmpeg codec, pixel- and container-formats
|
||||
/// </summary>
|
||||
public bool UseCache { get; set; } = true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
object ICloneable.Clone() => Clone();
|
||||
/// <inheritdoc />
|
||||
object ICloneable.Clone()
|
||||
{
|
||||
return Clone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new object that is a copy of the current instance.
|
||||
/// </summary>
|
||||
public FFOptions Clone() => (FFOptions)MemberwiseClone();
|
||||
public FFOptions Clone()
|
||||
{
|
||||
return (FFOptions)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue