Remove ArgumentStringifier + cleanup

No reason to split the responsibility


Former-commit-id: 0e2c788796
This commit is contained in:
Malte Rosenbjerg 2020-02-27 20:16:17 +01:00
parent 075ac1990f
commit 7d77c33609
33 changed files with 142 additions and 520 deletions

View file

@ -22,12 +22,10 @@ public override string ToString()
/// </summary> /// </summary>
public abstract class Argument<T> : Argument public abstract class Argument<T> : Argument
{ {
private T _value;
/// <summary> /// <summary>
/// Value type of <see cref="T"/> /// Value type of <see cref="T"/>
/// </summary> /// </summary>
public T Value { get => _value; set { CheckValue(value); _value = value; } } public T Value { get; protected set; }
public Argument() { } public Argument() { }
@ -35,11 +33,6 @@ public Argument(T value)
{ {
Value = value; Value = value;
} }
protected virtual void CheckValue(T value)
{
}
} }
/// <summary> /// <summary>
@ -47,19 +40,15 @@ protected virtual void CheckValue(T value)
/// </summary> /// </summary>
public abstract class Argument<T1, T2> : Argument public abstract class Argument<T1, T2> : Argument
{ {
private T1 _first;
private T2 _second;
/// <summary> /// <summary>
/// First value type of <see cref="T"/> /// First value type of <see cref="T"/>
/// </summary> /// </summary>
public T1 First { get => _first; set { CheckFirst(_first); _first = value; } } public T1 First { get; set; }
/// <summary> /// <summary>
/// Second value type of <see cref="T"/> /// Second value type of <see cref="T"/>
/// </summary> /// </summary>
public T2 Second { get => _second; set { CheckSecond(_second); _second = value; } } public T2 Second { get; set; }
public Argument() { } public Argument() { }
@ -68,15 +57,5 @@ public Argument(T1 first, T2 second)
First = first; First = first;
Second = second; Second = second;
} }
protected virtual void CheckFirst(T1 value)
{
}
protected virtual void CheckSecond(T2 value)
{
}
} }
} }

View file

@ -1,179 +0,0 @@
using FFMpegCore.FFMPEG.Enums;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace FFMpegCore.FFMPEG.Argument
{
internal static class ArgumentStringifier
{
internal static string Speed(Speed speed)
{
return $"-preset {speed.ToString().ToLower()} ";
}
internal static string Speed(int cpu)
{
return $"-quality good -cpu-used {cpu} -deadline realtime ";
}
internal static string Audio(AudioCodec codec, int bitrate)
{
return Audio(codec) + Audio(bitrate);
}
internal static string Audio(AudioCodec codec)
{
return $"-c:a {codec.ToString().ToLower()} ";
}
internal static string Audio(AudioQuality bitrate)
{
return Audio((int)bitrate);
}
internal static string Audio(int bitrate)
{
return $"-b:a {bitrate}k ";
}
internal static string Video(VideoCodec codec, int bitrate = 0)
{
var video = $"-c:v {codec.ToString().ToLower()} -pix_fmt yuv420p ";
if (bitrate > 0)
{
video += $"-b:v {bitrate}k ";
}
return video;
}
internal static string Threads(bool multiThread)
{
var threadCount = multiThread
? Environment.ProcessorCount
: 1;
return Threads(threadCount);
}
internal static string Threads(int threads)
{
return $"-threads {threads} ";
}
internal static string Disable(Channel type)
{
switch (type)
{
case Channel.Video:
return "-vn ";
case Channel.Audio:
return "-an ";
default:
return string.Empty;
}
}
internal static string Output(string output)
{
return $"\"{output}\"";
}
internal static string Input(string template)
{
return $"-i \"{template}\" ";
}
internal static string Scale(VideoSize size, int width =-1)
{
return size == VideoSize.Original ? string.Empty : Scale(width, (int)size);
}
internal static string Scale(int width, int height)
{
return $"-vf scale={width}:{height} ";
}
internal static string Size(Size? size)
{
if (!size.HasValue) return string.Empty;
var formatedSize = $"{size.Value.Width}x{size.Value.Height}";
return $"-s {formatedSize} ";
}
internal static string ForceFormat(VideoCodec codec)
{
return $"-f {codec.ToString().ToLower()} ";
}
internal static string BitStreamFilter(Channel type, Filter filter)
{
switch (type)
{
case Channel.Audio:
return $"-bsf:a {filter.ToString().ToLower()} ";
case Channel.Video:
return $"-bsf:v {filter.ToString().ToLower()} ";
default:
return string.Empty;
}
}
internal static string Copy(Channel type = Channel.Both)
{
switch (type)
{
case Channel.Audio:
return "-c:a copy ";
case Channel.Video:
return "-c:v copy ";
default:
return "-c copy ";
}
}
internal static string Seek(TimeSpan? seek)
{
return !seek.HasValue ? string.Empty : $"-ss {seek} ";
}
internal static string FrameOutputCount(int number)
{
return $"-vframes {number} ";
}
internal static string Loop(int count)
{
return $"-loop {count} ";
}
internal static string FinalizeAtShortestInput(bool applicable)
{
return applicable ? "-shortest " : string.Empty;
}
internal static string InputConcat(IEnumerable<string> paths)
{
return $"-i \"concat:{string.Join(@"|", paths)}\" ";
}
internal static string FrameRate(double frameRate)
{
return $"-r {frameRate} ";
}
internal static string StartNumber(int v)
{
return $"-start_number {v} ";
}
internal static string Duration(TimeSpan? duration)
{
return !duration.HasValue ? string.Empty : $"-t {duration} ";
}
}
}

View file

@ -10,33 +10,23 @@ public class AudioCodecArgument : Argument<AudioCodec>
/// <summary> /// <summary>
/// Bitrate of audio channel /// Bitrate of audio channel
/// </summary> /// </summary>
public int Bitrate { get; protected set; } = (int)AudioQuality.Normal; public int Bitrate { get; } = (int)AudioQuality.Normal;
public AudioCodecArgument() public AudioCodecArgument() { }
{
}
public AudioCodecArgument(AudioCodec value) : base(value) public AudioCodecArgument(AudioCodec value) : base(value) { }
{
}
public AudioCodecArgument(AudioCodec value, AudioQuality bitrate) : base(value) public AudioCodecArgument(AudioCodec value, AudioQuality bitrate) : this(value, (int) bitrate) { }
{
Bitrate = (int)bitrate;
}
public AudioCodecArgument(AudioCodec value, int bitrate) : base(value) public AudioCodecArgument(AudioCodec value, int bitrate) : base(value)
{ {
Bitrate = bitrate; Bitrate = bitrate;
} }
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Audio(Value, Bitrate); return $"-c:a {Value.ToString().ToLower()} -b:a {Bitrate}k";
} }
} }
} }

View file

@ -1,4 +1,5 @@
using FFMpegCore.FFMPEG.Enums; using System;
using FFMpegCore.FFMPEG.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.FFMPEG.Argument
{ {
@ -7,21 +8,19 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class BitStreamFilterArgument : Argument<Channel, Filter> public class BitStreamFilterArgument : Argument<Channel, Filter>
{ {
public BitStreamFilterArgument() public BitStreamFilterArgument() { }
{
}
public BitStreamFilterArgument(Channel first, Filter second) : base(first, second) public BitStreamFilterArgument(Channel first, Filter second) : base(first, second) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.BitStreamFilter(First, Second); return First switch
{
Channel.Audio => $"-bsf:a {Second.ToString().ToLower()}",
Channel.Video => $"-bsf:v {Second.ToString().ToLower()}",
_ => string.Empty
};
} }
} }
} }

View file

