mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-15 02:25:44 +00:00
Update code after update from main
This commit is contained in:
parent
ca305cd8cd
commit
c60e217a2f
2 changed files with 124 additions and 21 deletions
|
|
@ -18,22 +18,26 @@ namespace FFMpegCore.Test;
|
||||||
public class VideoTest
|
public class VideoTest
|
||||||
{
|
{
|
||||||
private const int BaseTimeoutMilliseconds = 15_000;
|
private const int BaseTimeoutMilliseconds = 15_000;
|
||||||
private string _segmentPathSource = "";
|
|
||||||
[TestInitialize]
|
private string _segmentPathSource = "";
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
_segmentPathSource = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}-");
|
|
||||||
}
|
|
||||||
[TestCleanup]
|
|
||||||
public void Cleanup()
|
|
||||||
{
|
|
||||||
foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(_segmentPathSource), Path.GetFileName(_segmentPathSource) + "*"))
|
|
||||||
{
|
|
||||||
File.Delete(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public TestContext TestContext { get; set; }
|
public TestContext TestContext { get; set; }
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_segmentPathSource = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}-");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCleanup]
|
||||||
|
public void Cleanup()
|
||||||
|
{
|
||||||
|
foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(_segmentPathSource), Path.GetFileName(_segmentPathSource) + "*"))
|
||||||
|
{
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
||||||
public void Video_ToOGV()
|
public void Video_ToOGV()
|
||||||
|
|
@ -1081,11 +1085,105 @@ public class VideoTest
|
||||||
|
|
||||||
var outputInfo = await FFProbe.AnalyseAsync(outputFile, cancellationToken: TestContext.CancellationToken);
|
var outputInfo = await FFProbe.AnalyseAsync(outputFile, cancellationToken: TestContext.CancellationToken);
|
||||||
|
|
||||||
Assert.IsNotNull(outputInfo);
|
Assert.IsNotNull(outputInfo);
|
||||||
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
||||||
Assert.AreEqual(240, outputInfo.PrimaryVideoStream.Height);
|
Assert.AreEqual(240, outputInfo.PrimaryVideoStream.Height);
|
||||||
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
||||||
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
||||||
|
public void Video_Segmented_File_Output()
|
||||||
|
{
|
||||||
|
using var input = File.OpenRead(TestResources.WebmVideo);
|
||||||
|
var success = FFMpegArguments
|
||||||
|
.FromPipeInput(new StreamPipeSource(input))
|
||||||
|
.OutPutToSegmentedFiles(
|
||||||
|
new SegmentArgument($"{_segmentPathSource}%Y-%m-%d_%H-%M-%S.mkv", true, segmentOptions => segmentOptions
|
||||||
|
.Strftime(true)
|
||||||
|
.Wrap()
|
||||||
|
.Time()
|
||||||
|
.ResetTimeStamps()),
|
||||||
|
options => options
|
||||||
|
.CopyChannel()
|
||||||
|
.WithVideoCodec("h264")
|
||||||
|
.ForceFormat("matroska")
|
||||||
|
.WithConstantRateFactor(21)
|
||||||
|
.WithVideoBitrate(3000)
|
||||||
|
.WithFastStart()
|
||||||
|
.WithVideoFilters(filterOptions => filterOptions
|
||||||
|
.Scale(VideoSize.Hd)
|
||||||
|
.DrawText(DrawTextOptions.Create(@"'%{localtime}.%{eif\:1M*t-1K*trunc(t*1K)\:d\:3}'",
|
||||||
|
@"C:/Users/yan.gauthier/AppData/Local/Microsoft/Windows/Fonts/Roboto-Regular.ttf")
|
||||||
|
.WithParameter("fontcolor", "yellow")
|
||||||
|
.WithParameter("fontsize", "40")
|
||||||
|
.WithParameter("x", "(w-text_w)")
|
||||||
|
.WithParameter("y", "(h - text_h)")
|
||||||
|
.WithParameter("rate", "19")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.CancellableThrough(TestContext.CancellationToken)
|
||||||
|
.ProcessSynchronously(false);
|
||||||
|
Assert.IsTrue(success);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
||||||
|
public void Video_MultiOutput_With_Segmented_File_Output()
|
||||||
|
{
|
||||||
|
using var input = File.OpenRead(TestResources.WebmVideo);
|
||||||
|
var success = FFMpegArguments
|
||||||
|
.FromPipeInput(new StreamPipeSource(input))
|
||||||
|
.MultiOutput(args => args
|
||||||
|
.OutputToFile($"{_segmentPathSource}2", true, options => options
|
||||||
|
.CopyChannel()
|
||||||
|
.WithVideoCodec("mjpeg")
|
||||||
|
.ForceFormat("matroska")
|
||||||
|
.WithConstantRateFactor(21)
|
||||||
|
.WithVideoBitrate(4000)
|
||||||
|
.WithFastStart()
|
||||||
|
.WithVideoFilters(filterOptions => filterOptions
|
||||||
|
.Scale(VideoSize.Hd)
|
||||||
|
.DrawText(DrawTextOptions.Create(@"'%{localtime}.%{eif\:1M*t-1K*trunc(t*1K)\:d\:3}'",
|
||||||
|
@"C:/Users/yan.gauthier/AppData/Local/Microsoft/Windows/Fonts/Roboto-Regular.ttf")
|
||||||
|
.WithParameter("fontcolor", "yellow")
|
||||||
|
.WithParameter("fontsize", "40")
|
||||||
|
.WithParameter("x", "(w-text_w)")
|
||||||
|
.WithParameter("y", "(h - text_h)")
|
||||||
|
.WithParameter("rate", "19")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.OutPutToSegmentedFiles(
|
||||||
|
new SegmentArgument($"{_segmentPathSource}%Y-%m-%d_%H-%M-%S.mkv", true, segmentOptions => segmentOptions
|
||||||
|
.Strftime(true)
|
||||||
|
.Wrap()
|
||||||
|
.Time()
|
||||||
|
.ResetTimeStamps()),
|
||||||
|
options => options
|
||||||
|
.CopyChannel()
|
||||||
|
.WithVideoCodec("h264")
|
||||||
|
.ForceFormat("matroska")
|
||||||
|
.WithConstantRateFactor(21)
|
||||||
|
.WithVideoBitrate(3000)
|
||||||
|
.WithFastStart()
|
||||||
|
.WithVideoFilters(filterOptions => filterOptions
|
||||||
|
.Scale(VideoSize.Hd)
|
||||||
|
.DrawText(DrawTextOptions.Create(@"'%{localtime}.%{eif\:1M*t-1K*trunc(t*1K)\:d\:3}'",
|
||||||
|
@"C:/Users/yan.gauthier/AppData/Local/Microsoft/Windows/Fonts/Roboto-Regular.ttf")
|
||||||
|
.WithParameter("fontcolor", "yellow")
|
||||||
|
.WithParameter("fontsize", "40")
|
||||||
|
.WithParameter("x", "(w-text_w)")
|
||||||
|
.WithParameter("y", "(h - text_h)")
|
||||||
|
.WithParameter("rate", "19")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.CancellableThrough(TestContext.CancellationToken)
|
||||||
|
.ProcessSynchronously(false);
|
||||||
|
Assert.IsTrue(success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,12 @@ public sealed class FFMpegArguments : FFMpegArgumentsBase
|
||||||
{
|
{
|
||||||
return ToProcessor(new OutputPipeArgument(reader), addArguments);
|
return ToProcessor(new OutputPipeArgument(reader), addArguments);
|
||||||
}
|
}
|
||||||
public FFMpegArgumentProcessor OutPutToSegmentedFiles(SegmentArgument segmentArgument, Action<FFMpegArgumentOptions>? addArguments = null) => ToProcessor(new OutputSegmentArgument(segmentArgument), addArguments);
|
|
||||||
|
public FFMpegArgumentProcessor OutPutToSegmentedFiles(SegmentArgument segmentArgument, Action<FFMpegArgumentOptions>? addArguments = null)
|
||||||
|
{
|
||||||
|
return ToProcessor(new OutputSegmentArgument(segmentArgument), addArguments);
|
||||||
|
}
|
||||||
|
|
||||||
private FFMpegArgumentProcessor ToProcessor(IOutputArgument argument, Action<FFMpegArgumentOptions>? addArguments)
|
private FFMpegArgumentProcessor ToProcessor(IOutputArgument argument, Action<FFMpegArgumentOptions>? addArguments)
|
||||||
{
|
{
|
||||||
var args = new FFMpegArgumentOptions();
|
var args = new FFMpegArgumentOptions();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue