2019-02-09 15:20:04 +01:00
|
|
|
|
using FFMpegCore.FFMPEG.Argument;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
using FFMpegCore.FFMPEG.Enums;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using System;
|
|
|
|
|
|
2019-03-03 00:33:00 +01:00
|
|
|
|
namespace FFMpegCore.Test
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2019-03-03 00:33:00 +01:00
|
|
|
|
public class ArgumentBuilderTest : BaseTest
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
private readonly string[] _concatFiles = { "1.mp4", "2.mp4", "3.mp4", "4.mp4"};
|
2019-02-08 11:19:40 +01:00
|
|
|
|
|
2020-04-30 14:14:10 +02:00
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_IO_1()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" \"output.mp4\"", str);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Scale()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").Scale(VideoSize.Hd).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -vf scale=-1:720 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
2020-05-08 11:07:51 +02:00
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_AudioCodec()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithAudioCodec(AudioCodec.Aac).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -c:a aac \"output.mp4\"", str);
|
2020-05-01 10:07:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_AudioBitrate()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithAudioBitrate(AudioQuality.Normal).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -b:a 128k \"output.mp4\"", str);
|
2020-05-01 10:07:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Quiet()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").Quiet().OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -hide_banner -loglevel warning \"output.mp4\"", str);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 14:14:10 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_AudioCodec_Fluent()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithAudioCodec(AudioCodec.Aac).WithAudioBitrate(128).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -c:a aac -b:a 128k \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_BitStream()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithBitStreamFilter(Channel.Audio, Filter.H264_Mp4ToAnnexB).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -bsf:a h264_mp4toannexb \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Concat()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromConcatenation(_concatFiles).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"concat:1.mp4|2.mp4|3.mp4|4.mp4\" \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Copy_Audio()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").CopyChannel(Channel.Audio).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -c:a copy \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
2019-02-08 11:19:40 +01:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Copy_Video()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").CopyChannel(Channel.Video).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -c:v copy \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Copy_Both()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").CopyChannel().OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -c copy \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_CpuSpeed()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithCpuSpeed(10).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -quality good -cpu-used 10 -deadline realtime \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_ForceFormat()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").ForceFormat(VideoCodec.LibX264).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -f libx264 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_FrameOutputCount()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithFrameOutputCount(50).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -vframes 50 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_FrameRate()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithFramerate(50).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -r 50 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Loop()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").Loop(50).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -loop 50 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Seek()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").Seek(TimeSpan.FromSeconds(10)).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -ss 00:00:10 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Shortest()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").UsingShortest().OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -shortest \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Size()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").Resize(1920, 1080).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -s 1920x1080 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Speed()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithSpeedPreset(Speed.Fast).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -preset fast \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-25 23:19:30 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_DrawtextFilter()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments
|
|
|
|
|
.FromInputFiles(true, "input.mp4")
|
|
|
|
|
.DrawText(DrawTextOptions
|
|
|
|
|
.Create("Stack Overflow", "/path/to/font.ttf")
|
|
|
|
|
.WithParameter("fontcolor", "white")
|
|
|
|
|
.WithParameter("fontsize", "24")
|
|
|
|
|
.WithParameter("box", "1")
|
|
|
|
|
.WithParameter("boxcolor", "black@0.5")
|
|
|
|
|
.WithParameter("boxborderw", "5")
|
|
|
|
|
.WithParameter("x", "(w-text_w)/2")
|
|
|
|
|
.WithParameter("y", "(h-text_h)/2"))
|
|
|
|
|
.OutputToFile("output.mp4").Arguments;
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -vf drawtext=\"text='Stack Overflow':fontfile=/path/to/font.ttf:fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2\" \"output.mp4\"", str);
|
2020-02-25 23:19:30 +01:00
|
|
|
|
}
|
2020-05-08 11:07:51 +02:00
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_StartNumber()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithStartNumber(50).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -start_number 50 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Threads_1()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").UsingThreads(50).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -threads 50 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Threads_2()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").UsingMultithreading(true).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual($"-i \"input.mp4\" -threads {Environment.ProcessorCount} \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Codec()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithVideoCodec(VideoCodec.LibX264).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Codec_Override()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithVideoCodec(VideoCodec.LibX264).OutputToFile("output.mp4", true).Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p \"output.mp4\" -y", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-01-29 15:33:15 +01:00
|
|
|
|
[TestMethod]
|
2020-04-28 06:26:42 +02:00
|
|
|
|
public void Builder_BuildString_Duration()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithDuration(TimeSpan.FromSeconds(20)).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -t 00:00:20 \"output.mp4\"", str);
|
2020-04-30 14:14:10 +02:00
|
|
|
|
}
|
2020-05-06 20:57:26 +02:00
|
|
|
|
|
2020-04-28 06:26:42 +02:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Builder_BuildString_Raw()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithCustomArgument(null).OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" \"output.mp4\"", str);
|
2020-04-28 06:26:42 +02:00
|
|
|
|
|
2020-05-08 11:07:51 +02:00
|
|
|
|
str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithCustomArgument("-acodec copy").OutputToFile("output.mp4").Arguments;
|
|
|
|
|
Assert.AreEqual("-i \"input.mp4\" -acodec copy \"output.mp4\"", str);
|
2020-04-28 06:26:42 +02:00
|
|
|
|
}
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
2020-04-28 06:26:42 +02:00
|
|
|
|
}
|