@ -10,27 +10,19 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class ConcatArgument : Argument<IEnumerable<string>>, IEnumerable<string> public class ConcatArgument : Argument<IEnumerable<string>>, IEnumerable<string>
{ {
public ConcatArgument() public ConcatArgument() : base(new List<string>()) { }
{
Value = new List<string>();
}
public ConcatArgument(IEnumerable<string> value) : base(value) public ConcatArgument(IEnumerable<string> value) : base(value) { }
{
}
public IEnumerator<string> GetEnumerator() public IEnumerator<string> GetEnumerator()
{ {
return Value.GetEnumerator(); return Value.GetEnumerator();
} }
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.InputConcat(Value); return $"-i \"concat:{string.Join(@"|", Value)}\"";
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()

View file

@ -15,9 +15,10 @@ public ConstantRateFactorArgument(int crf) : base(crf)
} }
} }
/// <inheritdoc/>
public override string GetStringValue() public override string GetStringValue()
{ {
return $"-crf {Value} "; return $"-crf {Value}";
} }
} }
} }

View file

@ -8,22 +8,18 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class CopyArgument : Argument<Channel> public class CopyArgument : Argument<Channel>
{ {
public CopyArgument() public CopyArgument() : base(Channel.Both) { }
{ public CopyArgument(Channel value = Channel.Both) : base(value) { }
Value = Channel.Both;
}
public CopyArgument(Channel value = Channel.Both) : base(value) /// <inheritdoc/>
{
}
/// <summary>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Copy(Value); return Value switch
{
Channel.Audio => "-c:a copy",
Channel.Video => "-c:v copy",
Channel.Both => "-c copy"
};
} }
} }
} }

View file

@ -5,21 +5,14 @@
/// </summary> /// </summary>
public class CpuSpeedArgument : Argument<int> public class CpuSpeedArgument : Argument<int>
{ {
public CpuSpeedArgument() public CpuSpeedArgument() { }
{
}
public CpuSpeedArgument(int value) : base(value) public CpuSpeedArgument(int value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Speed(Value); return $"-quality good -cpu-used {Value} -deadline realtime";
} }
} }
} }

View file

@ -7,21 +7,19 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class DisableChannelArgument : Argument<Channel> public class DisableChannelArgument : Argument<Channel>
{ {
public DisableChannelArgument() public DisableChannelArgument() { }
{
}
public DisableChannelArgument(Channel value) : base(value) public DisableChannelArgument(Channel value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Disable(Value); return Value switch
{
Channel.Video => "-vn",
Channel.Audio => "-an",
_ => string.Empty
};
} }
} }
} }

View file

@ -9,13 +9,12 @@ namespace FFMpegCore.FFMPEG.Argument
public class DrawTextArgument : Argument<IEnumerable<(string key, string value)>> public class DrawTextArgument : Argument<IEnumerable<(string key, string value)>>
{ {
public DrawTextArgument(string text, string fontPath, params (string, string)[] optionalArguments) public DrawTextArgument(string text, string fontPath, params (string, string)[] optionalArguments)
: base(new[] {("text", text), ("fontfile", fontPath)}.Concat(optionalArguments)) : base(new[] {("text", text), ("fontfile", fontPath)}.Concat(optionalArguments)) { }
{
}
/// <inheritdoc/>
public override string GetStringValue() public override string GetStringValue()
{ {
return $"-vf drawtext=\"{string.Join(": ", Value.Select(FormatArgumentPair))}\" "; return $"-vf drawtext=\"{string.Join(": ", Value.Select(FormatArgumentPair))}\"";
} }
private static string FormatArgumentPair((string key, string value) pair) private static string FormatArgumentPair((string key, string value) pair)

View file

@ -7,21 +7,14 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class DurationArgument : Argument<TimeSpan?> public class DurationArgument : Argument<TimeSpan?>
{ {
public DurationArgument() public DurationArgument() { }
{
}
public DurationArgument(TimeSpan? value) : base(value) public DurationArgument(TimeSpan? value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Duration(Value); return !Value.HasValue ? string.Empty : $"-t {Value}";
} }
} }
} }

View file

@ -5,13 +5,12 @@
/// </summary> /// </summary>
public class FaststartArgument : Argument public class FaststartArgument : Argument
{ {
public FaststartArgument() public FaststartArgument() { }
{
}
/// <inheritdoc/>
public override string GetStringValue() public override string GetStringValue()
{ {
return "-movflags faststart "; return "-movflags faststart";
} }
} }
} }

View file

@ -7,21 +7,14 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class ForceFormatArgument : Argument<VideoCodec> public class ForceFormatArgument : Argument<VideoCodec>
{ {
public ForceFormatArgument() public ForceFormatArgument() { }
{
}
public ForceFormatArgument(VideoCodec value) : base(value) public ForceFormatArgument(VideoCodec value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.ForceFormat(Value); return $"-f {Value.ToString().ToLower()}";
} }
} }
} }

View file

@ -5,21 +5,14 @@
/// </summary> /// </summary>
public class FrameOutputCountArgument : Argument<int> public class FrameOutputCountArgument : Argument<int>
{ {
public FrameOutputCountArgument() public FrameOutputCountArgument() { }
{
}
public FrameOutputCountArgument(int value) : base(value) public FrameOutputCountArgument(int value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.FrameOutputCount(Value); return $"-vframes {Value}";
} }
} }
} }

View file

@ -5,21 +5,14 @@
/// </summary> /// </summary>
public class FrameRateArgument : Argument<double> public class FrameRateArgument : Argument<double>
{ {
public FrameRateArgument() public FrameRateArgument() { }
{
}
public FrameRateArgument(double value) : base(value) public FrameRateArgument(double value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.FrameRate(Value); return $"-r {Value}";
} }
} }
} }

View file

@ -9,33 +9,20 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class InputArgument : Argument<string[]> public class InputArgument : Argument<string[]>
{ {
public InputArgument() public InputArgument() { }
{
}
public InputArgument(params string[] values) : base(values) public InputArgument(params string[] values) : base(values) { }
{
}
public InputArgument(params VideoInfo[] values) : base(values.Select(v => v.FullName).ToArray()) public InputArgument(params VideoInfo[] values) : base(values.Select(v => v.FullName).ToArray()) { }
{
}
public InputArgument(params FileInfo[] values) : base(values.Select(v => v.FullName).ToArray()) public InputArgument(params FileInfo[] values) : base(values.Select(v => v.FullName).ToArray()) { }
{
}
public InputArgument(params Uri[] values) : base(values.Select(v => v.AbsoluteUri).ToArray()) public InputArgument(params Uri[] values) : base(values.Select(v => v.AbsoluteUri).ToArray()) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return string.Join(" ", Value.Select(v => ArgumentStringifier.Input(v))); return string.Join(" ", Value.Select(v => $"-i \"{v}\""));
} }
public VideoInfo[] GetAsVideoInfo() public VideoInfo[] GetAsVideoInfo()
{ {

View file

@ -5,21 +5,14 @@
/// </summary> /// </summary>
public class LoopArgument : Argument<int> public class LoopArgument : Argument<int>
{ {
public LoopArgument() public LoopArgument() { }
{
}
public LoopArgument(int value) : base(value) public LoopArgument(int value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Loop(Value); return $"-loop {Value}";
} }
} }
} }

View file

@ -8,33 +8,20 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class OutputArgument : Argument<string> public class OutputArgument : Argument<string>
{ {
public OutputArgument() public OutputArgument() { }
{
}
public OutputArgument(string value) : base(value) public OutputArgument(string value) : base(value) { }
{
}
public OutputArgument(VideoInfo value) : base(value.FullName) public OutputArgument(VideoInfo value) : base(value.FullName) { }
{
}
public OutputArgument(FileInfo value) : base(value.FullName) public OutputArgument(FileInfo value) : base(value.FullName) { }
{
}
public OutputArgument(Uri value) : base(value.AbsolutePath) public OutputArgument(Uri value) : base(value.AbsolutePath) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Output(Value); return $"\"{Value}\"";
} }
public FileInfo GetAsFileInfo() public FileInfo GetAsFileInfo()

View file

