2022-06-20 05:31:18 +02:00
|
|
|
|
using FFMpegCore.Arguments;
|
|
|
|
|
using FFMpegCore.Enums;
|
|
|
|
|
using FFMpegCore.Exceptions;
|
|
|
|
|
using FFMpegCore.Pipes;
|
2019-03-03 00:33:00 +01:00
|
|
|
|
using FFMpegCore.Test.Resources;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2020-01-29 15:33:15 +01:00
|
|
|
|
using System;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
using System.Collections.Generic;
|
2020-05-12 22:48:20 +02:00
|
|
|
|
using System.Drawing;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2020-12-18 00:40:09 +01:00
|
|
|
|
using System.Text;
|
2021-07-07 20:16:14 +02:00
|
|
|
|
using System.Threading;
|
2022-06-20 05:31:18 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2022-03-24 20:19:37 +01:00
|
|
|
|
using FFMpegCore.Extensions.System.Drawing.Common;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
|
2019-03-03 00:33:00 +01:00
|
|
|
|
namespace FFMpegCore.Test
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2020-12-07 00:47:47 +01:00
|
|
|
|
public class VideoTest
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
2021-03-06 23:12:53 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_ToOGV()
|
2020-05-12 21:28:50 +02:00
|
|
|
|
{
|
2021-03-06 23:12:53 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-06 23:12:53 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
|
|
|
.OutputToFile(outputFile, false)
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2020-05-12 21:28:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-02-08 11:19:40 +01:00
|
|
|
|
public void Video_ToMP4()
|
|
|
|
|
{
|
2021-03-06 23:12:53 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-06 23:12:53 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
|
|
|
.OutputToFile(outputFile, false)
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-05-12 16:44:14 +02:00
|
|
|
|
public void Video_ToMP4_YUV444p()
|
|
|
|
|
{
|
2021-03-06 23:12:53 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-06 21:25:17 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
2021-03-06 23:12:53 +01:00
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.ForcePixelFormat("yuv444p"))
|
2021-03-06 21:25:17 +01:00
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
var analysis = FFProbe.Analyse(outputFile);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.IsTrue(analysis.VideoStreams.First().PixelFormat == "yuv444p");
|
2020-05-12 16:44:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-02-08 11:19:40 +01:00
|
|
|
|
public void Video_ToMP4_Args()
|
|
|
|
|
{
|
2021-03-06 23:12:53 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-06 23:12:53 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 18:53:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_ToH265_MKV_Args()
|
|
|
|
|
{
|
|
|
|
|
using var outputFile = new TemporaryFile($"out.mkv");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-11-03 18:53:38 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX265))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[DataTestMethod, Timeout(10000)]
|
2020-05-12 16:53:52 +02:00
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
|
|
|
|
public void Video_ToMP4_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat)
|
2020-04-27 18:24:26 +02:00
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
|
|
|
|
|
|
var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256));
|
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromPipeInput(videoFramesSource)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2020-04-27 18:24:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 18:35:19 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_ToMP4_Args_Pipe_DifferentImageSizes()
|
|
|
|
|
{
|
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
|
|
2022-06-20 05:31:18 +02:00
|
|
|
|
var frames = new List<IVideoFrame>
|
2021-03-15 18:35:19 +01:00
|
|
|
|
{
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0),
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 256, 256, 1, 0)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var videoFramesSource = new RawVideoPipeSource(frames);
|
2022-04-15 15:08:30 +02:00
|
|
|
|
var ex = Assert.ThrowsException<FFMpegStreamFormatException>(() => FFMpegArguments
|
2021-03-15 18:35:19 +01:00
|
|
|
|
.FromPipeInput(videoFramesSource)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessSynchronously());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public async Task Video_ToMP4_Args_Pipe_DifferentImageSizes_Async()
|
|
|
|
|
{
|
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
|
|
|
|
|
|
var frames = new List<IVideoFrame>
|
|
|
|
|
{
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0),
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 256, 256, 1, 0)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var videoFramesSource = new RawVideoPipeSource(frames);
|
2022-04-15 15:08:30 +02:00
|
|
|
|
var ex = await Assert.ThrowsExceptionAsync<FFMpegStreamFormatException>(() => FFMpegArguments
|
2021-03-15 18:35:19 +01:00
|
|
|
|
.FromPipeInput(videoFramesSource)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessAsynchronously());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_ToMP4_Args_Pipe_DifferentPixelFormats()
|
|
|
|
|
{
|
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
|
|
|
|
|
|
var frames = new List<IVideoFrame>
|
|
|
|
|
{
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0),
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format32bppRgb, 255, 255, 1, 0)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var videoFramesSource = new RawVideoPipeSource(frames);
|
2022-04-15 15:08:30 +02:00
|
|
|
|
var ex = Assert.ThrowsException<FFMpegStreamFormatException>(() => FFMpegArguments
|
2021-03-15 18:35:19 +01:00
|
|
|
|
.FromPipeInput(videoFramesSource)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessSynchronously());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public async Task Video_ToMP4_Args_Pipe_DifferentPixelFormats_Async()
|
|
|
|
|
{
|
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
|
|
|
|
|
|
var frames = new List<IVideoFrame>
|
|
|
|
|
{
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 255, 255, 1, 0),
|
|
|
|
|
BitmapSource.CreateVideoFrame(0, System.Drawing.Imaging.PixelFormat.Format32bppRgb, 255, 255, 1, 0)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var videoFramesSource = new RawVideoPipeSource(frames);
|
2022-04-15 15:08:30 +02:00
|
|
|
|
var ex = await Assert.ThrowsExceptionAsync<FFMpegStreamFormatException>(() => FFMpegArguments
|
2021-03-15 18:35:19 +01:00
|
|
|
|
.FromPipeInput(videoFramesSource)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessAsynchronously());
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:18:40 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-04-27 20:22:05 +02:00
|
|
|
|
public void Video_ToMP4_Args_StreamPipe()
|
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
using var input = File.OpenRead(TestResources.WebmVideo);
|
|
|
|
|
using var output = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromPipeInput(new StreamPipeSource(input))
|
|
|
|
|
.OutputToFile(output, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2020-04-27 20:22:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:18:40 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-05-12 23:52:07 +02:00
|
|
|
|
public async Task Video_ToMP4_Args_StreamOutputPipe_Async_Failure()
|
2020-04-28 21:40:33 +02:00
|
|
|
|
{
|
2021-03-07 00:26:08 +01:00
|
|
|
|
await Assert.ThrowsExceptionAsync<FFMpegException>(async () =>
|
2020-05-12 17:55:31 +02:00
|
|
|
|
{
|
|
|
|
|
await using var ms = new MemoryStream();
|
2020-05-24 19:17:14 +02:00
|
|
|
|
var pipeSource = new StreamPipeSink(ms);
|
2020-05-12 17:55:31 +02:00
|
|
|
|
await FFMpegArguments
|
2020-12-07 00:47:47 +01:00
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
2021-03-06 21:25:17 +01:00
|
|
|
|
.OutputToPipe(pipeSource, opt => opt.ForceFormat("mp4"))
|
2020-05-12 17:55:31 +02:00
|
|
|
|
.ProcessAsynchronously();
|
|
|
|
|
});
|
2020-04-28 21:40:33 +02:00
|
|
|
|
}
|
2021-03-15 18:35:19 +01:00
|
|
|
|
|
|
|
|
|
|
2020-12-03 20:47:20 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_StreamFile_OutputToMemoryStream()
|
|
|
|
|
{
|
|
|
|
|
var output = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
FFMpegArguments
|
2021-03-05 18:06:40 +01:00
|
|
|
|
.FromPipeInput(new StreamPipeSource(File.OpenRead(TestResources.WebmVideo)), opt => opt
|
|
|
|
|
.ForceFormat("webm"))
|
|
|
|
|
.OutputToPipe(new StreamPipeSink(output), opt => opt
|
2020-12-07 00:47:47 +01:00
|
|
|
|
.ForceFormat("mpegts"))
|
2020-12-03 20:47:20 +01:00
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
|
|
|
|
|
output.Position = 0;
|
|
|
|
|
var result = FFProbe.Analyse(output);
|
|
|
|
|
Console.WriteLine(result.Duration);
|
|
|
|
|
}
|
2020-04-28 21:40:33 +02:00
|
|
|
|
|
2020-10-25 17:18:40 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-04-28 21:40:33 +02:00
|
|
|
|
public void Video_ToMP4_Args_StreamOutputPipe_Failure()
|
|
|
|
|
{
|
2021-03-07 00:26:08 +01:00
|
|
|
|
Assert.ThrowsException<FFMpegException>(() =>
|
2021-03-05 18:06:40 +01:00
|
|
|
|
{
|
|
|
|
|
using var ms = new MemoryStream();
|
2021-03-06 23:12:53 +01:00
|
|
|
|
FFMpegArguments
|
2021-03-05 18:06:40 +01:00
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.OutputToPipe(new StreamPipeSink(ms), opt => opt
|
|
|
|
|
.ForceFormat("mkv"))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
});
|
2020-04-28 21:40:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-10-25 17:26:43 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2021-03-05 18:06:40 +01:00
|
|
|
|
public async Task Video_ToMP4_Args_StreamOutputPipe_Async()
|
2020-04-28 21:40:33 +02:00
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
await using var ms = new MemoryStream();
|
2020-05-24 19:17:14 +02:00
|
|
|
|
var pipeSource = new StreamPipeSink(ms);
|
2021-03-05 18:06:40 +01:00
|
|
|
|
await FFMpegArguments
|
2020-12-07 00:47:47 +01:00
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
2020-10-24 22:31:54 +02:00
|
|
|
|
.OutputToPipe(pipeSource, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.ForceFormat("matroska"))
|
2021-03-05 18:06:40 +01:00
|
|
|
|
.ProcessAsynchronously();
|
2020-04-28 21:40:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-07-13 23:54:46 +02:00
|
|
|
|
public async Task TestDuplicateRun()
|
|
|
|
|
{
|
2021-03-06 21:25:17 +01:00
|
|
|
|
FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
2020-10-24 22:31:54 +02:00
|
|
|
|
.OutputToFile("temporary.mp4")
|
2020-07-13 23:54:46 +02:00
|
|
|
|
.ProcessSynchronously();
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-06 21:25:17 +01:00
|
|
|
|
await FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
2020-10-24 22:31:54 +02:00
|
|
|
|
.OutputToFile("temporary.mp4")
|
2020-07-13 23:54:46 +02:00
|
|
|
|
.ProcessAsynchronously();
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2020-07-13 23:54:46 +02:00
|
|
|
|
File.Delete("temporary.mp4");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:26:43 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2021-03-06 21:25:17 +01:00
|
|
|
|
public void TranscodeToMemoryStream_Success()
|
2020-04-28 21:40:33 +02:00
|
|
|
|
{
|
2021-03-06 21:25:17 +01:00
|
|
|
|
using var output = new MemoryStream();
|
2021-03-05 18:06:40 +01:00
|
|
|
|
var success = FFMpegArguments
|
2021-03-06 21:25:17 +01:00
|
|
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
|
|
|
.OutputToPipe(new StreamPipeSink(output), opt => opt
|
2021-03-05 18:06:40 +01:00
|
|
|
|
.WithVideoCodec(VideoCodec.LibVpx)
|
|
|
|
|
.ForceFormat("matroska"))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
|
2021-03-06 21:25:17 +01:00
|
|
|
|
output.Position = 0;
|
|
|
|
|
var inputAnalysis = FFProbe.Analyse(TestResources.WebmVideo);
|
|
|
|
|
var outputAnalysis = FFProbe.Analyse(output);
|
2021-03-05 18:06:40 +01:00
|
|
|
|
Assert.AreEqual(inputAnalysis.Duration.TotalSeconds, outputAnalysis.Duration.TotalSeconds, 0.3);
|
2020-04-28 21:40:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-02-08 11:19:40 +01:00
|
|
|
|
public void Video_ToTS()
|
|
|
|
|
{
|
2021-03-06 23:12:53 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.MpegTs.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-06 23:12:53 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.OutputToFile(outputFile, false)
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-02-08 11:19:40 +01:00
|
|
|
|
public void Video_ToTS_Args()
|
|
|
|
|
{
|
2021-03-06 23:12:53 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.MpegTs.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-06 23:12:53 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.CopyChannel()
|
|
|
|
|
.WithBitStreamFilter(Channel.Video, Filter.H264_Mp4ToAnnexB)
|
|
|
|
|
.ForceFormat(VideoType.MpegTs))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:26:43 +01:00
|
|
|
|
[DataTestMethod, Timeout(10000)]
|
2020-05-12 16:53:52 +02:00
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
2021-03-05 18:06:40 +01:00
|
|
|
|
public async Task Video_ToTS_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat)
|
2020-04-27 18:24:26 +02:00
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
using var output = new TemporaryFile($"out{VideoType.Ts.Extension}");
|
|
|
|
|
var input = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256));
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
var success = await FFMpegArguments
|
|
|
|
|
.FromPipeInput(input)
|
|
|
|
|
.OutputToFile(output, false, opt => opt
|
|
|
|
|
.ForceFormat(VideoType.Ts))
|
|
|
|
|
.ProcessAsynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
var analysis = await FFProbe.AnalyseAsync(output);
|
|
|
|
|
Assert.AreEqual(VideoType.Ts.Name, analysis.Format.FormatName);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2021-03-05 18:06:40 +01:00
|
|
|
|
public async Task Video_ToOGV_Resize()
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
|
|
|
|
|
var success = await FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
2021-03-06 21:25:17 +01:00
|
|
|
|
.Resize(200, 200)
|
2021-03-05 18:06:40 +01:00
|
|
|
|
.WithVideoCodec(VideoCodec.LibTheora))
|
|
|
|
|
.ProcessAsynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:26:43 +01:00
|
|
|
|
[DataTestMethod, Timeout(10000)]
|
2020-05-12 16:53:52 +02:00
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
2020-05-10 14:15:32 +02:00
|
|
|
|
// [DataRow(PixelFormat.Format48bppRgb)]
|
2021-03-05 18:06:40 +01:00
|
|
|
|
public void RawVideoPipeSource_Ogv_Scale(System.Drawing.Imaging.PixelFormat pixelFormat)
|
2020-04-27 18:24:26 +02:00
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
|
|
|
|
|
var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256));
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
FFMpegArguments
|
|
|
|
|
.FromPipeInput(videoFramesSource)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoFilters(filterOptions => filterOptions
|
|
|
|
|
.Scale(VideoSize.Ed))
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibTheora))
|
|
|
|
|
.ProcessSynchronously();
|
2020-04-27 18:24:26 +02:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
var analysis = FFProbe.Analyse(outputFile);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual((int)VideoSize.Ed, analysis.PrimaryVideoStream!.Width);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2021-03-05 18:06:40 +01:00
|
|
|
|
public void Scale_Mp4_Multithreaded()
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.UsingMultithreading(true)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:26:43 +01:00
|
|
|
|
[DataTestMethod, Timeout(10000)]
|
2020-05-12 16:53:52 +02:00
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
|
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
2020-05-10 14:15:32 +02:00
|
|
|
|
// [DataRow(PixelFormat.Format48bppRgb)]
|
2020-05-12 16:53:52 +02:00
|
|
|
|
public void Video_ToMP4_Resize_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat)
|
2020-04-27 18:24:26 +02:00
|
|
|
|
{
|
2021-03-05 18:06:40 +01:00
|
|
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
|
var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256));
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromPipeInput(videoFramesSource)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
Assert.IsTrue(success);
|
2020-04-27 18:24:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-05-12 22:48:20 +02:00
|
|
|
|
public void Video_Snapshot_InMemory()
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
2022-03-24 20:19:37 +01:00
|
|
|
|
using var bitmap = FFMpegImage.Snapshot(TestResources.Mp4Video);
|
|
|
|
|
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width);
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height);
|
|
|
|
|
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-03-27 23:51:41 +01:00
|
|
|
|
public void Video_Snapshot_PersistSnapshot()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var outputPath = new TemporaryFile("out.png");
|
|
|
|
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
2019-03-27 23:51:41 +01:00
|
|
|
|
|
2021-03-06 21:25:17 +01:00
|
|
|
|
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
|
2020-05-12 22:48:20 +02:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
using var bitmap = Image.FromFile(outputPath);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width);
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height);
|
|
|
|
|
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
2019-03-27 23:51:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-02-08 11:19:40 +01:00
|
|
|
|
public void Video_Join()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var inputCopy = new TemporaryFile("copy-input.mp4");
|
|
|
|
|
File.Copy(TestResources.Mp4Video, inputCopy);
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var outputPath = new TemporaryFile("out.mp4");
|
|
|
|
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
|
|
|
|
var success = FFMpeg.Join(outputPath, TestResources.Mp4Video, inputCopy);
|
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
Assert.IsTrue(File.Exists(outputPath));
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var expectedDuration = input.Duration * 2;
|
|
|
|
|
var result = FFProbe.Analyse(outputPath);
|
|
|
|
|
Assert.AreEqual(expectedDuration.Days, result.Duration.Days);
|
|
|
|
|
Assert.AreEqual(expectedDuration.Hours, result.Duration.Hours);
|
|
|
|
|
Assert.AreEqual(expectedDuration.Minutes, result.Duration.Minutes);
|
|
|
|
|
Assert.AreEqual(expectedDuration.Seconds, result.Duration.Seconds);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height);
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-02-08 11:19:40 +01:00
|
|
|
|
public void Video_Join_Image_Sequence()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var imageSet = new List<ImageInfo>();
|
|
|
|
|
Directory.EnumerateFiles(TestResources.ImageCollection)
|
|
|
|
|
.Where(file => file.ToLower().EndsWith(".png"))
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(file =>
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
for (var i = 0; i < 15; i++)
|
|
|
|
|
{
|
|
|
|
|
imageSet.Add(new ImageInfo(file));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-24 20:19:37 +01:00
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
var success = FFMpegImage.JoinImageSequence(outputFile, images: imageSet.ToArray());
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
var result = FFProbe.Analyse(outputFile);
|
|
|
|
|
Assert.AreEqual(3, result.Duration.Seconds);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual(imageSet.First().Width, result.PrimaryVideoStream!.Width);
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.AreEqual(imageSet.First().Height, result.PrimaryVideoStream.Height);
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
2019-04-01 11:56:50 +02:00
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2019-04-01 11:56:50 +02:00
|
|
|
|
public void Video_With_Only_Audio_Should_Extract_Metadata()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var video = FFProbe.Analyse(TestResources.Mp4WithoutVideo);
|
2020-05-08 11:07:51 +02:00
|
|
|
|
Assert.AreEqual(null, video.PrimaryVideoStream);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual("aac", video.PrimaryAudioStream!.CodecName);
|
2020-10-25 17:16:47 +01:00
|
|
|
|
Assert.AreEqual(10, video.Duration.TotalSeconds, 0.5);
|
2019-04-01 11:56:50 +02:00
|
|
|
|
}
|
2020-04-27 18:24:26 +02:00
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-04-27 18:24:26 +02:00
|
|
|
|
public void Video_Duration()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var video = FFProbe.Analyse(TestResources.Mp4Video);
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
2020-05-12 16:44:14 +02:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt.WithDuration(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 2)))
|
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(File.Exists(outputFile));
|
|
|
|
|
var outputVideo = FFProbe.Analyse(outputFile);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(video.Duration.Days, outputVideo.Duration.Days);
|
|
|
|
|
Assert.AreEqual(video.Duration.Hours, outputVideo.Duration.Hours);
|
|
|
|
|
Assert.AreEqual(video.Duration.Minutes, outputVideo.Duration.Minutes);
|
|
|
|
|
Assert.AreEqual(video.Duration.Seconds - 2, outputVideo.Duration.Seconds);
|
2020-01-29 15:33:15 +01:00
|
|
|
|
}
|
2020-04-27 18:24:26 +02:00
|
|
|
|
|
2020-10-25 17:34:38 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-04-27 18:24:26 +02:00
|
|
|
|
public void Video_UpdatesProgress()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
2020-03-02 22:50:04 +01:00
|
|
|
|
|
|
|
|
|
var percentageDone = 0.0;
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var timeDone = TimeSpan.Zero;
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var analysis = FFProbe.Analyse(TestResources.Mp4Video);
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
|
|
|
|
void OnPercentageProgess(double percentage)
|
|
|
|
|
{
|
|
|
|
|
if (percentage < 100) percentageDone = percentage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTimeProgess(TimeSpan time)
|
|
|
|
|
{
|
|
|
|
|
if (time < analysis.Duration) timeDone = time;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
2022-06-20 05:31:18 +02:00
|
|
|
|
.WithDuration(analysis.Duration))
|
2020-12-07 00:47:47 +01:00
|
|
|
|
.NotifyOnProgress(OnPercentageProgess, analysis.Duration)
|
|
|
|
|
.NotifyOnProgress(OnTimeProgess)
|
|
|
|
|
.ProcessSynchronously();
|
2020-03-02 22:50:04 +01:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
Assert.IsTrue(File.Exists(outputFile));
|
|
|
|
|
Assert.AreNotEqual(0.0, percentageDone);
|
2022-06-20 05:31:18 +02:00
|
|
|
|
Assert.AreNotEqual(100.0, percentageDone);
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.AreNotEqual(TimeSpan.Zero, timeDone);
|
2022-06-20 05:31:18 +02:00
|
|
|
|
Assert.AreNotEqual(analysis.Duration, timeDone);
|
2020-03-02 22:50:04 +01:00
|
|
|
|
}
|
2020-04-28 21:54:39 +02:00
|
|
|
|
|
2020-12-18 00:40:09 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_OutputsData()
|
|
|
|
|
{
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
var dataReceived = false;
|
2022-06-20 05:31:18 +02:00
|
|
|
|
|
2021-03-07 00:26:08 +01:00
|
|
|
|
GlobalFFOptions.Configure(opt => opt.Encoding = Encoding.UTF8);
|
2020-12-18 00:40:09 +01:00
|
|
|
|
var success = FFMpegArguments
|
|
|
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
|
|
|
.WithGlobalOptions(options => options
|
|
|
|
|
.WithVerbosityLevel(VerbosityLevel.Info))
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithDuration(TimeSpan.FromSeconds(2)))
|
2022-03-12 19:06:46 +01:00
|
|
|
|
.NotifyOnError(_ => dataReceived = true)
|
2020-12-18 00:40:09 +01:00
|
|
|
|
.ProcessSynchronously();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(dataReceived);
|
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
Assert.IsTrue(File.Exists(outputFile));
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:18:40 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-04-28 21:54:39 +02:00
|
|
|
|
public void Video_TranscodeInMemory()
|
|
|
|
|
{
|
2020-05-08 11:07:51 +02:00
|
|
|
|
using var resStream = new MemoryStream();
|
2020-05-24 19:17:14 +02:00
|
|
|
|
var reader = new StreamPipeSink(resStream);
|
|
|
|
|
var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 128, 128));
|
2020-05-08 11:07:51 +02:00
|
|
|
|
|
2020-05-12 21:28:50 +02:00
|
|
|
|
FFMpegArguments
|
2020-10-24 22:31:54 +02:00
|
|
|
|
.FromPipeInput(writer)
|
|
|
|
|
.OutputToPipe(reader, opt => opt
|
|
|
|
|
.WithVideoCodec("vp9")
|
|
|
|
|
.ForceFormat("webm"))
|
2020-05-08 11:07:51 +02:00
|
|
|
|
.ProcessSynchronously();
|
2020-05-12 21:28:50 +02:00
|
|
|
|
|
2020-05-08 11:07:51 +02:00
|
|
|
|
resStream.Position = 0;
|
|
|
|
|
var vi = FFProbe.Analyse(resStream);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual(vi.PrimaryVideoStream!.Width, 128);
|
2020-05-08 11:07:51 +02:00
|
|
|
|
Assert.AreEqual(vi.PrimaryVideoStream.Height, 128);
|
2020-04-28 21:54:39 +02:00
|
|
|
|
}
|
2020-05-12 23:52:07 +02:00
|
|
|
|
|
2020-10-25 17:18:40 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-05-12 23:52:07 +02:00
|
|
|
|
public async Task Video_Cancel_Async()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
2021-03-02 19:33:19 +01:00
|
|
|
|
|
2020-05-12 23:52:07 +02:00
|
|
|
|
var task = FFMpegArguments
|
2021-03-02 19:33:19 +01:00
|
|
|
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
|
|
|
|
.WithCustomArgument("-re")
|
|
|
|
|
.ForceFormat("lavfi"))
|
2020-12-07 00:47:47 +01:00
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
2020-10-28 19:26:33 +01:00
|
|
|
|
.WithAudioCodec(AudioCodec.Aac)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
2021-03-02 19:33:19 +01:00
|
|
|
|
.WithSpeedPreset(Speed.VeryFast))
|
2020-05-12 23:52:07 +02:00
|
|
|
|
.CancellableThrough(out var cancel)
|
|
|
|
|
.ProcessAsynchronously(false);
|
2021-03-02 19:33:19 +01:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
await Task.Delay(300);
|
|
|
|
|
cancel();
|
2021-03-02 19:33:19 +01:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var result = await task;
|
2021-03-02 19:33:19 +01:00
|
|
|
|
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.IsFalse(result);
|
2020-05-12 23:52:07 +02:00
|
|
|
|
}
|
2021-03-02 19:33:19 +01:00
|
|
|
|
|
2022-04-15 15:08:30 +02:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_Cancel()
|
|
|
|
|
{
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
var task = FFMpegArguments
|
|
|
|
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
|
|
|
|
.WithCustomArgument("-re")
|
|
|
|
|
.ForceFormat("lavfi"))
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithAudioCodec(AudioCodec.Aac)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.WithSpeedPreset(Speed.VeryFast))
|
|
|
|
|
.CancellableThrough(out var cancel);
|
|
|
|
|
|
|
|
|
|
Task.Delay(300).ContinueWith((_) => cancel());
|
|
|
|
|
|
|
|
|
|
var result = task.ProcessSynchronously(false);
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 19:33:19 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public async Task Video_Cancel_Async_With_Timeout()
|
|
|
|
|
{
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
|
|
|
|
|
var task = FFMpegArguments
|
|
|
|
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
|
|
|
|
.WithCustomArgument("-re")
|
|
|
|
|
.ForceFormat("lavfi"))
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithAudioCodec(AudioCodec.Aac)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.WithSpeedPreset(Speed.VeryFast))
|
|
|
|
|
.CancellableThrough(out var cancel, 10000)
|
|
|
|
|
.ProcessAsynchronously(false);
|
|
|
|
|
|
|
|
|
|
await Task.Delay(300);
|
|
|
|
|
cancel();
|
|
|
|
|
|
2022-04-15 15:08:30 +02:00
|
|
|
|
await task;
|
2021-03-02 19:33:19 +01:00
|
|
|
|
|
2021-03-06 23:12:53 +01:00
|
|
|
|
var outputInfo = await FFProbe.AnalyseAsync(outputFile);
|
2021-03-02 19:33:19 +01:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(outputInfo);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
2021-03-02 19:33:19 +01:00
|
|
|
|
Assert.AreEqual(240, outputInfo.PrimaryVideoStream.Height);
|
|
|
|
|
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
2021-03-06 23:12:53 +01:00
|
|
|
|
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
2021-03-02 19:33:19 +01:00
|
|
|
|
}
|
2021-07-07 20:16:14 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public async Task Video_Cancel_CancellationToken_Async()
|
|
|
|
|
{
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
|
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
var task = FFMpegArguments
|
|
|
|
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
|
|
|
|
.WithCustomArgument("-re")
|
|
|
|
|
.ForceFormat("lavfi"))
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithAudioCodec(AudioCodec.Aac)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.WithSpeedPreset(Speed.VeryFast))
|
|
|
|
|
.CancellableThrough(cts.Token)
|
|
|
|
|
.ProcessAsynchronously(false);
|
|
|
|
|
|
2022-04-15 15:08:30 +02:00
|
|
|
|
cts.CancelAfter(300);
|
2021-07-07 20:16:14 +02:00
|
|
|
|
|
|
|
|
|
var result = await task;
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(result);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 15:08:30 +02:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public async Task Video_Cancel_CancellationToken_Async_Throws()
|
|
|
|
|
{
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
|
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
var task = FFMpegArguments
|
|
|
|
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
|
|
|
|
.WithCustomArgument("-re")
|
|
|
|
|
.ForceFormat("lavfi"))
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithAudioCodec(AudioCodec.Aac)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.WithSpeedPreset(Speed.VeryFast))
|
|
|
|
|
.CancellableThrough(cts.Token)
|
|
|
|
|
.ProcessAsynchronously();
|
|
|
|
|
|
|
|
|
|
cts.CancelAfter(300);
|
|
|
|
|
|
|
|
|
|
await Assert.ThrowsExceptionAsync<OperationCanceledException>(() => task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public void Video_Cancel_CancellationToken_Throws()
|
|
|
|
|
{
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
|
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
var task = FFMpegArguments
|
|
|
|
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
|
|
|
|
.WithCustomArgument("-re")
|
|
|
|
|
.ForceFormat("lavfi"))
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithAudioCodec(AudioCodec.Aac)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.WithSpeedPreset(Speed.VeryFast))
|
|
|
|
|
.CancellableThrough(cts.Token);
|
|
|
|
|
|
|
|
|
|
cts.CancelAfter(300);
|
|
|
|
|
|
|
|
|
|
Assert.ThrowsException<OperationCanceledException>(() => task.ProcessSynchronously());
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 20:16:14 +02:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
|
|
|
public async Task Video_Cancel_CancellationToken_Async_With_Timeout()
|
|
|
|
|
{
|
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
|
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
var task = FFMpegArguments
|
|
|
|
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
|
|
|
|
.WithCustomArgument("-re")
|
|
|
|
|
.ForceFormat("lavfi"))
|
|
|
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
|
|
|
.WithAudioCodec(AudioCodec.Aac)
|
|
|
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
|
|
|
.WithSpeedPreset(Speed.VeryFast))
|
2021-08-10 10:38:56 +02:00
|
|
|
|
.CancellableThrough(cts.Token, 8000)
|
2021-07-07 20:16:14 +02:00
|
|
|
|
.ProcessAsynchronously(false);
|
|
|
|
|
|
2022-04-15 15:08:30 +02:00
|
|
|
|
cts.CancelAfter(300);
|
2021-07-07 20:16:14 +02:00
|
|
|
|
|
2022-04-15 15:08:30 +02:00
|
|
|
|
await task;
|
2021-07-07 20:16:14 +02:00
|
|
|
|
|
|
|
|
|
var outputInfo = await FFProbe.AnalyseAsync(outputFile);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(outputInfo);
|
|
|
|
|
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
|
|
|
|
Assert.AreEqual(240, outputInfo.PrimaryVideoStream.Height);
|
|
|
|
|
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
|
|
|
|
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
|
|
|
|
}
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|