Former-commit-id: 46bc75c6d1
This commit is contained in:
Malte Rosenbjerg 2020-02-27 21:12:48 +01:00
parent c1bbd4ce9d
commit 7b2a419c10
12 changed files with 59 additions and 70 deletions

View file

@ -3,7 +3,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using FFMpegCore.FFMPEG;
namespace FFMpegCore.Test
{
@ -22,8 +21,7 @@ public ArgumentBuilderTest() : base()
private string GetArgumentsString(params Argument[] args)
{
var container = new ArgumentContainer();
container.Add(new InputArgument("input.mp4"));
var container = new ArgumentContainer {new InputArgument("input.mp4")};
foreach (var a in args)
{
container.Add(a);
@ -68,10 +66,8 @@ public void Builder_BuildString_BitStream()
[TestMethod]
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);

View file

@ -70,8 +70,7 @@ public void Convert(VideoType type, ArgumentContainer container)
{
var input = VideoInfo.FromFileInfo(Input);
var arguments = new ArgumentContainer();
arguments.Add(new InputArgument(input));
var arguments = new ArgumentContainer {new InputArgument(input)};
foreach (var arg in container)
{
arguments.Add(arg.Value);
@ -124,8 +123,7 @@ public void Video_ToMP4()
[TestMethod]
public void Video_ToMP4_Args()
{
var container = new ArgumentContainer();
container.Add(new VideoCodecArgument(VideoCodec.LibX264));
var container = new ArgumentContainer {new VideoCodecArgument(VideoCodec.LibX264)};
Convert(VideoType.Mp4, container);
}
@ -138,10 +136,12 @@ public void Video_ToTS()
[TestMethod]
public void Video_ToTS_Args()
{
var container = new ArgumentContainer();
container.Add(new CopyArgument());
container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB));
container.Add(new ForceFormatArgument(VideoCodec.MpegTs));
var container = new ArgumentContainer
{
new CopyArgument(),
new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB),
new ForceFormatArgument(VideoCodec.MpegTs)
};
Convert(VideoType.Ts, container);
}
@ -155,9 +155,11 @@ public void Video_ToOGV_Resize()
[TestMethod]
public void Video_ToOGV_Resize_Args()
{
var container = new ArgumentContainer();
container.Add(new ScaleArgument(VideoSize.Ed));
container.Add(new VideoCodecArgument(VideoCodec.LibTheora));
var container = new ArgumentContainer
{
new ScaleArgument(VideoSize.Ed),
new VideoCodecArgument(VideoCodec.LibTheora)
};
Convert(VideoType.Ogv, container);
}
@ -170,9 +172,11 @@ public void Video_ToMP4_Resize()
[TestMethod]
public void Video_ToMP4_Resize_Args()
{
var container = new ArgumentContainer();
container.Add(new ScaleArgument(VideoSize.Ld));
container.Add(new VideoCodecArgument(VideoCodec.LibX264));
var container = new ArgumentContainer
{
new ScaleArgument(VideoSize.Ld),
new VideoCodecArgument(VideoCodec.LibX264)
};
Convert(VideoType.Mp4, container);
}
@ -209,13 +213,11 @@ public void Video_Snapshot()
{
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.Height, bitmap.Height);
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
}
}
finally
{
if (File.Exists(output.FullName))
@ -231,14 +233,12 @@ public void Video_Snapshot_PersistSnapshot()
{
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.Height, bitmap.Height);
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
Assert.IsTrue(File.Exists(output.FullName));
}
}
finally
{
if (File.Exists(output.FullName))
@ -260,7 +260,7 @@ public void Video_Join()
var result = Encoder.Join(output, input, input2);
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.Hours, result.Duration.Hours);
Assert.AreEqual(expectedDuration.Minutes, result.Duration.Minutes);
@ -289,7 +289,7 @@ public void Video_Join_Image_Sequence()
.ToList()
.ForEach(file =>
{
for (int i = 0; i < 15; i++)
for (var i = 0; i < 15; i++)
{
imageSet.Add(new ImageInfo(file));
}
@ -329,10 +329,12 @@ public void Video_Duration() {
var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo);
var output = Input.OutputLocation(VideoType.Mp4);
var arguments = new ArgumentContainer();
arguments.Add(new InputArgument(VideoLibrary.LocalVideo));
arguments.Add(new DurationArgument(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 5)));
arguments.Add(new OutputArgument(output));
var arguments = new ArgumentContainer
{
new InputArgument(VideoLibrary.LocalVideo),
new DurationArgument(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 5)),
new OutputArgument(output)
};
try {
Encoder.Convert(arguments);

View file

@ -41,14 +41,14 @@ public Argument(T value)
public abstract class Argument<T1, T2> : Argument
{
/// <summary>
/// First value type of <see cref="T"/>
/// First value type of <see cref="T1"/>
/// </summary>
public T1 First { get; set; }
public T1 First { get; }
/// <summary>
/// Second value type of <see cref="T"/>
/// Second value type of <see cref="T2"/>
/// </summary>
public T2 Second { get; set; }
public T2 Second { get; }
public Argument() { }

View file

@ -17,7 +17,7 @@ public ArgumentContainer(params Argument[] arguments)
foreach(var argument in arguments)
{
this.Add(argument);
Add(argument);
}
}
@ -50,7 +50,7 @@ public void Add(Type key, Argument value)
[Obsolete]
public void Add(KeyValuePair<Type, Argument> item)
{
this.Add(item.Value);
Add(item.Value);
}
/// <summary>

View file

@ -1,5 +1,4 @@
using System;
using FFMpegCore.FFMPEG.Enums;
using FFMpegCore.FFMPEG.Enums;
namespace FFMpegCore.FFMPEG.Argument
{

View file

@ -18,7 +18,7 @@ public override string GetStringValue()
{
Channel.Audio => "-c:a copy",
Channel.Video => "-c:v copy",
Channel.Both => "-c copy"
_ => "-c copy"
};
}
}

