FFMpegCore: move argument implementations to seperate folder

This commit is contained in:
Vlad Jerca 2019-02-09 16:20:04 +02:00
parent 3729d65e24
commit 8272dc9c94
31 changed files with 180 additions and 183 deletions

View file

@ -1,4 +1,4 @@
using FFMpegCore.FFMPEG.Arguments; using FFMpegCore.FFMPEG.Argument;
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.FFMPEG.Enums;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System; using System;
@ -24,7 +24,7 @@ public ArgumentBuilderTests() : base()
private string GetArgumentsString(params Argument[] args) private string GetArgumentsString(params Argument[] args)
{ {
var container = new ArgumentsContainer(); var container = new ArgumentContainer();
container.Add(new InputArgument("input.mp4")); container.Add(new InputArgument("input.mp4"));
foreach (var a in args) foreach (var a in args)
{ {
@ -70,7 +70,7 @@ public void Builder_BuildString_BitStream()
[TestMethod] [TestMethod]
public void Builder_BuildString_Concat() public void Builder_BuildString_Concat()
{ {
var container = new ArgumentsContainer(); var container = new ArgumentContainer();
container.Add(new ConcatArgument(concatFiles)); container.Add(new ConcatArgument(concatFiles));
container.Add(new OutputArgument("output.mp4")); container.Add(new OutputArgument("output.mp4"));

View file

@ -1,6 +1,6 @@
using FFMpegCore.Enums; using FFMpegCore.Enums;
using FFMpegCore.FFMPEG; using FFMpegCore.FFMPEG;
using FFMpegCore.FFMPEG.Arguments; using FFMpegCore.FFMPEG.Argument;
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.FFMPEG.Enums;
using FFMpegCore.Tests.Resources; using FFMpegCore.Tests.Resources;
using Microsoft.VisualStudio.TestTools.UnitTesting; 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); var output = Input.OutputLocation(type);
@ -69,7 +69,7 @@ public void Convert(VideoType type, ArgumentsContainer container)
{ {
var input = VideoInfo.FromFileInfo(Input); var input = VideoInfo.FromFileInfo(Input);
var arguments = new ArgumentsContainer(); var arguments = new ArgumentContainer();
arguments.Add(new InputArgument(input)); arguments.Add(new InputArgument(input));
foreach (var arg in container) foreach (var arg in container)
{ {
@ -122,7 +122,7 @@ public void Video_ToMP4()
[TestMethod] [TestMethod]
public void Video_ToMP4_Args() public void Video_ToMP4_Args()
{ {
var container = new ArgumentsContainer(); var container = new ArgumentContainer();
container.Add(new VideoCodecArgument(VideoCodec.LibX264)); container.Add(new VideoCodecArgument(VideoCodec.LibX264));
Convert(VideoType.Mp4, container); Convert(VideoType.Mp4, container);
} }
@ -136,7 +136,7 @@ public void Video_ToTS()
[TestMethod] [TestMethod]
public void Video_ToTS_Args() public void Video_ToTS_Args()
{ {
var container = new ArgumentsContainer(); var container = new ArgumentContainer();
container.Add(new CopyArgument()); container.Add(new CopyArgument());
container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB)); container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB));
container.Add(new ForceFormatArgument(VideoCodec.MpegTs)); container.Add(new ForceFormatArgument(VideoCodec.MpegTs));
@ -153,7 +153,7 @@ public void Video_ToOGV_Resize()
[TestMethod] [TestMethod]
public void Video_ToOGV_Resize_Args() public void Video_ToOGV_Resize_Args()
{ {
var container = new ArgumentsContainer(); var container = new ArgumentContainer();
container.Add(new ScaleArgument(VideoSize.Ed)); container.Add(new ScaleArgument(VideoSize.Ed));
container.Add(new VideoCodecArgument(VideoCodec.LibTheora)); container.Add(new VideoCodecArgument(VideoCodec.LibTheora));
Convert(VideoType.Ogv, container); Convert(VideoType.Ogv, container);
@ -168,7 +168,7 @@ public void Video_ToMP4_Resize()
[TestMethod] [TestMethod]
public void Video_ToMP4_Resize_Args() public void Video_ToMP4_Resize_Args()
{ {
var container = new ArgumentsContainer(); var container = new ArgumentContainer();
container.Add(new ScaleArgument(VideoSize.Ld)); container.Add(new ScaleArgument(VideoSize.Ld));
container.Add(new VideoCodecArgument(VideoCodec.LibX264)); container.Add(new VideoCodecArgument(VideoCodec.LibX264));
Convert(VideoType.Mp4, container); Convert(VideoType.Mp4, container);

View file

@ -18,10 +18,6 @@ public static VideoInfo AddAudio(this Bitmap poster, FileInfo audio, FileInfo ou
{ {
return new FFMpeg().PosterWithAudio(tempFile, audio, output); return new FFMpeg().PosterWithAudio(tempFile, audio, output);
} }
catch(Exception e)
{
throw;
}
finally finally
{ {
tempFile.Delete(); tempFile.Delete();

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Abstract class implements basic functionality of ffmpeg arguments /// Abstract class implements basic functionality of ffmpeg arguments

View file

@ -5,29 +5,34 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Container of arguments represented parameters of FFMPEG process /// Container of arguments represented parameters of FFMPEG process
/// </summary> /// </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>(); _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> /// <summary>
/// This method is not supported, left for <see cref="{IDictionary<Type, Argument>}"/> interface support /// 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] [Obsolete]
public void Add(KeyValuePair<Type, Argument> item) public void Add(KeyValuePair<Type, Argument> item)
{ {
throw new InvalidOperationException("Not supported operation"); this.Add(item.Value);
} }
/// <summary> /// <summary>
@ -56,7 +61,7 @@ public void Add(KeyValuePair<Type, Argument> item)
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {
((IDictionary<Type, Argument>)_args).Clear(); _args.Clear();
} }
/// <summary> /// <summary>
@ -66,16 +71,19 @@ public void Clear()
/// <returns>Returns if contains item</returns> /// <returns>Returns if contains item</returns>
public bool Contains(KeyValuePair<Type, Argument> item) public bool Contains(KeyValuePair<Type, Argument> item)
{ {
return ((IDictionary<Type, Argument>)_args).Contains(item); return _args.Contains(item);
} }
/// <summary> /// <summary>
/// Adds argument to collection /// Adds argument to collection
/// </summary> /// </summary>
/// <param name="value">Argument that should be added to collection</param> /// <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> /// <summary>
@ -96,37 +104,37 @@ public bool ContainsInputOutput()
/// <returns></returns> /// <returns></returns>
public bool ContainsKey(Type key) 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) 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() public IEnumerator<KeyValuePair<Type, Argument>> GetEnumerator()
{ {
return ((IDictionary<Type, Argument>)_args).GetEnumerator(); return _args.GetEnumerator();
} }
public bool Remove(Type key) public bool Remove(Type key)
{ {
return ((IDictionary<Type, Argument>)_args).Remove(key); return _args.Remove(key);
} }
public bool Remove(KeyValuePair<Type, Argument> item) 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) 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() IEnumerator IEnumerable.GetEnumerator()
{ {
return ((IDictionary<Type, Argument>)_args).GetEnumerator(); return _args.GetEnumerator();
} }
/// <summary> /// <summary>

View file

@ -4,9 +4,9 @@
using System.Drawing; using System.Drawing;
using System.IO; 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) internal static string Speed(Speed speed)
{ {

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents parameter of audio codec and it's quality /// 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> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Audio(Value, Bitrate); return ArgumentStringifier.Audio(Value, Bitrate);
} }
} }
} }

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents parameter of bitstream filter /// 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> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.BitStreamFilter(First, Second); return ArgumentStringifier.BitStreamFilter(First, Second);
} }
} }
} }

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
@ -34,7 +34,7 @@ public IEnumerator<string> GetEnumerator()
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.InputConcat(Value); return ArgumentStringifier.InputConcat(Value);
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents parameter of copy parameter /// Represents parameter of copy parameter
@ -28,7 +28,7 @@ public CopyArgument(Channel value = Channel.Both) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Copy(Value); return ArgumentStringifier.Copy(Value);
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents cpu speed parameter /// Represents cpu speed parameter
@ -25,7 +25,7 @@ public CpuSpeedArgument(int value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Speed(Value); return ArgumentStringifier.Speed(Value);
} }
} }
} }

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.FFMPEG.Enums;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents cpu speed parameter /// Represents cpu speed parameter
@ -21,7 +21,7 @@ public DisableChannelArgument(Channel value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Disable(Value); return ArgumentStringifier.Disable(Value);
} }
} }
} }

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents force format parameter /// Represents force format parameter
@ -26,7 +26,7 @@ public ForceFormatArgument(VideoCodec value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.ForceFormat(Value); return ArgumentStringifier.ForceFormat(Value);
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents frame output count parameter /// Represents frame output count parameter
@ -25,7 +25,7 @@ public FrameOutputCountArgument(int value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.FrameOutputCount(Value); return ArgumentStringifier.FrameOutputCount(Value);
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents frame rate parameter /// Represents frame rate parameter
@ -25,7 +25,7 @@ public FrameRateArgument(double value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.FrameRate(Value); return ArgumentStringifier.FrameRate(Value);
} }
} }
} }

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents input parameter /// 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> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return string.Join(" ", Value.Select(v => ArgumentsStringifier.Input(v))); return string.Join(" ", Value.Select(v => ArgumentStringifier.Input(v)));
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents loop parameter /// Represents loop parameter
@ -25,7 +25,7 @@ public LoopArgument(int value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Loop(Value); return ArgumentStringifier.Loop(Value);
} }
} }
} }

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents output parameter /// Represents output parameter
@ -38,7 +38,7 @@ public OutputArgument(Uri value) : base(value.AbsolutePath)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Output(Value); return ArgumentStringifier.Output(Value);
} }
public FileInfo GetAsFileInfo() public FileInfo GetAsFileInfo()

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents override parameter /// Represents override parameter

View file

@ -6,7 +6,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents scale parameter /// Represents scale parameter
@ -36,7 +36,7 @@ public ScaleArgument(VideoSize videosize)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Scale(Value); return ArgumentStringifier.Scale(Value);
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents seek parameter /// Represents seek parameter
@ -25,7 +25,7 @@ public SeekArgument(TimeSpan? value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Seek(Value); return ArgumentStringifier.Seek(Value);
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents shortest parameter /// Represents shortest parameter
@ -25,7 +25,7 @@ public ShortestArgument(bool value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.FinalizeAtShortestInput(Value); return ArgumentStringifier.FinalizeAtShortestInput(Value);
} }
} }
} }

View file

@ -6,7 +6,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.FFMPEG.Enums;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents size parameter /// Represents size parameter
@ -35,7 +35,7 @@ public SizeArgument(int width, int heignt) : base(width, heignt)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Size(Value); return ArgumentStringifier.Size(Value);
} }
} }
} }

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents speed parameter /// Represents speed parameter
@ -26,7 +26,7 @@ public SpeedArgument(Speed value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Speed(Value); return ArgumentStringifier.Speed(Value);
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents start number parameter /// Represents start number parameter
@ -25,7 +25,7 @@ public StartNumberArgument(int value) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.StartNumber(Value); return ArgumentStringifier.StartNumber(Value);
} }
} }
} }

