mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-14 02:04:14 +01:00
278ab4c7b5
* Move NotifyOnProgress processing to ErrorData
* added HighPass filter, LowPass filter, Audiogate and Silencedetection
* re-added corresponding AudioFilterOptions
* Update LICENSE
* Update ci.yml
* Fix argument
* Bump action versions
* Ignore Uri_Duration until root cause found
* Use action that can install specific ffmpeg version
* Remove ignore
* Revert "Remove ignore"
This reverts commit d85a4b81ab
.
* Bump dependencies
* Use setup-dotnet@v2 since v3 seems to install .NET 7
* Init
* WIP
* Add Directory.Build.props
* Add SupportedOSPlatform attribute on tests using SDC
* Fix using temporarily
* Add IgnoreIf attribute to only run SDC tests on Windows
* Cleanup pipelines
* Cleanup
* Cleanup using directives
* More cleanup
* Simplify attribute
* Fix attribute
* Add missing test file
* Added blackdetect and blackframe arguments
* Added log levels
* Add missing using directive after rebase
* fix extension is not png lost path
* Apply fix to methods in new location
* Add Uri support for Frame Analysis,
skipped Stream support as this cannot support MP4's with moov atom in the end of the file, and input pipes do not support seek.
* Add select multiple streams
* Add other stream types to Channel (V,s,d,t)
* Add negative mapping to select stream (deselect)
* Update test
* Add pad video filter
* Update PipeHelpers.cs
* Fix GetPipePath() for MacOS
* Add SampleAspectRatio property to VideoStream
* Update year
* Always use Path.GetTempPath() on linux and macos
* Use FedericoCarboni/setup-ffmpeg@v2
* Include macos in ci matrix
* AddDeviceInput similar to AddFileInput and FromDeviceInput
* fixed hwaccel parameter not working in 5.0
* a hack to unconditionally kill ffmpeg when parent .NET process exits
* Remove PInvoke.Kernel32
* Remove unneeded cast
* Update test
* Added ability to retrieve bit depth from media streams for lossless encodings (#359)
* Added ability to retrieve bit depth from media streams for lossless encodings
* Shortened sample AIFF file used in tests
* Cleanup after splitting into two packages (#386)
* Move PosterWithAudio to FFMpegCore
* Reduce windows only tests
* Update Directory.Build.props
* Create .editorconfig
* More cleanup
* Enable implicit usings
* Remove unused method
* Apply dotnet format
* Fix unused variable in AudioGateArgument
* Fix boolean conditions in AudioGateArgument
* Merge boolean conditions into pattern
* Use target-typed new
* Add linting to CI
* Add CUDA to HardwareAccelerationDevice enum
* Increase timeout for Video_Join_Image_Sequence
* Adjust Video_Join_Image_Sequence timeout
* Fix expected seconds in Video_Join_Image_Sequence
* Increase timeout for Video_TranscodeToMemory due to macos agents
* fix: Switch source for rotation property from 'tags/rotate' to 'side_data_list/rotation' (incl. test case) (#388)
* Init (#389)
* build master branch after merge or push (#390)
* Update ci.yml
* Add codecov
* Remove codecov for now
* Add coverlet.collector and codecov
---------
Co-authored-by: keg247 <44041557+keg247@users.noreply.github.com>
Co-authored-by: Wilbert Bongers <msdnwilbert@muziekweb.nl>
Co-authored-by: Artemii Gazizianov <107502822+ArtemiiimetrA@users.noreply.github.com>
Co-authored-by: Thodoris Koskinopoulos <me@koskit.me>
Co-authored-by: 赵宁 <602726286@qq.com>
Co-authored-by: jeroenvanderschoot <jeroen.vanderschoot@kinetiq.tv>
Co-authored-by: Sky Z <qe201020335@sina.com>
Co-authored-by: Gleb Moskalenko <gleb.moskalenko.general@gmail.com>
Co-authored-by: ep1kt3t0s <86835785+ep1kt3t0s@users.noreply.github.com>
Co-authored-by: Victor Nova <lostfreeman@gmail.com>
Co-authored-by: Tom Bogle <tom_bogle@sil.org>
Co-authored-by: pklaes <10601494+pklaes@users.noreply.github.com>
780 lines
31 KiB
C#
780 lines
31 KiB
C#
using System.Drawing.Imaging;
|
|
using System.Runtime.Versioning;
|
|
using System.Text;
|
|
using FFMpegCore.Arguments;
|
|
using FFMpegCore.Enums;
|
|
using FFMpegCore.Exceptions;
|
|
using FFMpegCore.Extensions.System.Drawing.Common;
|
|
using FFMpegCore.Pipes;
|
|
using FFMpegCore.Test.Resources;
|
|
using FFMpegCore.Test.Utilities;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace FFMpegCore.Test
|
|
{
|
|
[TestClass]
|
|
public class VideoTest
|
|
{
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToOGV()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
.OutputToFile(outputFile, false)
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToMP4()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
.OutputToFile(outputFile, false)
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToMP4_YUV444p()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
.ForcePixelFormat("yuv444p"))
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
var analysis = FFProbe.Analyse(outputFile);
|
|
Assert.IsTrue(analysis.VideoStreams.First().PixelFormat == "yuv444p");
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToMP4_Args()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToH265_MKV_Args()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out.mkv");
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX265))
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyDataTestMethod, Timeout(10000)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
|
public void Video_ToMP4_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat)
|
|
{
|
|
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);
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyTestMethod, Timeout(10000)]
|
|
public void Video_ToMP4_Args_Pipe_DifferentImageSizes()
|
|
{
|
|
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);
|
|
var ex = Assert.ThrowsException<FFMpegStreamFormatException>(() => FFMpegArguments
|
|
.FromPipeInput(videoFramesSource)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
.ProcessSynchronously());
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyTestMethod, 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);
|
|
var ex = await Assert.ThrowsExceptionAsync<FFMpegStreamFormatException>(() => FFMpegArguments
|
|
.FromPipeInput(videoFramesSource)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
.ProcessAsynchronously());
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyTestMethod, 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);
|
|
var ex = Assert.ThrowsException<FFMpegStreamFormatException>(() => FFMpegArguments
|
|
.FromPipeInput(videoFramesSource)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
.ProcessSynchronously());
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyTestMethod, 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);
|
|
var ex = await Assert.ThrowsExceptionAsync<FFMpegStreamFormatException>(() => FFMpegArguments
|
|
.FromPipeInput(videoFramesSource)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
.ProcessAsynchronously());
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToMP4_Args_StreamPipe()
|
|
{
|
|
using var input = File.OpenRead(TestResources.WebmVideo);
|
|
using var output = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
var success = FFMpegArguments
|
|
.FromPipeInput(new StreamPipeSource(input))
|
|
.OutputToFile(output, false, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public async Task Video_ToMP4_Args_StreamOutputPipe_Async_Failure()
|
|
{
|
|
await Assert.ThrowsExceptionAsync<FFMpegException>(async () =>
|
|
{
|
|
await using var ms = new MemoryStream();
|
|
var pipeSource = new StreamPipeSink(ms);
|
|
await FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToPipe(pipeSource, opt => opt.ForceFormat("mp4"))
|
|
.ProcessAsynchronously();
|
|
});
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_StreamFile_OutputToMemoryStream()
|
|
{
|
|
var output = new MemoryStream();
|
|
|
|
FFMpegArguments
|
|
.FromPipeInput(new StreamPipeSource(File.OpenRead(TestResources.WebmVideo)), opt => opt
|
|
.ForceFormat("webm"))
|
|
.OutputToPipe(new StreamPipeSink(output), opt => opt
|
|
.ForceFormat("mpegts"))
|
|
.ProcessSynchronously();
|
|
|
|
output.Position = 0;
|
|
var result = FFProbe.Analyse(output);
|
|
Console.WriteLine(result.Duration);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToMP4_Args_StreamOutputPipe_Failure()
|
|
{
|
|
Assert.ThrowsException<FFMpegException>(() =>
|
|
{
|
|
using var ms = new MemoryStream();
|
|
FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToPipe(new StreamPipeSink(ms), opt => opt
|
|
.ForceFormat("mkv"))
|
|
.ProcessSynchronously();
|
|
});
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public async Task Video_ToMP4_Args_StreamOutputPipe_Async()
|
|
{
|
|
await using var ms = new MemoryStream();
|
|
var pipeSource = new StreamPipeSink(ms);
|
|
await FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToPipe(pipeSource, opt => opt
|
|
.WithVideoCodec(VideoCodec.LibX264)
|
|
.ForceFormat("matroska"))
|
|
.ProcessAsynchronously();
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public async Task TestDuplicateRun()
|
|
{
|
|
FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToFile("temporary.mp4")
|
|
.ProcessSynchronously();
|
|
|
|
await FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToFile("temporary.mp4")
|
|
.ProcessAsynchronously();
|
|
|
|
File.Delete("temporary.mp4");
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void TranscodeToMemoryStream_Success()
|
|
{
|
|
using var output = new MemoryStream();
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
.OutputToPipe(new StreamPipeSink(output), opt => opt
|
|
.WithVideoCodec(VideoCodec.LibVpx)
|
|
.ForceFormat("matroska"))
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
|
|
output.Position = 0;
|
|
var inputAnalysis = FFProbe.Analyse(TestResources.WebmVideo);
|
|
var outputAnalysis = FFProbe.Analyse(output);
|
|
Assert.AreEqual(inputAnalysis.Duration.TotalSeconds, outputAnalysis.Duration.TotalSeconds, 0.3);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToTS()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.MpegTs.Extension}");
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToFile(outputFile, false)
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_ToTS_Args()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.MpegTs.Extension}");
|
|
|
|
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);
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyDataTestMethod, Timeout(10000)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
|
public async Task Video_ToTS_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat)
|
|
{
|
|
using var output = new TemporaryFile($"out{VideoType.Ts.Extension}");
|
|
var input = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256));
|
|
|
|
var success = await FFMpegArguments
|
|
.FromPipeInput(input)
|
|
.OutputToFile(output, false, opt => opt
|
|
.ForceFormat(VideoType.Ts))
|
|
.ProcessAsynchronously();
|
|
Assert.IsTrue(success);
|
|
|
|
var analysis = await FFProbe.AnalyseAsync(output);
|
|
Assert.AreEqual(VideoType.Ts.Name, analysis.Format.FormatName);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public async Task Video_ToOGV_Resize()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
|
|
var success = await FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.Resize(200, 200)
|
|
.WithVideoCodec(VideoCodec.LibTheora))
|
|
.ProcessAsynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyDataTestMethod, Timeout(10000)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format48bppRgb)]
|
|
public void RawVideoPipeSource_Ogv_Scale(System.Drawing.Imaging.PixelFormat pixelFormat)
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
|
|
var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256));
|
|
|
|
FFMpegArguments
|
|
.FromPipeInput(videoFramesSource)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithVideoFilters(filterOptions => filterOptions
|
|
.Scale(VideoSize.Ed))
|
|
.WithVideoCodec(VideoCodec.LibTheora))
|
|
.ProcessSynchronously();
|
|
|
|
var analysis = FFProbe.Analyse(outputFile);
|
|
Assert.AreEqual((int)VideoSize.Ed, analysis.PrimaryVideoStream!.Width);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Scale_Mp4_Multithreaded()
|
|
{
|
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.UsingMultithreading(true)
|
|
.WithVideoCodec(VideoCodec.LibX264))
|
|
.ProcessSynchronously();
|
|
Assert.IsTrue(success);
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyDataTestMethod, Timeout(10000)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format24bppRgb)]
|
|
[DataRow(System.Drawing.Imaging.PixelFormat.Format32bppArgb)]
|
|
// [DataRow(PixelFormat.Format48bppRgb)]
|
|
public void Video_ToMP4_Resize_Args_Pipe(System.Drawing.Imaging.PixelFormat pixelFormat)
|
|
{
|
|
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);
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyTestMethod, Timeout(10000)]
|
|
public void Video_Snapshot_InMemory()
|
|
{
|
|
using var bitmap = FFMpegImage.Snapshot(TestResources.Mp4Video);
|
|
|
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
|
Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width);
|
|
Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height);
|
|
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_Snapshot_PersistSnapshot()
|
|
{
|
|
var outputPath = new TemporaryFile("out.png");
|
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
|
|
|
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
|
|
|
|
var analysis = FFProbe.Analyse(outputPath);
|
|
Assert.AreEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width);
|
|
Assert.AreEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height);
|
|
Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_Join()
|
|
{
|
|
var inputCopy = new TemporaryFile("copy-input.mp4");
|
|
File.Copy(TestResources.Mp4Video, inputCopy);
|
|
|
|
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));
|
|
|
|
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);
|
|
Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height);
|
|
Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width);
|
|
}
|
|
|
|
[TestMethod, Timeout(20000)]
|
|
public void Video_Join_Image_Sequence()
|
|
{
|
|
var imageSet = new List<string>();
|
|
Directory.EnumerateFiles(TestResources.ImageCollection, "*.png")
|
|
.ToList()
|
|
.ForEach(file =>
|
|
{
|
|
for (var i = 0; i < 5; i++)
|
|
{
|
|
imageSet.Add(file);
|
|
}
|
|
});
|
|
var imageAnalysis = FFProbe.Analyse(imageSet.First());
|
|
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
var success = FFMpeg.JoinImageSequence(outputFile, frameRate: 10, images: imageSet.ToArray());
|
|
Assert.IsTrue(success);
|
|
var result = FFProbe.Analyse(outputFile);
|
|
|
|
Assert.AreEqual(1, result.Duration.Seconds);
|
|
Assert.AreEqual(imageAnalysis.PrimaryVideoStream!.Width, result.PrimaryVideoStream!.Width);
|
|
Assert.AreEqual(imageAnalysis.PrimaryVideoStream!.Height, result.PrimaryVideoStream.Height);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_With_Only_Audio_Should_Extract_Metadata()
|
|
{
|
|
var video = FFProbe.Analyse(TestResources.Mp4WithoutVideo);
|
|
Assert.AreEqual(null, video.PrimaryVideoStream);
|
|
Assert.AreEqual("aac", video.PrimaryAudioStream!.CodecName);
|
|
Assert.AreEqual(10, video.Duration.TotalSeconds, 0.5);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_Duration()
|
|
{
|
|
var video = FFProbe.Analyse(TestResources.Mp4Video);
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
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);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_UpdatesProgress()
|
|
{
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
var percentageDone = 0.0;
|
|
var timeDone = TimeSpan.Zero;
|
|
var analysis = FFProbe.Analyse(TestResources.Mp4Video);
|
|
|
|
void OnPercentageProgess(double percentage)
|
|
{
|
|
if (percentage < 100)
|
|
{
|
|
percentageDone = percentage;
|
|
}
|
|
}
|
|
|
|
void OnTimeProgess(TimeSpan time)
|
|
{
|
|
if (time < analysis.Duration)
|
|
{
|
|
timeDone = time;
|
|
}
|
|
}
|
|
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithDuration(analysis.Duration))
|
|
.NotifyOnProgress(OnPercentageProgess, analysis.Duration)
|
|
.NotifyOnProgress(OnTimeProgess)
|
|
.ProcessSynchronously();
|
|
|
|
Assert.IsTrue(success);
|
|
Assert.IsTrue(File.Exists(outputFile));
|
|
Assert.AreNotEqual(0.0, percentageDone);
|
|
Assert.AreNotEqual(100.0, percentageDone);
|
|
Assert.AreNotEqual(TimeSpan.Zero, timeDone);
|
|
Assert.AreNotEqual(analysis.Duration, timeDone);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public void Video_OutputsData()
|
|
{
|
|
var outputFile = new TemporaryFile("out.mp4");
|
|
var dataReceived = false;
|
|
|
|
GlobalFFOptions.Configure(opt => opt.Encoding = Encoding.UTF8);
|
|
var success = FFMpegArguments
|
|
.FromFileInput(TestResources.Mp4Video)
|
|
.WithGlobalOptions(options => options
|
|
.WithVerbosityLevel(VerbosityLevel.Info))
|
|
.OutputToFile(outputFile, false, opt => opt
|
|
.WithDuration(TimeSpan.FromSeconds(2)))
|
|
.NotifyOnError(_ => dataReceived = true)
|
|
.ProcessSynchronously();
|
|
|
|
Assert.IsTrue(dataReceived);
|
|
Assert.IsTrue(success);
|
|
Assert.IsTrue(File.Exists(outputFile));
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[WindowsOnlyTestMethod, Timeout(10000)]
|
|
public void Video_TranscodeInMemory()
|
|
{
|
|
using var resStream = new MemoryStream();
|
|
var reader = new StreamPipeSink(resStream);
|
|
var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 128, 128));
|
|
|
|
FFMpegArguments
|
|
.FromPipeInput(writer)
|
|
.OutputToPipe(reader, opt => opt
|
|
.WithVideoCodec("vp9")
|
|
.ForceFormat("webm"))
|
|
.ProcessSynchronously();
|
|
|
|
resStream.Position = 0;
|
|
var vi = FFProbe.Analyse(resStream);
|
|
Assert.AreEqual(vi.PrimaryVideoStream!.Width, 128);
|
|
Assert.AreEqual(vi.PrimaryVideoStream.Height, 128);
|
|
}
|
|
|
|
[TestMethod, Timeout(20000)]
|
|
public void Video_TranscodeToMemory()
|
|
{
|
|
using var memoryStream = new MemoryStream();
|
|
|
|
FFMpegArguments
|
|
.FromFileInput(TestResources.WebmVideo)
|
|
.OutputToPipe(new StreamPipeSink(memoryStream), opt => opt
|
|
.WithVideoCodec("vp9")
|
|
.ForceFormat("webm"))
|
|
.ProcessSynchronously();
|
|
|
|
memoryStream.Position = 0;
|
|
var vi = FFProbe.Analyse(memoryStream);
|
|
Assert.AreEqual(vi.PrimaryVideoStream!.Width, 640);
|
|
Assert.AreEqual(vi.PrimaryVideoStream.Height, 360);
|
|
}
|
|
|
|
[TestMethod, Timeout(10000)]
|
|
public async Task Video_Cancel_Async()
|
|
{
|
|
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)
|
|
.ProcessAsynchronously(false);
|
|
|
|
await Task.Delay(300);
|
|
cancel();
|
|
|
|
var result = await task;
|
|
|
|
Assert.IsFalse(result);
|
|
}
|
|
|
|
[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);
|
|
}
|
|
|
|
[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();
|
|
|
|
await task;
|
|
|
|
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);
|
|
}
|
|
|
|
[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);
|
|
|
|
cts.CancelAfter(300);
|
|
|
|
var result = await task;
|
|
|
|
Assert.IsFalse(result);
|
|
}
|
|
|
|
[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());
|
|
}
|
|
|
|
[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))
|
|
.CancellableThrough(cts.Token, 8000)
|
|
.ProcessAsynchronously(false);
|
|
|
|
cts.CancelAfter(300);
|
|
|
|
await task;
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|