View file

@ -1,7 +1,4 @@
using FFMpegCore.Enums;
using FFMpegCore.Helpers;
using System;
using System.IO;
using System;
using System.Linq;
namespace FFMpegCore.FFMPEG.Argument

View file

@ -14,18 +14,16 @@ public enum FFMpegExceptionType
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, 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)
{
Type = type;
}
public FFMpegExceptionType Type { get; set; }
public FFMpegExceptionType Type { get; }
}
}

View file

@ -5,7 +5,6 @@
using FFMpegCore.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;

View file

@ -1,9 +1,7 @@
using FFMpegCore.FFMPEG.Exceptions;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Runtime.InteropServices;
using Instances;
namespace FFMpegCore.FFMPEG
{

View file

@ -78,11 +78,11 @@ private VideoInfo ParseVideoInfoInternal(VideoInfo info, string probeOutput)
var video = metadata.Streams.Find(s => s.CodecType == "video");
var audio = metadata.Streams.Find(s => s.CodecType == "audio");
double videoSize = 0d;
double audioSize = 0d;
var videoSize = 0d;
var audioSize = 0d;
string sDuration = (video ?? audio).Duration;
TimeSpan duration = TimeSpan.Zero;
var sDuration = (video ?? audio).Duration;
var duration = TimeSpan.Zero;
if (sDuration != null)
{
duration = TimeSpan.FromSeconds(double.TryParse(sDuration, NumberStyles.Any, CultureInfo.InvariantCulture, out var output) ? output : 0);

View file

@ -23,14 +23,14 @@ public ImageInfo(FileInfo fileInfo)
fileInfo.Refresh();
this.Size = fileInfo.Length / (1024 * 1024);
Size = fileInfo.Length / (1024 * 1024);
using (var image = Image.FromFile(fileInfo.FullName))
{
this.Width = image.Width;
this.Height = image.Height;
var cd = FFProbeHelper.Gcd(this.Width, this.Height);
this.Ratio = $"{this.Width / cd}:{this.Height / cd}";
Width = image.Width;
Height = image.Height;
var cd = FFProbeHelper.Gcd(Width, Height);
Ratio = $"{Width / cd}:{Height / cd}";
}