mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Cleanup
This commit is contained in:
parent
dd1c27dfa0
commit
46bc75c6d1
12 changed files with 59 additions and 70 deletions
|
@ -3,7 +3,6 @@
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using FFMpegCore.FFMPEG;
|
|
||||||
|
|
||||||
namespace FFMpegCore.Test
|
namespace FFMpegCore.Test
|
||||||
{
|
{
|
||||||
|
@ -22,8 +21,7 @@ public ArgumentBuilderTest() : base()
|
||||||
|
|
||||||
private string GetArgumentsString(params Argument[] args)
|
private string GetArgumentsString(params Argument[] args)
|
||||||
{
|
{
|
||||||
var container = new ArgumentContainer();
|
var container = new ArgumentContainer {new InputArgument("input.mp4")};
|
||||||
container.Add(new InputArgument("input.mp4"));
|
|
||||||
foreach (var a in args)
|
foreach (var a in args)
|
||||||
{
|
{
|
||||||
container.Add(a);
|
container.Add(a);
|
||||||
|
@ -68,10 +66,8 @@ public void Builder_BuildString_BitStream()
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Builder_BuildString_Concat()
|
public void Builder_BuildString_Concat()
|
||||||
{
|
{
|
||||||
var container = new ArgumentContainer();
|
var container = new ArgumentContainer {new ConcatArgument(concatFiles), new OutputArgument("output.mp4")};
|
||||||
|
|
||||||
container.Add(new ConcatArgument(concatFiles));
|
|
||||||
container.Add(new OutputArgument("output.mp4"));
|
|
||||||
|
|
||||||
var str = builder.BuildArguments(container);
|
var str = builder.BuildArguments(container);
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,7 @@ public void Convert(VideoType type, ArgumentContainer container)
|
||||||
{
|
{
|
||||||
var input = VideoInfo.FromFileInfo(Input);
|
var input = VideoInfo.FromFileInfo(Input);
|
||||||
|
|
||||||
var arguments = new ArgumentContainer();
|
var arguments = new ArgumentContainer {new InputArgument(input)};
|
||||||
arguments.Add(new InputArgument(input));
|
|
||||||
foreach (var arg in container)
|
foreach (var arg in container)
|
||||||
{
|
{
|
||||||
arguments.Add(arg.Value);
|
arguments.Add(arg.Value);
|
||||||
|
@ -124,8 +123,7 @@ public void Video_ToMP4()
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Video_ToMP4_Args()
|
public void Video_ToMP4_Args()
|
||||||
{
|
{
|
||||||
var container = new ArgumentContainer();
|
var container = new ArgumentContainer {new VideoCodecArgument(VideoCodec.LibX264)};
|
||||||
container.Add(new VideoCodecArgument(VideoCodec.LibX264));
|
|
||||||
Convert(VideoType.Mp4, container);
|
Convert(VideoType.Mp4, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,10 +136,12 @@ public void Video_ToTS()
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Video_ToTS_Args()
|
public void Video_ToTS_Args()
|
||||||
{
|
{
|
||||||
var container = new ArgumentContainer();
|
var container = new ArgumentContainer
|
||||||
container.Add(new CopyArgument());
|
{
|
||||||
container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB));
|
new CopyArgument(),
|
||||||
container.Add(new ForceFormatArgument(VideoCodec.MpegTs));
|
new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB),
|
||||||
|
new ForceFormatArgument(VideoCodec.MpegTs)
|
||||||
|
};
|
||||||
Convert(VideoType.Ts, container);
|
Convert(VideoType.Ts, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,9 +155,11 @@ public void Video_ToOGV_Resize()
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Video_ToOGV_Resize_Args()
|
public void Video_ToOGV_Resize_Args()
|
||||||
{
|
{
|
||||||
var container = new ArgumentContainer();
|
var container = new ArgumentContainer
|
||||||
container.Add(new ScaleArgument(VideoSize.Ed));
|
{
|
||||||
container.Add(new VideoCodecArgument(VideoCodec.LibTheora));
|
new ScaleArgument(VideoSize.Ed),
|
||||||
|
new VideoCodecArgument(VideoCodec.LibTheora)
|
||||||
|
};
|
||||||
Convert(VideoType.Ogv, container);
|
Convert(VideoType.Ogv, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,9 +172,11 @@ public void Video_ToMP4_Resize()
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Video_ToMP4_Resize_Args()
|
public void Video_ToMP4_Resize_Args()
|
||||||
{
|
{
|
||||||
var container = new ArgumentContainer();
|
var container = new ArgumentContainer
|
||||||
container.Add(new ScaleArgument(VideoSize.Ld));
|
{
|
||||||
container.Add(new VideoCodecArgument(VideoCodec.LibX264));
|
new ScaleArgument(VideoSize.Ld),
|
||||||
|
new VideoCodecArgument(VideoCodec.LibX264)
|
||||||
|
};
|
||||||
Convert(VideoType.Mp4, container);
|
Convert(VideoType.Mp4, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,13 +213,11 @@ public void Video_Snapshot()
|
||||||
{
|
{
|
||||||
var input = VideoInfo.FromFileInfo(Input);
|
var input = VideoInfo.FromFileInfo(Input);
|
||||||
|
|
||||||
using (var bitmap = Encoder.Snapshot(input, output))
|
using var bitmap = Encoder.Snapshot(input, output);
|
||||||
{
|
|
||||||
Assert.AreEqual(input.Width, bitmap.Width);
|
Assert.AreEqual(input.Width, bitmap.Width);
|
||||||
Assert.AreEqual(input.Height, bitmap.Height);
|
Assert.AreEqual(input.Height, bitmap.Height);
|
||||||
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (File.Exists(output.FullName))
|
if (File.Exists(output.FullName))
|
||||||
|
@ -231,14 +233,12 @@ public void Video_Snapshot_PersistSnapshot()
|
||||||
{
|
{
|
||||||
var input = VideoInfo.FromFileInfo(Input);
|
var input = VideoInfo.FromFileInfo(Input);
|
||||||
|
|
||||||
using (var bitmap = Encoder.Snapshot(input, output, persistSnapshotOnFileSystem: true))
|
using var bitmap = Encoder.Snapshot(input, output, persistSnapshotOnFileSystem: true);
|
||||||
{
|
|
||||||
Assert.AreEqual(input.Width, bitmap.Width);
|
Assert.AreEqual(input.Width, bitmap.Width);
|
||||||
Assert.AreEqual(input.Height, bitmap.Height);
|
Assert.AreEqual(input.Height, bitmap.Height);
|
||||||
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
||||||
Assert.IsTrue(File.Exists(output.FullName));
|
Assert.IsTrue(File.Exists(output.FullName));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (File.Exists(output.FullName))
|
if (File.Exists(output.FullName))
|
||||||
|
@ -260,7 +260,7 @@ public void Video_Join()
|
||||||
var result = Encoder.Join(output, input, input2);
|
var result = Encoder.Join(output, input, input2);
|
||||||
|
|
||||||
Assert.IsTrue(File.Exists(output.FullName));
|
Assert.IsTrue(File.Exists(output.FullName));
|
||||||
TimeSpan expectedDuration = input.Duration * 2;
|
var expectedDuration = input.Duration * 2;
|
||||||
Assert.AreEqual(expectedDuration.Days, result.Duration.Days);
|
Assert.AreEqual(expectedDuration.Days, result.Duration.Days);
|
||||||
Assert.AreEqual(expectedDuration.Hours, result.Duration.Hours);
|
Assert.AreEqual(expectedDuration.Hours, result.Duration.Hours);
|
||||||
Assert.AreEqual(expectedDuration.Minutes, result.Duration.Minutes);
|
Assert.AreEqual(expectedDuration.Minutes, result.Duration.Minutes);
|
||||||
|
@ -289,7 +289,7 @@ public void Video_Join_Image_Sequence()
|
||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(file =>
|
.ForEach(file =>
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 15; i++)
|
for (var i = 0; i < 15; i++)
|
||||||
{
|
{
|
||||||
imageSet.Add(new ImageInfo(file));
|
imageSet.Add(new ImageInfo(file));
|
||||||
}
|
}
|
||||||
|
@ -329,10 +329,12 @@ public void Video_Duration() {
|
||||||
var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo);
|
var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo);
|
||||||
var output = Input.OutputLocation(VideoType.Mp4);
|
var output = Input.OutputLocation(VideoType.Mp4);
|
||||||
|
|
||||||
var arguments = new ArgumentContainer();
|
var arguments = new ArgumentContainer
|
||||||
arguments.Add(new InputArgument(VideoLibrary.LocalVideo));
|
{
|
||||||
arguments.Add(new DurationArgument(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 5)));
|
new InputArgument(VideoLibrary.LocalVideo),
|
||||||
arguments.Add(new OutputArgument(output));
|
new DurationArgument(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 5)),
|
||||||
|
new OutputArgument(output)
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Encoder.Convert(arguments);
|
Encoder.Convert(arguments);
|
||||||
|
|
|
@ -41,14 +41,14 @@ public Argument(T value)
|
||||||
public abstract class Argument<T1, T2> : Argument
|
public abstract class Argument<T1, T2> : Argument
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// First value type of <see cref="T"/>
|
/// First value type of <see cref="T1"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public T1 First { get; set; }
|
public T1 First { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Second value type of <see cref="T"/>
|
/// Second value type of <see cref="T2"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public T2 Second { get; set; }
|
public T2 Second { get; }
|
||||||
|
|
||||||
public Argument() { }
|
public Argument() { }
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public ArgumentContainer(params Argument[] arguments)
|
||||||
|
|
||||||
foreach(var argument in arguments)
|
foreach(var argument in arguments)
|
||||||
{
|
{
|
||||||
this.Add(argument);
|
Add(argument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public void Add(Type key, Argument value)
|
||||||
[Obsolete]
|
[Obsolete]
|
||||||
public void Add(KeyValuePair<Type, Argument> item)
|
public void Add(KeyValuePair<Type, Argument> item)
|
||||||
{
|
{
|
||||||
this.Add(item.Value);
|
Add(item.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using FFMpegCore.FFMPEG.Enums;
|
||||||
using FFMpegCore.FFMPEG.Enums;
|
|
||||||
|
|
||||||
namespace FFMpegCore.FFMPEG.Argument
|
namespace FFMpegCore.FFMPEG.Argument
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@ public override string GetStringValue()
|
||||||
{
|
{
|
||||||
Channel.Audio => "-c:a copy",
|
Channel.Audio => "-c:a copy",
|
||||||
Channel.Video => "-c:v copy",
|
Channel.Video => "-c:v copy",
|
||||||
Channel.Both => "-c copy"
|
_ => "-c copy"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using FFMpegCore.Enums;
|
using System;
|
||||||
using FFMpegCore.Helpers;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace FFMpegCore.FFMPEG.Argument
|
namespace FFMpegCore.FFMPEG.Argument
|
||||||
|
|
|
@ -14,18 +14,16 @@ public enum FFMpegExceptionType
|
||||||
|
|
||||||
public class FFMpegException : Exception
|
public class FFMpegException : Exception
|
||||||
{
|
{
|
||||||
public FFMpegException(FFMpegExceptionType type): this(type, null, null) { }
|
|
||||||
|
|
||||||
public FFMpegException(FFMpegExceptionType type, StringBuilder sb): this(type, sb.ToString(), null) { }
|
public FFMpegException(FFMpegExceptionType type, StringBuilder sb): this(type, sb.ToString(), null) { }
|
||||||
|
|
||||||
public FFMpegException(FFMpegExceptionType type, string message): this(type, message, null) { }
|
public FFMpegException(FFMpegExceptionType type, string message): this(type, message, null) { }
|
||||||
|
|
||||||
public FFMpegException(FFMpegExceptionType type, string message, FFMpegException innerException)
|
public FFMpegException(FFMpegExceptionType type, string message = null, Exception innerException = null)
|
||||||
: base(message, innerException)
|
: base(message, innerException)
|
||||||
{
|
{
|
||||||
Type = type;
|
Type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FFMpegExceptionType Type { get; set; }
|
public FFMpegExceptionType Type { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@
|
||||||
using FFMpegCore.Helpers;
|
using FFMpegCore.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
using FFMpegCore.FFMPEG.Exceptions;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Instances;
|
|
||||||
|
|
||||||
namespace FFMpegCore.FFMPEG
|
namespace FFMpegCore.FFMPEG
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,11 +78,11 @@ private VideoInfo ParseVideoInfoInternal(VideoInfo info, string probeOutput)
|
||||||
var video = metadata.Streams.Find(s => s.CodecType == "video");
|
var video = metadata.Streams.Find(s => s.CodecType == "video");
|
||||||
var audio = metadata.Streams.Find(s => s.CodecType == "audio");
|
var audio = metadata.Streams.Find(s => s.CodecType == "audio");
|
||||||
|
|
||||||
double videoSize = 0d;
|
var videoSize = 0d;
|
||||||
double audioSize = 0d;
|
var audioSize = 0d;
|
||||||
|
|
||||||
string sDuration = (video ?? audio).Duration;
|
var sDuration = (video ?? audio).Duration;
|
||||||
TimeSpan duration = TimeSpan.Zero;
|
var duration = TimeSpan.Zero;
|
||||||
if (sDuration != null)
|
if (sDuration != null)
|
||||||
{
|
{
|
||||||
duration = TimeSpan.FromSeconds(double.TryParse(sDuration, NumberStyles.Any, CultureInfo.InvariantCulture, out var output) ? output : 0);
|
duration = TimeSpan.FromSeconds(double.TryParse(sDuration, NumberStyles.Any, CultureInfo.InvariantCulture, out var output) ? output : 0);
|
||||||
|
|
|
@ -23,14 +23,14 @@ public ImageInfo(FileInfo fileInfo)
|
||||||
|
|
||||||
fileInfo.Refresh();
|
fileInfo.Refresh();
|
||||||
|
|
||||||
this.Size = fileInfo.Length / (1024 * 1024);
|
Size = fileInfo.Length / (1024 * 1024);
|
||||||
|
|
||||||
using (var image = Image.FromFile(fileInfo.FullName))
|
using (var image = Image.FromFile(fileInfo.FullName))
|
||||||
{
|
{
|
||||||
this.Width = image.Width;
|
Width = image.Width;
|
||||||
this.Height = image.Height;
|
Height = image.Height;
|
||||||
var cd = FFProbeHelper.Gcd(this.Width, this.Height);
|
var cd = FFProbeHelper.Gcd(Width, Height);
|
||||||
this.Ratio = $"{this.Width / cd}:{this.Height / cd}";
|
Ratio = $"{Width / cd}:{Height / cd}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue