Compare commits

..

11 commits

Author SHA1 Message Date
SinisterMaya
c38c308630
Merge adfc781e4c into 55d526ce92 2025-10-28 19:18:25 +01:00
Malte Rosenbjerg
55d526ce92
Merge pull request #599 from rosenbjerg/Delegate-WithChapter-overload-with-double-argument-to-long-overload-to-reduce-code
Delegate to WithChapter with long argument overload
2025-10-27 21:23:58 +01:00
Malte Rosenbjerg
ebe60ef5da
Merge branch 'main' into Delegate-WithChapter-overload-with-double-argument-to-long-overload-to-reduce-code 2025-10-27 21:13:04 +01:00
Malte Rosenbjerg
e12bc2a148
Merge pull request #600 from rosenbjerg/ensure-cancellationtoken-passed-to-cancellablethrough-is-not-already-cancelled
Throw if CancellationToken passed to CancellableThrough is not already cancelled
2025-10-27 21:12:52 +01:00
Malte Rosenbjerg
736420e916
Merge branch 'main' into ensure-cancellationtoken-passed-to-cancellablethrough-is-not-already-cancelled 2025-10-27 21:08:42 +01:00
Malte Rosenbjerg
f9a3f2b0dc
Merge pull request #601 from rosenbjerg/fix-changing-of-output-extension-in-BaseSubVideo
Fix changing of output extension in BaseSubVideo
2025-10-27 21:08:31 +01:00
Malte Rosenbjerg
1442c08e37 Lower amount of bitmaps used in tests 2025-10-27 21:03:24 +01:00
Malte Rosenbjerg
cdf2dd5b65 Refine unit tests for cancellation 2025-10-27 21:01:36 +01:00
Malte Rosenbjerg
3c6cb1fb43 Throw if CancellationToken passed to CancellableThrough is not already cancelled 2025-10-27 20:49:35 +01:00
Malte Rosenbjerg
df03c58081 Delegate to WithChapter with long argument overload 2025-10-27 20:45:17 +01:00
Malte Rosenbjerg
2a16824e69 Fix changing of output extension in BaseSubVideo 2025-10-27 20:43:56 +01:00
4 changed files with 32 additions and 12 deletions

View file

@ -171,7 +171,7 @@ public class VideoTest
{ {
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(64, pixelFormat, 256, 256));
var success = FFMpegArguments var success = FFMpegArguments
.FromPipeInput(videoFramesSource) .FromPipeInput(videoFramesSource)
.OutputToFile(outputFile, false, opt => opt .OutputToFile(outputFile, false, opt => opt
@ -491,7 +491,7 @@ public class VideoTest
private static async Task Video_ToTS_Args_Pipe_Internal(dynamic pixelFormat, CancellationToken cancellationToken) private static async Task Video_ToTS_Args_Pipe_Internal(dynamic pixelFormat, CancellationToken cancellationToken)
{ {
using var output = new TemporaryFile($"out{VideoType.Ts.Extension}"); using var output = new TemporaryFile($"out{VideoType.Ts.Extension}");
var input = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); var input = new RawVideoPipeSource(BitmapSource.CreateBitmaps(64, pixelFormat, 256, 256));
var success = await FFMpegArguments var success = await FFMpegArguments
.FromPipeInput(input) .FromPipeInput(input)
@ -528,7 +528,7 @@ public class VideoTest
public void RawVideoPipeSource_Ogv_Scale(SKColorType pixelFormat) public void RawVideoPipeSource_Ogv_Scale(SKColorType pixelFormat)
{ {
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}"); using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(64, pixelFormat, 256, 256));
FFMpegArguments FFMpegArguments
.FromPipeInput(videoFramesSource) .FromPipeInput(videoFramesSource)
@ -582,7 +582,7 @@ public class VideoTest
private static void Video_ToMP4_Resize_Args_Pipe_Internal(dynamic pixelFormat, CancellationToken cancellationToken) private static void Video_ToMP4_Resize_Args_Pipe_Internal(dynamic pixelFormat, CancellationToken cancellationToken)
{ {
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(64, pixelFormat, 256, 256));
var success = FFMpegArguments var success = FFMpegArguments
.FromPipeInput(videoFramesSource) .FromPipeInput(videoFramesSource)
@ -944,7 +944,7 @@ public class VideoTest
{ {
using var resStream = new MemoryStream(); using var resStream = new MemoryStream();
var reader = new StreamPipeSink(resStream); var reader = new StreamPipeSink(resStream);
var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 128, 128)); var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(64, pixelFormat, 128, 128));
FFMpegArguments FFMpegArguments
.FromPipeInput(writer) .FromPipeInput(writer)
@ -1139,13 +1139,12 @@ public class VideoTest
[TestMethod] [TestMethod]
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
public void Video_Cancel_CancellationToken_Before_Throws() public void Video_Cancel_CancellationToken_BeforeProcessing_Throws()
{ {
using var outputFile = new TemporaryFile("out.mp4"); using var outputFile = new TemporaryFile("out.mp4");
using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken); using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken);
cts.Cancel();
var task = FFMpegArguments var task = FFMpegArguments
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args .FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
.WithCustomArgument("-re") .WithCustomArgument("-re")
@ -1156,8 +1155,29 @@ public class VideoTest
.WithSpeedPreset(Speed.VeryFast)) .WithSpeedPreset(Speed.VeryFast))
.CancellableThrough(cts.Token); .CancellableThrough(cts.Token);
Assert.ThrowsExactly<OperationCanceledException>(() => task.CancellableThrough(TestContext.CancellationToken) cts.Cancel();
.ProcessSynchronously()); Assert.ThrowsExactly<OperationCanceledException>(() => task.ProcessSynchronously());
}
[TestMethod]
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
public void Video_Cancel_CancellationToken_BeforePassing_Throws()
{
using var outputFile = new TemporaryFile("out.mp4");
using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken);
cts.Cancel();
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));
Assert.ThrowsExactly<OperationCanceledException>(() => task.CancellableThrough(cts.Token));
} }
[TestMethod] [TestMethod]

View file

@ -26,8 +26,7 @@ public class FFMetadataBuilder
public FFMetadataBuilder WithChapter(string title, double durationSeconds) public FFMetadataBuilder WithChapter(string title, double durationSeconds)
{ {
Chapters.Add(new FFMetadataChapter(title, Convert.ToInt64(durationSeconds * 1000))); return WithChapter(title, Convert.ToInt64(durationSeconds * 1000));
return this;
} }
public string GetMetadataFileContent() public string GetMetadataFileContent()

View file

@ -297,7 +297,7 @@ public static class FFMpeg
{ {
if (Path.GetExtension(input) != Path.GetExtension(output)) if (Path.GetExtension(input) != Path.GetExtension(output))
{ {
output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output), Path.GetExtension(input)); output = Path.ChangeExtension(output, Path.GetExtension(input));
} }
return FFMpegArguments return FFMpegArguments

View file

@ -85,6 +85,7 @@ public class FFMpegArgumentProcessor
public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0) public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0)
{ {
token.ThrowIfCancellationRequested();
_cancellationTokenRegistration?.Dispose(); _cancellationTokenRegistration?.Dispose();
_cancellationTokenRegistration = token.Register(() => Cancel(timeout)); _cancellationTokenRegistration = token.Register(() => Cancel(timeout));
return this; return this;