@ -6,14 +6,9 @@
/// </summary> /// </summary>
public class OverrideArgument : Argument public class OverrideArgument : Argument
{ {
public OverrideArgument() public OverrideArgument() { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return "-y"; return "-y";

View file

@ -5,13 +5,12 @@
/// </summary> /// </summary>
public class RemoveMetadataArgument : Argument public class RemoveMetadataArgument : Argument
{ {
public RemoveMetadataArgument() public RemoveMetadataArgument() { }
{
}
/// <inheritdoc/>
public override string GetStringValue() public override string GetStringValue()
{ {
return $"-map_metadata -1 "; return $"-map_metadata -1";
} }
} }
} }

View file

@ -8,30 +8,21 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class ScaleArgument : Argument<Size> public class ScaleArgument : Argument<Size>
{ {
public ScaleArgument() public ScaleArgument() { }
{
}
public ScaleArgument(Size value) : base(value) public ScaleArgument(Size value) : base(value) { }
{
}
public ScaleArgument(int width, int heignt) : base(new Size(width, heignt)) public ScaleArgument(int width, int height) : base(new Size(width, height)) { }
{
}
public ScaleArgument(VideoSize videosize) public ScaleArgument(VideoSize videosize)
{ {
Value = videosize == VideoSize.Original ? new Size(-1, -1) : new Size(-1, (int)videosize); Value = videosize == VideoSize.Original ? new Size(-1, -1) : new Size(-1, (int)videosize);
} }
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Scale(Value.Width, Value.Height); return $"-vf scale={Value.Width}:{Value.Height}";
} }
} }
} }

View file

@ -7,21 +7,14 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class SeekArgument : Argument<TimeSpan?> public class SeekArgument : Argument<TimeSpan?>
{ {
public SeekArgument() public SeekArgument() { }
{
}
public SeekArgument(TimeSpan? value) : base(value) public SeekArgument(TimeSpan? value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Seek(Value); return !Value.HasValue ? string.Empty : $"-ss {Value}";
} }
} }
} }

View file

@ -5,21 +5,14 @@
/// </summary> /// </summary>
public class ShortestArgument : Argument<bool> public class ShortestArgument : Argument<bool>
{ {
public ShortestArgument() public ShortestArgument() { }
{
}
public ShortestArgument(bool value) : base(value) public ShortestArgument(bool value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.FinalizeAtShortestInput(Value); return Value ? "-shortest" : string.Empty;
} }
} }
} }

View file

@ -8,29 +8,18 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class SizeArgument : ScaleArgument public class SizeArgument : ScaleArgument
{ {
public SizeArgument() public SizeArgument() { }
{
}
public SizeArgument(Size? value) : base(value ?? new Size()) public SizeArgument(Size? value) : base(value ?? default) { }
{
}
public SizeArgument(VideoSize videosize) : base(videosize) public SizeArgument(VideoSize videosize) : base(videosize) { }
{
}
public SizeArgument(int width, int heignt) : base(width, heignt) public SizeArgument(int width, int height) : base(width, height) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Size(Value); return Value == default ? string.Empty : $"-s {Value.Width}x{Value.Height}";
} }
} }
} }

View file

@ -11,17 +11,12 @@ public SpeedArgument()
{ {
} }
public SpeedArgument(Speed value) : base(value) public SpeedArgument(Speed value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Speed(Value); return $"-preset {Value.ToString().ToLower()}";
} }
} }
} }

View file

@ -5,21 +5,14 @@
/// </summary> /// </summary>
public class StartNumberArgument : Argument<int> public class StartNumberArgument : Argument<int>
{ {
public StartNumberArgument() public StartNumberArgument() { }
{
}
public StartNumberArgument(int value) : base(value) public StartNumberArgument(int value) : base(value) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.StartNumber(Value); return $"-start_number {Value}";
} }
} }
} }

View file

@ -8,28 +8,19 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class ThreadsArgument : Argument<int> public class ThreadsArgument : Argument<int>
{ {
public ThreadsArgument() public ThreadsArgument() { }
{
}
public ThreadsArgument(int value) : base(value) public ThreadsArgument(int value) : base(value) { }
{
}
public ThreadsArgument(bool isMultiThreaded) : public ThreadsArgument(bool isMultiThreaded) :
base(isMultiThreaded base(isMultiThreaded
? Environment.ProcessorCount ? Environment.ProcessorCount
: 1) : 1) { }
{
}
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Threads(Value); return $"-threads {Value}";
} }
} }
} }

View file

@ -15,9 +15,10 @@ public VariableBitRateArgument(int vbr) : base(vbr)
} }
} }
/// <inheritdoc/>
public override string GetStringValue() public override string GetStringValue()
{ {
return $"-vbr {Value} "; return $"-vbr {Value}";
} }
} }
} }

View file

@ -9,26 +9,26 @@ public class VideoCodecArgument : Argument<VideoCodec>
{ {
public int Bitrate { get; protected set; } = 0; public int Bitrate { get; protected set; } = 0;
public VideoCodecArgument() public VideoCodecArgument() { }
{
}
public VideoCodecArgument(VideoCodec value) : base(value) public VideoCodecArgument(VideoCodec value) : base(value) { }
{
}
public VideoCodecArgument(VideoCodec value, int bitrate) : base(value) public VideoCodecArgument(VideoCodec value, int bitrate) : base(value)
{ {
Bitrate = bitrate; Bitrate = bitrate;
} }
/// <summary> /// <inheritdoc/>
/// String representation of the argument
/// </summary>
/// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentStringifier.Video(Value, Bitrate); var video = $"-c:v {Value.ToString().ToLower()} -pix_fmt yuv420p";
if (Bitrate != default)
{
video += $" -b:v {Bitrate}k";
}
return video;
} }
} }
} }

View file

@ -20,28 +20,8 @@ public string BuildArguments(ArgumentContainer container)
{ {
if (!container.ContainsInputOutput()) if (!container.ContainsInputOutput())
throw new ArgumentException("No input or output parameter found", nameof(container)); throw new ArgumentException("No input or output parameter found", nameof(container));
return string.Join(" ", container.Select(argument => argument.Value.GetStringValue().Trim())); return string.Join(" ", container.Select(argument => argument.Value.GetStringValue()));
}
private void CheckExtensionOfOutputExtension(ArgumentContainer container, FileInfo output)
{
if(container.ContainsKey(typeof(VideoCodecArgument)))
{
var codec = (VideoCodecArgument)container[typeof(VideoCodecArgument)];
FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.ForCodec(codec.Value));
}
}
private Argument GetInput(ArgumentContainer container)
{
if (container.ContainsKey(typeof(InputArgument)))
return container[typeof(InputArgument)];
else if (container.ContainsKey(typeof(ConcatArgument)))
return container[typeof(ConcatArgument)];
else
throw new ArgumentException("No inputs found");
} }
} }
} }

View file

@ -2,10 +2,10 @@
{ {
public enum VideoSize public enum VideoSize
{ {
Hd = 720,
FullHd = 1080, FullHd = 1080,
Hd = 720,
Ed = 480, Ed = 480,
Ld = 360, Ld = 360,
Original Original = -1
} }
} }

View file

@ -46,9 +46,7 @@ public ImageInfo(FileInfo fileInfo)
/// Create a image information object from a target path. /// Create a image information object from a target path.
/// </summary> /// </summary>
/// <param name="path">Path to image.</param> /// <param name="path">Path to image.</param>
public ImageInfo(string path) : this(new FileInfo(path)) public ImageInfo(string path) : this(new FileInfo(path)) { }
{
}
/// <summary> /// <summary>
/// Aspect ratio. /// Aspect ratio.

View file

@ -28,9 +28,7 @@ public VideoInfo(FileInfo fileInfo)
/// Create a video information object from a target path. /// Create a video information object from a target path.
/// </summary> /// </summary>
/// <param name="path">Path to video.</param> /// <param name="path">Path to video.</param>
public VideoInfo(string path) : this(new FileInfo(path)) public VideoInfo(string path) : this(new FileInfo(path)) { }
{
}
/// <summary> /// <summary>
/// Duration of the video file. /// Duration of the video file.