View file

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents threads parameter /// Represents threads parameter
@ -33,7 +33,7 @@ public ThreadsArgument(bool isMultiThreaded) :
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Threads(Value); return ArgumentStringifier.Threads(Value);
} }
} }
} }

View file

@ -5,7 +5,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <summary>
/// Represents video codec parameter /// Represents video codec parameter
@ -33,7 +33,7 @@ public VideoCodecArgument(VideoCodec value, int bitrate) : base(value)
/// <returns>String representation of the argument</returns> /// <returns>String representation of the argument</returns>
public override string GetStringValue() public override string GetStringValue()
{ {
return ArgumentsStringifier.Video(Value, Bitrate); return ArgumentStringifier.Video(Value, Bitrate);
} }
} }
} }

View file

@ -1,41 +1,31 @@
using FFMpegCore.Enums; using FFMpegCore.Enums;
using FFMpegCore.Helpers; using FFMpegCore.Helpers;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
/// <summary> /// <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> /// </summary>
public class FFArgumentBuilder : IArgumentBuilder public class FFArgumentBuilder : IArgumentBuilder
{ {
/// <summary> /// <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> /// </summary>
/// <param name="container">Container of arguments</param> /// <param name="container">Container of arguments</param>
/// <returns>Parameters string</returns> /// <returns>Parameters string</returns>
public string BuildArguments(ArgumentsContainer container) 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));
CheckContainerException(container);
return string.Join(" ", container.Select(argument => argument.Value.GetStringValue().Trim())); return string.Join(" ", container.Select(argument => argument.Value.GetStringValue().Trim()));
} }
private void CheckContainerException(ArgumentsContainer container) private void CheckExtensionOfOutputExtension(ArgumentContainer container, FileInfo output)
{
// TODO: implement arguments check
}
private void CheckExtensionOfOutputExtension(ArgumentsContainer container, FileInfo output)
{ {
if(container.ContainsKey(typeof(VideoCodecArgument))) 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))) if (container.ContainsKey(typeof(InputArgument)))
return container[typeof(InputArgument)]; return container[typeof(InputArgument)];
@ -53,15 +43,5 @@ private Argument GetInput(ArgumentsContainer container)
else else
throw new ArgumentException("No inputs found"); 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));
}
} }
} }

