mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-14 02:04:14 +01:00
Arguments: DurationArgument
#33 * added format provider to correctly parse the video's duration * added DurationArgument
This commit is contained in:
parent
acf6b10fab
commit
ec03bfe4a6
4 changed files with 62 additions and 0 deletions
|
@ -214,5 +214,12 @@ public void Builder_BuildString_Codec_Override()
|
||||||
|
|
||||||
Assert.AreEqual(str, "-i \"input.mp4\" -codec:v libx264 -pix_fmt yuv420p -y \"output.mp4\"");
|
Assert.AreEqual(str, "-i \"input.mp4\" -codec:v libx264 -pix_fmt yuv420p -y \"output.mp4\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Builder_BuildString_Duration() {
|
||||||
|
var str = GetArgumentsString(new DurationArgument(TimeSpan.FromSeconds(20)));
|
||||||
|
|
||||||
|
Assert.AreEqual(str, "-i \"input.mp4\" -t 00:00:20 \"output.mp4\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
using FFMpegCore.FFMPEG.Enums;
|
using FFMpegCore.FFMPEG.Enums;
|
||||||
using FFMpegCore.Test.Resources;
|
using FFMpegCore.Test.Resources;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -318,5 +319,27 @@ public void Video_With_Only_Audio_Should_Extract_Metadata()
|
||||||
Assert.AreEqual(video.Duration.TotalSeconds, 79);
|
Assert.AreEqual(video.Duration.TotalSeconds, 79);
|
||||||
Assert.AreEqual(video.Size, 1.25);
|
Assert.AreEqual(video.Size, 1.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
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));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Encoder.Convert(arguments);
|
||||||
|
|
||||||
|
Assert.IsTrue(File.Exists(output.FullName));
|
||||||
|
var outputVideo = new VideoInfo(output.FullName);
|
||||||
|
Assert.AreEqual(video.Duration.TotalSeconds - 5, outputVideo.Duration.TotalSeconds);
|
||||||
|
} finally {
|
||||||
|
if (File.Exists(output.FullName))
|
||||||
|
output.Delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,5 +201,10 @@ internal static string StartNumber(int v)
|
||||||
{
|
{
|
||||||
return $"-start_number {v} ";
|
return $"-start_number {v} ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string Duration(TimeSpan? duration)
|
||||||
|
{
|
||||||
|
return !duration.HasValue ? string.Empty : $"-t {duration} ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
27
FFMpegCore/FFMPEG/Argument/Atoms/DurationArgument.cs
Normal file
27
FFMpegCore/FFMPEG/Argument/Atoms/DurationArgument.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace FFMpegCore.FFMPEG.Argument
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents duration parameter
|
||||||
|
/// </summary>
|
||||||
|
public class DurationArgument : Argument<TimeSpan?>
|
||||||
|
{
|
||||||
|
public DurationArgument()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DurationArgument(TimeSpan? value) : base(value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// String representation of the argument
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String representation of the argument</returns>
|
||||||
|
public override string GetStringValue()
|
||||||
|
{
|
||||||
|
return ArgumentStringifier.Duration(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue