mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 00:24:14 +01:00
FFMpegCore: move argument implementations to seperate folder
This commit is contained in:
parent
3729d65e24
commit
8272dc9c94
31 changed files with 180 additions and 183 deletions
|
@ -1,4 +1,4 @@
|
|||
using FFMpegCore.FFMPEG.Arguments;
|
||||
using FFMpegCore.FFMPEG.Argument;
|
||||
using FFMpegCore.FFMPEG.Enums;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
@ -24,7 +24,7 @@ public ArgumentBuilderTests() : base()
|
|||
|
||||
private string GetArgumentsString(params Argument[] args)
|
||||
{
|
||||
var container = new ArgumentsContainer();
|
||||
var container = new ArgumentContainer();
|
||||
container.Add(new InputArgument("input.mp4"));
|
||||
foreach (var a in args)
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ public void Builder_BuildString_BitStream()
|
|||
[TestMethod]
|
||||
public void Builder_BuildString_Concat()
|
||||
{
|
||||
var container = new ArgumentsContainer();
|
||||
var container = new ArgumentContainer();
|
||||
|
||||
container.Add(new ConcatArgument(concatFiles));
|
||||
container.Add(new OutputArgument("output.mp4"));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using FFMpegCore.Enums;
|
||||
using FFMpegCore.FFMPEG;
|
||||
using FFMpegCore.FFMPEG.Arguments;
|
||||
using FFMpegCore.FFMPEG.Argument;
|
||||
using FFMpegCore.FFMPEG.Enums;
|
||||
using FFMpegCore.Tests.Resources;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
@ -61,7 +61,7 @@ public bool Convert(VideoType type, bool multithreaded = false, VideoSize size =
|
|||
}
|
||||
}
|
||||
|
||||
public void Convert(VideoType type, ArgumentsContainer container)
|
||||
public void Convert(VideoType type, ArgumentContainer container)
|
||||
{
|
||||
var output = Input.OutputLocation(type);
|
||||
|
||||
|
@ -69,7 +69,7 @@ public void Convert(VideoType type, ArgumentsContainer container)
|
|||
{
|
||||
var input = VideoInfo.FromFileInfo(Input);
|
||||
|
||||
var arguments = new ArgumentsContainer();
|
||||
var arguments = new ArgumentContainer();
|
||||
arguments.Add(new InputArgument(input));
|
||||
foreach (var arg in container)
|
||||
{
|
||||
|
@ -122,7 +122,7 @@ public void Video_ToMP4()
|
|||
[TestMethod]
|
||||
public void Video_ToMP4_Args()
|
||||
{
|
||||
var container = new ArgumentsContainer();
|
||||
var container = new ArgumentContainer();
|
||||
container.Add(new VideoCodecArgument(VideoCodec.LibX264));
|
||||
Convert(VideoType.Mp4, container);
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public void Video_ToTS()
|
|||
[TestMethod]
|
||||
public void Video_ToTS_Args()
|
||||
{
|
||||
var container = new ArgumentsContainer();
|
||||
var container = new ArgumentContainer();
|
||||
container.Add(new CopyArgument());
|
||||
container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB));
|
||||
container.Add(new ForceFormatArgument(VideoCodec.MpegTs));
|
||||
|
@ -153,7 +153,7 @@ public void Video_ToOGV_Resize()
|
|||
[TestMethod]
|
||||
public void Video_ToOGV_Resize_Args()
|
||||
{
|
||||
var container = new ArgumentsContainer();
|
||||
var container = new ArgumentContainer();
|
||||
container.Add(new ScaleArgument(VideoSize.Ed));
|
||||
container.Add(new VideoCodecArgument(VideoCodec.LibTheora));
|
||||
Convert(VideoType.Ogv, container);
|
||||
|
@ -168,7 +168,7 @@ public void Video_ToMP4_Resize()
|
|||
[TestMethod]
|
||||
public void Video_ToMP4_Resize_Args()
|
||||
{
|
||||
var container = new ArgumentsContainer();
|
||||
var container = new ArgumentContainer();
|
||||
container.Add(new ScaleArgument(VideoSize.Ld));
|
||||
container.Add(new VideoCodecArgument(VideoCodec.LibX264));
|
||||
Convert(VideoType.Mp4, container);
|
||||
|
|
|
@ -18,10 +18,6 @@ public static VideoInfo AddAudio(this Bitmap poster, FileInfo audio, FileInfo ou
|
|||
{
|
||||
return new FFMpeg().PosterWithAudio(tempFile, audio, output);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
tempFile.Delete();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class implements basic functionality of ffmpeg arguments
|
|
@ -5,29 +5,34 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Container of arguments represented parameters of FFMPEG process
|
||||
/// </summary>
|
||||
public class ArgumentsContainer : IDictionary<Type, Argument>
|
||||
public class ArgumentContainer : IDictionary<Type, Argument>
|
||||
{
|
||||
Dictionary<Type, Argument> _args;
|
||||
IDictionary<Type, Argument> _args;
|
||||
|
||||
public ArgumentsContainer()
|
||||
public ArgumentContainer(params Argument[] arguments)
|
||||
{
|
||||
_args = new Dictionary<Type, Argument>();
|
||||
|
||||
foreach(var argument in arguments)
|
||||
{
|
||||
this.Add(argument);
|
||||
}
|
||||
}
|
||||
|
||||
public Argument this[Type key] { get => ((IDictionary<Type, Argument>)_args)[key]; set => ((IDictionary<Type, Argument>)_args)[key] = value; }
|
||||
public Argument this[Type key] { get => _args[key]; set => _args[key] = value; }
|
||||
|
||||
public ICollection<Type> Keys => ((IDictionary<Type, Argument>)_args).Keys;
|
||||
public ICollection<Type> Keys => _args.Keys;
|
||||
|
||||
public ICollection<Argument> Values => ((IDictionary<Type, Argument>)_args).Values;
|
||||
public ICollection<Argument> Values => _args.Values;
|
||||
|
||||
public int Count => ((IDictionary<Type, Argument>)_args).Count;
|
||||
public int Count => _args.Count;
|
||||
|
||||
public bool IsReadOnly => ((IDictionary<Type, Argument>)_args).IsReadOnly;
|
||||
public bool IsReadOnly => _args.IsReadOnly;
|
||||
|
||||
/// <summary>
|
||||
/// This method is not supported, left for <see cref="{IDictionary<Type, Argument>}"/> interface support
|
||||
|
@ -48,7 +53,7 @@ public void Add(Type key, Argument value)
|
|||
[Obsolete]
|
||||
public void Add(KeyValuePair<Type, Argument> item)
|
||||
{
|
||||
throw new InvalidOperationException("Not supported operation");
|
||||
this.Add(item.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -56,7 +61,7 @@ public void Add(KeyValuePair<Type, Argument> item)
|
|||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
((IDictionary<Type, Argument>)_args).Clear();
|
||||
_args.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -66,16 +71,19 @@ public void Clear()
|
|||
/// <returns>Returns if contains item</returns>
|
||||
public bool Contains(KeyValuePair<Type, Argument> item)
|
||||
{
|
||||
return ((IDictionary<Type, Argument>)_args).Contains(item);
|
||||
return _args.Contains(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds argument to collection
|
||||
/// </summary>
|
||||
/// <param name="value">Argument that should be added to collection</param>
|
||||
public void Add(Argument value)
|
||||
public void Add(params Argument[] values)
|
||||
{
|
||||
((IDictionary<Type, Argument>)_args).Add(value.GetType(), value);
|
||||
foreach(var value in values)
|
||||
{
|
||||
_args.Add(value.GetType(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -96,37 +104,37 @@ public bool ContainsInputOutput()
|
|||
/// <returns></returns>
|
||||
public bool ContainsKey(Type key)
|
||||
{
|
||||
return ((IDictionary<Type, Argument>)_args).ContainsKey(key);
|
||||
return _args.ContainsKey(key);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<Type, Argument>[] array, int arrayIndex)
|
||||
{
|
||||
((IDictionary<Type, Argument>)_args).CopyTo(array, arrayIndex);
|
||||
_args.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<Type, Argument>> GetEnumerator()
|
||||
{
|
||||
return ((IDictionary<Type, Argument>)_args).GetEnumerator();
|
||||
return _args.GetEnumerator();
|
||||
}
|
||||
|
||||
public bool Remove(Type key)
|
||||
{
|
||||
return ((IDictionary<Type, Argument>)_args).Remove(key);
|
||||
return _args.Remove(key);
|
||||
}
|
||||
|
||||
public bool Remove(KeyValuePair<Type, Argument> item)
|
||||
{
|
||||
return ((IDictionary<Type, Argument>)_args).Remove(item);
|
||||
return _args.Remove(item);
|
||||
}
|
||||
|
||||
public bool TryGetValue(Type key, out Argument value)
|
||||
{
|
||||
return ((IDictionary<Type, Argument>)_args).TryGetValue(key, out value);
|
||||
return _args.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IDictionary<Type, Argument>)_args).GetEnumerator();
|
||||
return _args.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
|
@ -4,9 +4,9 @@
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
internal static class ArgumentsStringifier
|
||||
internal static class ArgumentStringifier
|
||||
{
|
||||
internal static string Speed(Speed speed)
|
||||
{
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents parameter of audio codec and it's quality
|
||||
|
@ -41,7 +41,7 @@ public AudioCodecArgument(AudioCodec value, int bitrate) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Audio(Value, Bitrate);
|
||||
return ArgumentStringifier.Audio(Value, Bitrate);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents parameter of bitstream filter
|
||||
|
@ -26,7 +26,7 @@ public BitStreamFilterArgument(Channel first, Filter second) : base(first, secon
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.BitStreamFilter(First, Second);
|
||||
return ArgumentStringifier.BitStreamFilter(First, Second);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
@ -34,7 +34,7 @@ public IEnumerator<string> GetEnumerator()
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.InputConcat(Value);
|
||||
return ArgumentStringifier.InputConcat(Value);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents parameter of copy parameter
|
||||
|
@ -28,7 +28,7 @@ public CopyArgument(Channel value = Channel.Both) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Copy(Value);
|
||||
return ArgumentStringifier.Copy(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents cpu speed parameter
|
||||
|
@ -25,7 +25,7 @@ public CpuSpeedArgument(int value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Speed(Value);
|
||||
return ArgumentStringifier.Speed(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using FFMpegCore.FFMPEG.Enums;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents cpu speed parameter
|
||||
|
@ -21,7 +21,7 @@ public DisableChannelArgument(Channel value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Disable(Value);
|
||||
return ArgumentStringifier.Disable(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents force format parameter
|
||||
|
@ -26,7 +26,7 @@ public ForceFormatArgument(VideoCodec value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.ForceFormat(Value);
|
||||
return ArgumentStringifier.ForceFormat(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents frame output count parameter
|
||||
|
@ -25,7 +25,7 @@ public FrameOutputCountArgument(int value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.FrameOutputCount(Value);
|
||||
return ArgumentStringifier.FrameOutputCount(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents frame rate parameter
|
||||
|
@ -25,7 +25,7 @@ public FrameRateArgument(double value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.FrameRate(Value);
|
||||
return ArgumentStringifier.FrameRate(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents input parameter
|
||||
|
@ -38,7 +38,7 @@ public InputArgument(params Uri[] values) : base(values.Select(v => v.AbsolutePa
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return string.Join(" ", Value.Select(v => ArgumentsStringifier.Input(v)));
|
||||
return string.Join(" ", Value.Select(v => ArgumentStringifier.Input(v)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents loop parameter
|
||||
|
@ -25,7 +25,7 @@ public LoopArgument(int value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Loop(Value);
|
||||
return ArgumentStringifier.Loop(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents output parameter
|
||||
|
@ -38,7 +38,7 @@ public OutputArgument(Uri value) : base(value.AbsolutePath)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Output(Value);
|
||||
return ArgumentStringifier.Output(Value);
|
||||
}
|
||||
|
||||
public FileInfo GetAsFileInfo()
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents override parameter
|
|
@ -6,7 +6,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents scale parameter
|
||||
|
@ -36,7 +36,7 @@ public ScaleArgument(VideoSize videosize)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Scale(Value);
|
||||
return ArgumentStringifier.Scale(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents seek parameter
|
||||
|
@ -25,7 +25,7 @@ public SeekArgument(TimeSpan? value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Seek(Value);
|
||||
return ArgumentStringifier.Seek(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents shortest parameter
|
||||
|
@ -25,7 +25,7 @@ public ShortestArgument(bool value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.FinalizeAtShortestInput(Value);
|
||||
return ArgumentStringifier.FinalizeAtShortestInput(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using FFMpegCore.FFMPEG.Enums;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents size parameter
|
||||
|
@ -35,7 +35,7 @@ public SizeArgument(int width, int heignt) : base(width, heignt)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Size(Value);
|
||||
return ArgumentStringifier.Size(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents speed parameter
|
||||
|
@ -26,7 +26,7 @@ public SpeedArgument(Speed value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Speed(Value);
|
||||
return ArgumentStringifier.Speed(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents start number parameter
|
||||
|
@ -25,7 +25,7 @@ public StartNumberArgument(int value) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.StartNumber(Value);
|
||||
return ArgumentStringifier.StartNumber(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents threads parameter
|
||||
|
@ -33,7 +33,7 @@ public ThreadsArgument(bool isMultiThreaded) :
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Threads(Value);
|
||||
return ArgumentStringifier.Threads(Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents video codec parameter
|
||||
|
@ -33,7 +33,7 @@ public VideoCodecArgument(VideoCodec value, int bitrate) : base(value)
|
|||
/// <returns>String representation of the argument</returns>
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return ArgumentsStringifier.Video(Value, Bitrate);
|
||||
return ArgumentStringifier.Video(Value, Bitrate);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +1,31 @@
|
|||
using FFMpegCore.Enums;
|
||||
using FFMpegCore.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds parameters string from <see cref="ArgumentsContainer"/> that would be passed to ffmpeg process
|
||||
/// Builds parameters string from <see cref="ArgumentContainer"/> that would be passed to ffmpeg process
|
||||
/// </summary>
|
||||
public class FFArgumentBuilder : IArgumentBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds parameters string from <see cref="ArgumentsContainer"/> that would be passed to ffmpeg process
|
||||
/// Builds parameters string from <see cref="ArgumentContainer"/> that would be passed to ffmpeg process
|
||||
/// </summary>
|
||||
/// <param name="container">Container of arguments</param>
|
||||
/// <returns>Parameters string</returns>
|
||||
public string BuildArguments(ArgumentsContainer container)
|
||||
public string BuildArguments(ArgumentContainer container)
|
||||
{
|
||||
if (!container.ContainsInputOutput())
|
||||
throw new ArgumentException("No input or output parameter found", nameof(container));
|
||||
|
||||
CheckContainerException(container);
|
||||
|
||||
|
||||
return string.Join(" ", container.Select(argument => argument.Value.GetStringValue().Trim()));
|
||||
}
|
||||
|
||||
private void CheckContainerException(ArgumentsContainer container)
|
||||
{
|
||||
// TODO: implement arguments check
|
||||
}
|
||||
|
||||
private void CheckExtensionOfOutputExtension(ArgumentsContainer container, FileInfo output)
|
||||
private void CheckExtensionOfOutputExtension(ArgumentContainer container, FileInfo output)
|
||||
{
|
||||
if(container.ContainsKey(typeof(VideoCodecArgument)))
|
||||
{
|
||||
|
@ -44,7 +34,7 @@ private void CheckExtensionOfOutputExtension(ArgumentsContainer container, FileI
|
|||
}
|
||||
}
|
||||
|
||||
private Argument GetInput(ArgumentsContainer container)
|
||||
private Argument GetInput(ArgumentContainer container)
|
||||
{
|
||||
if (container.ContainsKey(typeof(InputArgument)))
|
||||
return container[typeof(InputArgument)];
|
||||
|
@ -53,15 +43,5 @@ private Argument GetInput(ArgumentsContainer container)
|
|||
else
|
||||
throw new ArgumentException("No inputs found");
|
||||
}
|
||||
|
||||
private bool IsInputOrOutput(Argument arg)
|
||||
{
|
||||
return IsInputOrOutput(arg.GetType());
|
||||
}
|
||||
|
||||
private bool IsInputOrOutput(Type arg)
|
||||
{
|
||||
return (arg == typeof(InputArgument)) || (arg == typeof(ConcatArgument)) || (arg == typeof(OutputArgument)) || (arg == typeof(OverrideArgument));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,10 +6,10 @@
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFMpegCore.FFMPEG.Arguments
|
||||
namespace FFMpegCore.FFMPEG.Argument
|
||||
{
|
||||
public interface IArgumentBuilder
|
||||
{
|
||||
string BuildArguments(ArgumentsContainer container);
|
||||
string BuildArguments(ArgumentContainer container);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
using FFMpegCore.Enums;
|
||||
using FFMpegCore.FFMPEG.Arguments;
|
||||
using FFMpegCore.FFMPEG.Argument;
|
||||
using FFMpegCore.FFMPEG.Enums;
|
||||
using FFMpegCore.FFMPEG.Exceptions;
|
||||
using FFMpegCore.Helpers;
|
||||
|
@ -20,7 +20,7 @@ namespace FFMpegCore.FFMPEG
|
|||
|
||||
public class FFMpeg : FFBase
|
||||
{
|
||||
IArgumentBuilder argumentBuilder { get; set; }
|
||||
IArgumentBuilder ArgumentBuilder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Intializes the FFMPEG encoder.
|
||||
|
@ -28,13 +28,13 @@ public class FFMpeg : FFBase
|
|||
public FFMpeg()
|
||||
{
|
||||
_Init();
|
||||
argumentBuilder = new FFArgumentBuilder();
|
||||
ArgumentBuilder = new FFArgumentBuilder();
|
||||
}
|
||||
|
||||
public FFMpeg(IArgumentBuilder builder)
|
||||
{
|
||||
_Init();
|
||||
argumentBuilder = builder;
|
||||
ArgumentBuilder = builder;
|
||||
}
|
||||
|
||||
private void _Init()
|
||||
|
@ -91,13 +91,14 @@ public Bitmap Snapshot(VideoInfo source, FileInfo output, Size? size = null, Tim
|
|||
}
|
||||
|
||||
FFMpegHelper.ConversionExceptionCheck(source.ToFileInfo(), output);
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new InputArgument(source));
|
||||
container.Add(new VideoCodecArgument(VideoCodec.Png));
|
||||
container.Add(new FrameOutputCountArgument(1));
|
||||
container.Add(new SeekArgument(captureTime));
|
||||
container.Add(new SizeArgument(size));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new InputArgument(source),
|
||||
new VideoCodecArgument(VideoCodec.Png),
|
||||
new FrameOutputCountArgument(1),
|
||||
new SeekArgument(captureTime),
|
||||
new SizeArgument(size),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
if (!RunProcess(container, output))
|
||||
{
|
||||
|
@ -163,34 +164,40 @@ public VideoInfo Convert(
|
|||
outputSize.Width += 1;
|
||||
}
|
||||
|
||||
var container = new ArgumentsContainer();
|
||||
var container = new ArgumentContainer();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case VideoType.Mp4:
|
||||
container.Add(new InputArgument(source));
|
||||
container.Add(new ThreadsArgument(multithreaded));
|
||||
container.Add(new ScaleArgument(outputSize));
|
||||
container.Add(new VideoCodecArgument(VideoCodec.LibX264, 2400));
|
||||
container.Add(new SpeedArgument(speed));
|
||||
container.Add(new AudioCodecArgument(AudioCodec.Aac, audioQuality));
|
||||
container.Add(new OutputArgument(output));
|
||||
container.Add(
|
||||
new InputArgument(source),
|
||||
new ThreadsArgument(multithreaded),
|
||||
new ScaleArgument(outputSize),
|
||||
new VideoCodecArgument(VideoCodec.LibX264, 2400),
|
||||
new SpeedArgument(speed),
|
||||
new AudioCodecArgument(AudioCodec.Aac, audioQuality),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
break;
|
||||
case VideoType.Ogv:
|
||||
container.Add(new InputArgument(source));
|
||||
container.Add(new ThreadsArgument(multithreaded));
|
||||
container.Add(new ScaleArgument(outputSize));
|
||||
container.Add(new VideoCodecArgument(VideoCodec.LibTheora, 2400));
|
||||
container.Add(new SpeedArgument(speed));
|
||||
container.Add(new AudioCodecArgument(AudioCodec.LibVorbis, audioQuality));
|
||||
container.Add(new OutputArgument(output));
|
||||
container.Add(
|
||||
new InputArgument(source),
|
||||
new ThreadsArgument(multithreaded),
|
||||
new ScaleArgument(outputSize),
|
||||
new VideoCodecArgument(VideoCodec.LibTheora, 2400),
|
||||
new SpeedArgument(speed),
|
||||
new AudioCodecArgument(AudioCodec.LibVorbis, audioQuality),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
break;
|
||||
case VideoType.Ts:
|
||||
container.Add(new InputArgument(source));
|
||||
container.Add(new CopyArgument());
|
||||
container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB));
|
||||
container.Add(new ForceFormatArgument(VideoCodec.MpegTs));
|
||||
container.Add(new OutputArgument(output));
|
||||
container.Add(
|
||||
new InputArgument(source),
|
||||
new CopyArgument(),
|
||||
new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB),
|
||||
new ForceFormatArgument(VideoCodec.MpegTs),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -215,13 +222,14 @@ public VideoInfo PosterWithAudio(FileInfo image, FileInfo audio, FileInfo output
|
|||
FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.Mp4);
|
||||
FFMpegHelper.ConversionSizeExceptionCheck(Image.FromFile(image.FullName));
|
||||
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new LoopArgument(1));
|
||||
container.Add(new InputArgument(image.FullName, audio.FullName));
|
||||
container.Add(new VideoCodecArgument(VideoCodec.LibX264, 2400));
|
||||
container.Add(new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Normal));
|
||||
container.Add(new ShortestArgument(true));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new LoopArgument(1),
|
||||
new InputArgument(image.FullName, audio.FullName),
|
||||
new VideoCodecArgument(VideoCodec.LibX264, 2400),
|
||||
new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Normal),
|
||||
new ShortestArgument(true),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
if (!RunProcess(container, output))
|
||||
{
|
||||
|
@ -254,11 +262,12 @@ public VideoInfo Join(FileInfo output, params VideoInfo[] videos)
|
|||
return destinationPath;
|
||||
}).ToList();
|
||||
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new ConcatArgument(temporaryVideoParts));
|
||||
container.Add(new CopyArgument());
|
||||
container.Add(new BitStreamFilterArgument(Channel.Audio, Filter.Aac_AdtstoAsc));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new ConcatArgument(temporaryVideoParts),
|
||||
new CopyArgument(),
|
||||
new BitStreamFilterArgument(Channel.Audio, Filter.Aac_AdtstoAsc),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -295,14 +304,15 @@ public VideoInfo JoinImageSequence(FileInfo output, double frameRate = 30, param
|
|||
|
||||
var firstImage = images.First();
|
||||
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new FrameRateArgument(frameRate));
|
||||
container.Add(new SizeArgument(firstImage.Width, firstImage.Height));
|
||||
container.Add(new StartNumberArgument(0));
|
||||
container.Add(new InputArgument($"{firstImage.Directory}\\%09d.png"));
|
||||
container.Add(new FrameOutputCountArgument(images.Length));
|
||||
container.Add(new VideoCodecArgument(VideoCodec.LibX264));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new FrameRateArgument(frameRate),
|
||||
new SizeArgument(firstImage.Width, firstImage.Height),
|
||||
new StartNumberArgument(0),
|
||||
new InputArgument($"{firstImage.Directory}\\%09d.png"),
|
||||
new FrameOutputCountArgument(images.Length),
|
||||
new VideoCodecArgument(VideoCodec.LibX264),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -331,9 +341,10 @@ public VideoInfo SaveM3U8Stream(Uri uri, FileInfo output)
|
|||
|
||||
if (uri.Scheme == "http" || uri.Scheme == "https")
|
||||
{
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new InputArgument(uri));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new InputArgument(uri),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
if (!RunProcess(container, output))
|
||||
{
|
||||
|
@ -357,11 +368,12 @@ public VideoInfo Mute(VideoInfo source, FileInfo output)
|
|||
FFMpegHelper.ConversionSizeExceptionCheck(source);
|
||||
FFMpegHelper.ExtensionExceptionCheck(output, source.Extension);
|
||||
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new InputArgument(source));
|
||||
container.Add(new CopyArgument());
|
||||
container.Add(new DisableChannelArgument(Channel.Audio));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new InputArgument(source),
|
||||
new CopyArgument(),
|
||||
new DisableChannelArgument(Channel.Audio),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
if (!RunProcess(container, output))
|
||||
{
|
||||
|
@ -382,10 +394,11 @@ public FileInfo ExtractAudio(VideoInfo source, FileInfo output)
|
|||
FFMpegHelper.ConversionExceptionCheck(source.ToFileInfo(), output);
|
||||
FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.Mp3);
|
||||
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new InputArgument(source));
|
||||
container.Add(new DisableChannelArgument(Channel.Video));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new InputArgument(source),
|
||||
new DisableChannelArgument(Channel.Video),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
if (!RunProcess(container, output))
|
||||
{
|
||||
|
@ -412,13 +425,13 @@ public VideoInfo ReplaceAudio(VideoInfo source, FileInfo audio, FileInfo output,
|
|||
FFMpegHelper.ConversionSizeExceptionCheck(source);
|
||||
FFMpegHelper.ExtensionExceptionCheck(output, source.Extension);
|
||||
|
||||
var container = new ArgumentsContainer();
|
||||
container.Add(new InputArgument(source.FullName, audio.FullName));
|
||||
//container.Add(new InputArgument(audio));
|
||||
container.Add(new CopyArgument());
|
||||
container.Add(new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Hd));
|
||||
container.Add(new ShortestArgument(stopAtShortest));
|
||||
container.Add(new OutputArgument(output));
|
||||
var container = new ArgumentContainer(
|
||||
new InputArgument(source.FullName, audio.FullName),
|
||||
new CopyArgument(),
|
||||
new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Hd),
|
||||
new ShortestArgument(stopAtShortest),
|
||||
new OutputArgument(output)
|
||||
);
|
||||
|
||||
if (!RunProcess(container, output))
|
||||
{
|
||||
|
@ -428,9 +441,9 @@ public VideoInfo ReplaceAudio(VideoInfo source, FileInfo audio, FileInfo output,
|
|||
return new VideoInfo(output);
|
||||
}
|
||||
|
||||
public VideoInfo Convert(ArgumentsContainer arguments)
|
||||
public VideoInfo Convert(ArgumentContainer arguments)
|
||||
{
|
||||
var args = argumentBuilder.BuildArguments(arguments);
|
||||
var args = ArgumentBuilder.BuildArguments(arguments);
|
||||
var output = ((OutputArgument)arguments[typeof(OutputArgument)]).GetAsFileInfo();
|
||||
|
||||
if (!RunProcess(arguments, output))
|
||||
|
@ -459,11 +472,11 @@ public void Stop()
|
|||
|
||||
private volatile StringBuilder _errorOutput = new StringBuilder();
|
||||
|
||||
private bool RunProcess(ArgumentsContainer container, FileInfo output)
|
||||
private bool RunProcess(ArgumentContainer container, FileInfo output)
|
||||
{
|
||||
var successState = true;
|
||||
|
||||
CreateProcess(this.argumentBuilder.BuildArguments(container), _ffmpegPath, true, rStandardError: true);
|
||||
CreateProcess(this.ArgumentBuilder.BuildArguments(container), _ffmpegPath, true, rStandardError: true);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
0
FFMpegCore/FFMPEG/ProbeInfo.cs
Normal file
0
FFMpegCore/FFMPEG/ProbeInfo.cs
Normal file
Loading…
Reference in a new issue