View file

@ -6,10 +6,10 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Arguments namespace FFMpegCore.FFMPEG.Argument
{ {
public interface IArgumentBuilder public interface IArgumentBuilder
{ {
string BuildArguments(ArgumentsContainer container); string BuildArguments(ArgumentContainer container);
} }
} }

View file

@ -1,5 +1,5 @@
using FFMpegCore.Enums; using FFMpegCore.Enums;
using FFMpegCore.FFMPEG.Arguments; using FFMpegCore.FFMPEG.Argument;
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.FFMPEG.Enums;
using FFMpegCore.FFMPEG.Exceptions; using FFMpegCore.FFMPEG.Exceptions;
using FFMpegCore.Helpers; using FFMpegCore.Helpers;
@ -20,7 +20,7 @@ namespace FFMpegCore.FFMPEG
public class FFMpeg : FFBase public class FFMpeg : FFBase
{ {
IArgumentBuilder argumentBuilder { get; set; } IArgumentBuilder ArgumentBuilder { get; set; }
/// <summary> /// <summary>
/// Intializes the FFMPEG encoder. /// Intializes the FFMPEG encoder.
@ -28,13 +28,13 @@ public class FFMpeg : FFBase
public FFMpeg() public FFMpeg()
{ {
_Init(); _Init();
argumentBuilder = new FFArgumentBuilder(); ArgumentBuilder = new FFArgumentBuilder();
} }
public FFMpeg(IArgumentBuilder builder) public FFMpeg(IArgumentBuilder builder)
{ {
_Init(); _Init();
argumentBuilder = builder; ArgumentBuilder = builder;
} }
private void _Init() private void _Init()
@ -91,13 +91,14 @@ public Bitmap Snapshot(VideoInfo source, FileInfo output, Size? size = null, Tim
} }
FFMpegHelper.ConversionExceptionCheck(source.ToFileInfo(), output); FFMpegHelper.ConversionExceptionCheck(source.ToFileInfo(), output);
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new InputArgument(source)); new InputArgument(source),
container.Add(new VideoCodecArgument(VideoCodec.Png)); new VideoCodecArgument(VideoCodec.Png),
container.Add(new FrameOutputCountArgument(1)); new FrameOutputCountArgument(1),
container.Add(new SeekArgument(captureTime)); new SeekArgument(captureTime),
container.Add(new SizeArgument(size)); new SizeArgument(size),
container.Add(new OutputArgument(output)); new OutputArgument(output)
);
if (!RunProcess(container, output)) if (!RunProcess(container, output))
{ {
@ -163,34 +164,40 @@ public VideoInfo Convert(
outputSize.Width += 1; outputSize.Width += 1;
} }
var container = new ArgumentsContainer(); var container = new ArgumentContainer();
switch (type) switch (type)
{ {
case VideoType.Mp4: case VideoType.Mp4:
container.Add(new InputArgument(source)); container.Add(
container.Add(new ThreadsArgument(multithreaded)); new InputArgument(source),
container.Add(new ScaleArgument(outputSize)); new ThreadsArgument(multithreaded),
container.Add(new VideoCodecArgument(VideoCodec.LibX264, 2400)); new ScaleArgument(outputSize),
container.Add(new SpeedArgument(speed)); new VideoCodecArgument(VideoCodec.LibX264, 2400),
container.Add(new AudioCodecArgument(AudioCodec.Aac, audioQuality)); new SpeedArgument(speed),
container.Add(new OutputArgument(output)); new AudioCodecArgument(AudioCodec.Aac, audioQuality),
new OutputArgument(output)
);
break; break;
case VideoType.Ogv: case VideoType.Ogv:
container.Add(new InputArgument(source)); container.Add(
container.Add(new ThreadsArgument(multithreaded)); new InputArgument(source),
container.Add(new ScaleArgument(outputSize)); new ThreadsArgument(multithreaded),
container.Add(new VideoCodecArgument(VideoCodec.LibTheora, 2400)); new ScaleArgument(outputSize),
container.Add(new SpeedArgument(speed)); new VideoCodecArgument(VideoCodec.LibTheora, 2400),
container.Add(new AudioCodecArgument(AudioCodec.LibVorbis, audioQuality)); new SpeedArgument(speed),
container.Add(new OutputArgument(output)); new AudioCodecArgument(AudioCodec.LibVorbis, audioQuality),
new OutputArgument(output)
);
break; break;
case VideoType.Ts: case VideoType.Ts:
container.Add(new InputArgument(source)); container.Add(
container.Add(new CopyArgument()); new InputArgument(source),
container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB)); new CopyArgument(),
container.Add(new ForceFormatArgument(VideoCodec.MpegTs)); new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB),
container.Add(new OutputArgument(output)); new ForceFormatArgument(VideoCodec.MpegTs),
new OutputArgument(output)
);
break; break;
} }
@ -215,13 +222,14 @@ public VideoInfo PosterWithAudio(FileInfo image, FileInfo audio, FileInfo output
FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.Mp4); FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.Mp4);
FFMpegHelper.ConversionSizeExceptionCheck(Image.FromFile(image.FullName)); FFMpegHelper.ConversionSizeExceptionCheck(Image.FromFile(image.FullName));
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new LoopArgument(1)); new LoopArgument(1),
container.Add(new InputArgument(image.FullName, audio.FullName)); new InputArgument(image.FullName, audio.FullName),
container.Add(new VideoCodecArgument(VideoCodec.LibX264, 2400)); new VideoCodecArgument(VideoCodec.LibX264, 2400),
container.Add(new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Normal)); new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Normal),
container.Add(new ShortestArgument(true)); new ShortestArgument(true),
container.Add(new OutputArgument(output)); new OutputArgument(output)
);
if (!RunProcess(container, output)) if (!RunProcess(container, output))
{ {
@ -254,11 +262,12 @@ public VideoInfo Join(FileInfo output, params VideoInfo[] videos)
return destinationPath; return destinationPath;
}).ToList(); }).ToList();
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new ConcatArgument(temporaryVideoParts)); new ConcatArgument(temporaryVideoParts),
container.Add(new CopyArgument()); new CopyArgument(),
container.Add(new BitStreamFilterArgument(Channel.Audio, Filter.Aac_AdtstoAsc)); new BitStreamFilterArgument(Channel.Audio, Filter.Aac_AdtstoAsc),
container.Add(new OutputArgument(output)); new OutputArgument(output)
);
try try
{ {
@ -295,14 +304,15 @@ public VideoInfo JoinImageSequence(FileInfo output, double frameRate = 30, param
var firstImage = images.First(); var firstImage = images.First();
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new FrameRateArgument(frameRate)); new FrameRateArgument(frameRate),
container.Add(new SizeArgument(firstImage.Width, firstImage.Height)); new SizeArgument(firstImage.Width, firstImage.Height),
container.Add(new StartNumberArgument(0)); new StartNumberArgument(0),
container.Add(new InputArgument($"{firstImage.Directory}\\%09d.png")); new InputArgument($"{firstImage.Directory}\\%09d.png"),
container.Add(new FrameOutputCountArgument(images.Length)); new FrameOutputCountArgument(images.Length),
container.Add(new VideoCodecArgument(VideoCodec.LibX264)); new VideoCodecArgument(VideoCodec.LibX264),
container.Add(new OutputArgument(output)); new OutputArgument(output)
);
try try
{ {
@ -331,9 +341,10 @@ public VideoInfo SaveM3U8Stream(Uri uri, FileInfo output)
if (uri.Scheme == "http" || uri.Scheme == "https") if (uri.Scheme == "http" || uri.Scheme == "https")
{ {
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new InputArgument(uri)); new InputArgument(uri),
container.Add(new OutputArgument(output)); new OutputArgument(output)
);
if (!RunProcess(container, output)) if (!RunProcess(container, output))
{ {
@ -357,11 +368,12 @@ public VideoInfo Mute(VideoInfo source, FileInfo output)
FFMpegHelper.ConversionSizeExceptionCheck(source); FFMpegHelper.ConversionSizeExceptionCheck(source);
FFMpegHelper.ExtensionExceptionCheck(output, source.Extension); FFMpegHelper.ExtensionExceptionCheck(output, source.Extension);
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new InputArgument(source)); new InputArgument(source),
container.Add(new CopyArgument()); new CopyArgument(),
container.Add(new DisableChannelArgument(Channel.Audio)); new DisableChannelArgument(Channel.Audio),
container.Add(new OutputArgument(output)); new OutputArgument(output)
);
if (!RunProcess(container, output)) if (!RunProcess(container, output))
{ {
@ -382,10 +394,11 @@ public FileInfo ExtractAudio(VideoInfo source, FileInfo output)
FFMpegHelper.ConversionExceptionCheck(source.ToFileInfo(), output); FFMpegHelper.ConversionExceptionCheck(source.ToFileInfo(), output);
FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.Mp3); FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.Mp3);
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new InputArgument(source)); new InputArgument(source),
container.Add(new DisableChannelArgument(Channel.Video)); new DisableChannelArgument(Channel.Video),
container.Add(new OutputArgument(output)); new OutputArgument(output)
);
if (!RunProcess(container, output)) if (!RunProcess(container, output))
{ {
@ -412,13 +425,13 @@ public VideoInfo ReplaceAudio(VideoInfo source, FileInfo audio, FileInfo output,
FFMpegHelper.ConversionSizeExceptionCheck(source); FFMpegHelper.ConversionSizeExceptionCheck(source);
FFMpegHelper.ExtensionExceptionCheck(output, source.Extension); FFMpegHelper.ExtensionExceptionCheck(output, source.Extension);
var container = new ArgumentsContainer(); var container = new ArgumentContainer(
container.Add(new InputArgument(source.FullName, audio.FullName)); new InputArgument(source.FullName, audio.FullName),
//container.Add(new InputArgument(audio)); new CopyArgument(),
container.Add(new CopyArgument()); new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Hd),
container.Add(new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Hd)); new ShortestArgument(stopAtShortest),
container.Add(new ShortestArgument(stopAtShortest)); new OutputArgument(output)
container.Add(new OutputArgument(output)); );
if (!RunProcess(container, output)) if (!RunProcess(container, output))
{ {
@ -428,9 +441,9 @@ public VideoInfo ReplaceAudio(VideoInfo source, FileInfo audio, FileInfo output,
return new VideoInfo(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(); var output = ((OutputArgument)arguments[typeof(OutputArgument)]).GetAsFileInfo();
if (!RunProcess(arguments, output)) if (!RunProcess(arguments, output))
@ -459,11 +472,11 @@ public void Stop()
private volatile StringBuilder _errorOutput = new StringBuilder(); private volatile StringBuilder _errorOutput = new StringBuilder();
private bool RunProcess(ArgumentsContainer container, FileInfo output) private bool RunProcess(ArgumentContainer container, FileInfo output)
{ {
var successState = true; var successState = true;
CreateProcess(this.argumentBuilder.BuildArguments(container), _ffmpegPath, true, rStandardError: true); CreateProcess(this.ArgumentBuilder.BuildArguments(container), _ffmpegPath, true, rStandardError: true);
try try
{ {

View file