From e01b73787dbe8ff26e1577880ce3907dcb966277 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 21:48:30 +0200 Subject: [PATCH 01/12] Improve cancellation handling --- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 51 +++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index 590c099..18ee9dd 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -10,8 +10,11 @@ namespace FFMpegCore; public class FFMpegArgumentProcessor { private static readonly Regex ProgressRegex = new(@"time=(\d\d:\d\d:\d\d.\d\d?)", RegexOptions.Compiled); + private readonly CancellationTokenSource _cancellationTokenSource = new(); private readonly List> _configurations; private readonly FFMpegArguments _ffMpegArguments; + private CancellationTokenRegistration? _cancellationTokenRegistration; + private bool _cancelled; private FFMpegLogLevel? _logLevel; private Action? _onError; private Action? _onOutput; @@ -29,6 +32,12 @@ public class FFMpegArgumentProcessor private event EventHandler CancelEvent = null!; + ~FFMpegArgumentProcessor() + { + _cancellationTokenSource.Dispose(); + _cancellationTokenRegistration?.Dispose(); + } + /// /// Register action that will be invoked during the ffmpeg processing, when a progress time is output and parsed and progress percentage is /// calculated. @@ -71,13 +80,21 @@ public class FFMpegArgumentProcessor public FFMpegArgumentProcessor CancellableThrough(out Action cancel, int timeout = 0) { - cancel = () => CancelEvent?.Invoke(this, timeout); + cancel = () => + { + _cancelled = true; + CancelEvent?.Invoke(this, timeout); + }; return this; } public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0) { - token.Register(() => CancelEvent?.Invoke(this, timeout)); + _cancellationTokenRegistration = token.Register(() => + { + _cancelled = true; + CancelEvent?.Invoke(this, timeout); + }); return this; } @@ -101,12 +118,12 @@ public class FFMpegArgumentProcessor public bool ProcessSynchronously(bool throwOnError = true, FFOptions? ffMpegOptions = null) { var options = GetConfiguredOptions(ffMpegOptions); - var processArguments = PrepareProcessArguments(options, out var cancellationTokenSource); + var processArguments = PrepareProcessArguments(options); IProcessResult? processResult = null; try { - processResult = Process(processArguments, cancellationTokenSource).ConfigureAwait(false).GetAwaiter().GetResult(); + processResult = Process(processArguments).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (OperationCanceledException) { @@ -122,12 +139,12 @@ public class FFMpegArgumentProcessor public async Task ProcessAsynchronously(bool throwOnError = true, FFOptions? ffMpegOptions = null) { var options = GetConfiguredOptions(ffMpegOptions); - var processArguments = PrepareProcessArguments(options, out var cancellationTokenSource); + var processArguments = PrepareProcessArguments(options); IProcessResult? processResult = null; try { - processResult = await Process(processArguments, cancellationTokenSource).ConfigureAwait(false); + processResult = await Process(processArguments).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -140,23 +157,25 @@ public class FFMpegArgumentProcessor return HandleCompletion(throwOnError, processResult?.ExitCode ?? -1, processResult?.ErrorData ?? Array.Empty()); } - private async Task Process(ProcessArguments processArguments, CancellationTokenSource cancellationTokenSource) + private async Task Process(ProcessArguments processArguments) { IProcessResult processResult = null!; + if (_cancelled) + { + throw new OperationCanceledException("cancelled before starting processing"); + } _ffMpegArguments.Pre(); using var instance = processArguments.Start(); - var cancelled = false; void OnCancelEvent(object sender, int timeout) { - cancelled = true; instance.SendInput("q"); - if (!cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true)) + if (!_cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true)) { - cancellationTokenSource.Cancel(); + _cancellationTokenSource.Cancel(); instance.Kill(); } } @@ -168,11 +187,11 @@ public class FFMpegArgumentProcessor await Task.WhenAll(instance.WaitForExitAsync().ContinueWith(t => { processResult = t.Result; - cancellationTokenSource.Cancel(); + _cancellationTokenSource.Cancel(); _ffMpegArguments.Post(); - }), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false); + }), _ffMpegArguments.During(_cancellationTokenSource.Token)).ConfigureAwait(false); - if (cancelled) + if (_cancelled) { throw new OperationCanceledException("ffmpeg processing was cancelled"); } @@ -214,8 +233,7 @@ public class FFMpegArgumentProcessor return options; } - private ProcessArguments PrepareProcessArguments(FFOptions ffOptions, - out CancellationTokenSource cancellationTokenSource) + private ProcessArguments PrepareProcessArguments(FFOptions ffOptions) { FFMpegHelper.RootExceptionCheck(); FFMpegHelper.VerifyFFMpegExists(ffOptions); @@ -245,7 +263,6 @@ public class FFMpegArgumentProcessor WorkingDirectory = ffOptions.WorkingDirectory }; var processArguments = new ProcessArguments(startInfo); - cancellationTokenSource = new CancellationTokenSource(); if (_onOutput != null) { From 4baddaab7fa7f724724134ac21ab0378db40200a Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 21:51:11 +0200 Subject: [PATCH 02/12] Add test verifying cancellation before processing starts --- FFMpegCore.Test/VideoTest.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 7946552..5921a6e 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -1043,6 +1043,28 @@ public class VideoTest Assert.ThrowsExactly(() => task.ProcessSynchronously()); } + [TestMethod] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public void Video_Cancel_CancellationToken_Before_Throws() + { + using var outputFile = new TemporaryFile("out.mp4"); + + var cts = new CancellationTokenSource(); + + 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)) + .CancellableThrough(cts.Token); + + Assert.ThrowsExactly(() => task.ProcessSynchronously()); + } + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public async Task Video_Cancel_CancellationToken_Async_With_Timeout() From 670986dcb2404d3ad159337ebd2c8ffd7c35d763 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 21:54:19 +0200 Subject: [PATCH 03/12] Extract method for reuse --- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index 18ee9dd..163e113 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -78,23 +78,22 @@ public class FFMpegArgumentProcessor return this; } + private void Cancel(int timeout) + { + _cancelled = true; + CancelEvent?.Invoke(this, timeout); + } + public FFMpegArgumentProcessor CancellableThrough(out Action cancel, int timeout = 0) { - cancel = () => - { - _cancelled = true; - CancelEvent?.Invoke(this, timeout); - }; + cancel = () => Cancel(timeout); return this; } + public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0) { - _cancellationTokenRegistration = token.Register(() => - { - _cancelled = true; - CancelEvent?.Invoke(this, timeout); - }); + _cancellationTokenRegistration = token.Register(() => Cancel(timeout)); return this; } From d8904292691bca19a0bfabc0472db9ac67a33871 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 21:56:40 +0200 Subject: [PATCH 04/12] Remove extranous blank line --- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index 163e113..0aa31ca 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -90,7 +90,6 @@ public class FFMpegArgumentProcessor return this; } - public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0) { _cancellationTokenRegistration = token.Register(() => Cancel(timeout)); From fab7ff0aaba6f02f5e464a02d4dc35afafba77e1 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 22:37:39 +0200 Subject: [PATCH 05/12] Ensure TestContext.CancellationToken is used --- FFMpegCore.Test/AudioTest.cs | 17 +++++++ FFMpegCore.Test/VideoTest.cs | 99 ++++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 28 deletions(-) diff --git a/FFMpegCore.Test/AudioTest.cs b/FFMpegCore.Test/AudioTest.cs index 3960b9f..3f0f25e 100644 --- a/FFMpegCore.Test/AudioTest.cs +++ b/FFMpegCore.Test/AudioTest.cs @@ -9,6 +9,8 @@ namespace FFMpegCore.Test; [TestClass] public class AudioTest { + public TestContext TestContext { get; set; } + [TestMethod] public void Audio_Remove() { @@ -41,6 +43,7 @@ public class AudioTest await FFMpegArguments .FromPipeInput(new StreamPipeSource(file), options => options.ForceFormat("s16le")) .OutputToPipe(new StreamPipeSink(memoryStream), options => options.ForceFormat("mp3")) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(); } @@ -83,6 +86,7 @@ public class AudioTest .FromPipeInput(audioSamplesSource) .OutputToFile(outputFile, false, opt => opt .WithAudioCodec(AudioCodec.Aac)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -101,6 +105,7 @@ public class AudioTest .FromPipeInput(audioSamplesSource) .OutputToFile(outputFile, false, opt => opt .WithAudioCodec(AudioCodec.LibVorbis)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -119,6 +124,7 @@ public class AudioTest .FromPipeInput(audioSamplesSource) .OutputToFile(outputFile, false, opt => opt .WithAudioCodec(AudioCodec.Aac)) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(); Assert.IsTrue(success); } @@ -137,6 +143,7 @@ public class AudioTest .FromPipeInput(audioSamplesSource) .OutputToFile(outputFile, false, opt => opt .WithAudioCodec(AudioCodec.Aac)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -153,6 +160,7 @@ public class AudioTest .FromPipeInput(audioSamplesSource) .OutputToFile(outputFile, false, opt => opt .WithAudioCodec(AudioCodec.Aac)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously()); } @@ -168,6 +176,7 @@ public class AudioTest .FromPipeInput(audioSamplesSource) .OutputToFile(outputFile, false, opt => opt .WithAudioCodec(AudioCodec.Aac)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously()); } @@ -183,6 +192,7 @@ public class AudioTest .FromPipeInput(audioSamplesSource) .OutputToFile(outputFile, false, opt => opt .WithAudioCodec(AudioCodec.Aac)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously()); } @@ -196,6 +206,7 @@ public class AudioTest .OutputToFile(outputFile, true, argumentOptions => argumentOptions .WithAudioFilters(filter => filter.Pan(1, "c0 < 0.9 * c0 + 0.1 * c1"))) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); var mediaAnalysis = FFProbe.Analyse(outputFile); @@ -215,6 +226,7 @@ public class AudioTest .OutputToFile(outputFile, true, argumentOptions => argumentOptions .WithAudioFilters(filter => filter.Pan(1))) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); var mediaAnalysis = FFProbe.Analyse(outputFile); @@ -234,6 +246,7 @@ public class AudioTest .OutputToFile(outputFile, true, argumentOptions => argumentOptions .WithAudioFilters(filter => filter.Pan(1, "c0=c0", "c1=c1"))) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously()); } @@ -247,6 +260,7 @@ public class AudioTest .OutputToFile(outputFile, true, argumentOptions => argumentOptions .WithAudioFilters(filter => filter.Pan("mono", "c0=c0", "c1=c1"))) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously()); } @@ -260,6 +274,7 @@ public class AudioTest .OutputToFile(outputFile, true, argumentOptions => argumentOptions .WithAudioFilters(filter => filter.DynamicNormalizer())) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); @@ -275,6 +290,7 @@ public class AudioTest .OutputToFile(outputFile, true, argumentOptions => argumentOptions .WithAudioFilters(filter => filter.DynamicNormalizer(250, 7, 0.9, 2, 1, false, true, true, 0.5))) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); @@ -294,6 +310,7 @@ public class AudioTest .OutputToFile(outputFile, true, argumentOptions => argumentOptions .WithAudioFilters(filter => filter.DynamicNormalizer(filterWindow: filterWindow))) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously()); } } diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 5921a6e..522c925 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -30,6 +30,7 @@ public class VideoTest var success = FFMpegArguments .FromFileInput(TestResources.WebmVideo) .OutputToFile(outputFile, false) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -43,6 +44,7 @@ public class VideoTest var success = FFMpegArguments .FromFileInput(TestResources.WebmVideo) .OutputToFile(outputFile, false) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -58,6 +60,7 @@ public class VideoTest .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264) .ForcePixelFormat("yuv444p")) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); var analysis = FFProbe.Analyse(outputFile); @@ -74,6 +77,7 @@ public class VideoTest .FromFileInput(TestResources.WebmVideo) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -88,6 +92,7 @@ public class VideoTest .FromFileInput(TestResources.WebmVideo) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX265)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -99,7 +104,7 @@ public class VideoTest [DataRow(PixelFormat.Format32bppArgb)] public void Video_ToMP4_Args_Pipe_WindowsOnly(PixelFormat pixelFormat) { - Video_ToMP4_Args_Pipe_Internal(pixelFormat); + Video_ToMP4_Args_Pipe_Internal(pixelFormat, TestContext.CancellationToken); } [TestMethod] @@ -108,10 +113,10 @@ public class VideoTest [DataRow(SKColorType.Bgra8888)] public void Video_ToMP4_Args_Pipe(SKColorType pixelFormat) { - Video_ToMP4_Args_Pipe_Internal(pixelFormat); + Video_ToMP4_Args_Pipe_Internal(pixelFormat, TestContext.CancellationToken); } - private static void Video_ToMP4_Args_Pipe_Internal(dynamic pixelFormat) + private static void Video_ToMP4_Args_Pipe_Internal(dynamic pixelFormat, CancellationToken cancellationToken) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -120,6 +125,7 @@ public class VideoTest .FromPipeInput(videoFramesSource) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(cancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -129,17 +135,17 @@ public class VideoTest [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_ToMP4_Args_Pipe_DifferentImageSizes_WindowsOnly() { - Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal(PixelFormat.Format24bppRgb); + Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal(PixelFormat.Format24bppRgb, TestContext.CancellationToken); } [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_ToMP4_Args_Pipe_DifferentImageSizes() { - Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal(SKColorType.Rgb565); + Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal(SKColorType.Rgb565, TestContext.CancellationToken); } - private static void Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal(dynamic pixelFormat) + private static void Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal(dynamic pixelFormat, CancellationToken cancellationToken) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -153,6 +159,7 @@ public class VideoTest .FromPipeInput(videoFramesSource) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(cancellationToken) .ProcessSynchronously()); } @@ -161,17 +168,17 @@ public class VideoTest [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public async Task Video_ToMP4_Args_Pipe_DifferentImageSizes_WindowsOnly_Async() { - await Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal_Async(PixelFormat.Format24bppRgb); + await Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal_Async(PixelFormat.Format24bppRgb, TestContext.CancellationToken); } [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public async Task Video_ToMP4_Args_Pipe_DifferentImageSizes_Async() { - await Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal_Async(SKColorType.Rgb565); + await Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal_Async(SKColorType.Rgb565, TestContext.CancellationToken); } - private static async Task Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal_Async(dynamic pixelFormat) + private static async Task Video_ToMP4_Args_Pipe_DifferentImageSizes_Internal_Async(dynamic pixelFormat, CancellationToken cancellationToken) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -185,6 +192,7 @@ public class VideoTest .FromPipeInput(videoFramesSource) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(cancellationToken) .ProcessAsynchronously()); } @@ -194,20 +202,22 @@ public class VideoTest public void Video_ToMP4_Args_Pipe_DifferentPixelFormats_WindowsOnly() { Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal(PixelFormat.Format24bppRgb, - PixelFormat.Format32bppRgb); + PixelFormat.Format32bppRgb, TestContext.CancellationToken); } [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_ToMP4_Args_Pipe_DifferentPixelFormats() { - Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal(SKColorType.Rgb565, SKColorType.Bgra8888); + Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal(SKColorType.Rgb565, SKColorType.Bgra8888, TestContext.CancellationToken); } - private static void Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal(dynamic pixelFormatFrame1, dynamic pixelFormatFrame2) + private static void Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal(dynamic pixelFormatFrame1, dynamic pixelFormatFrame2, + CancellationToken cancellationToken) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); + var frames = new List { BitmapSource.CreateVideoFrame(0, pixelFormatFrame1, 255, 255, 1, 0), BitmapSource.CreateVideoFrame(0, pixelFormatFrame2, 255, 255, 1, 0) @@ -218,6 +228,7 @@ public class VideoTest .FromPipeInput(videoFramesSource) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(cancellationToken) .ProcessSynchronously()); } @@ -227,17 +238,18 @@ public class VideoTest public async Task Video_ToMP4_Args_Pipe_DifferentPixelFormats_WindowsOnly_Async() { await Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal_Async(PixelFormat.Format24bppRgb, - PixelFormat.Format32bppRgb); + PixelFormat.Format32bppRgb, TestContext.CancellationToken); } [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public async Task Video_ToMP4_Args_Pipe_DifferentPixelFormats_Async() { - await Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal_Async(SKColorType.Rgb565, SKColorType.Bgra8888); + await Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal_Async(SKColorType.Rgb565, SKColorType.Bgra8888, TestContext.CancellationToken); } - private static async Task Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal_Async(dynamic pixelFormatFrame1, dynamic pixelFormatFrame2) + private static async Task Video_ToMP4_Args_Pipe_DifferentPixelFormats_Internal_Async(dynamic pixelFormatFrame1, dynamic pixelFormatFrame2, + CancellationToken cancellationToken) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -251,6 +263,7 @@ public class VideoTest .FromPipeInput(videoFramesSource) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(cancellationToken) .ProcessAsynchronously()); } @@ -265,6 +278,7 @@ public class VideoTest .FromPipeInput(new StreamPipeSource(input)) .OutputToFile(output, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -280,6 +294,7 @@ public class VideoTest await FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToPipe(pipeSource, opt => opt.ForceFormat("mp4")) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(); }); } @@ -295,6 +310,7 @@ public class VideoTest .ForceFormat("webm")) .OutputToPipe(new StreamPipeSink(output), opt => opt .ForceFormat("mpegts")) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); output.Position = 0; @@ -313,6 +329,7 @@ public class VideoTest .FromFileInput(TestResources.Mp4Video) .OutputToPipe(new StreamPipeSink(ms), opt => opt .ForceFormat("mkv")) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); }); } @@ -328,6 +345,7 @@ public class VideoTest .OutputToPipe(pipeSource, opt => opt .WithVideoCodec(VideoCodec.LibX264) .ForceFormat("matroska")) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(); } @@ -338,11 +356,13 @@ public class VideoTest FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToFile("temporary.mp4") + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); await FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToFile("temporary.mp4") + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(); File.Delete("temporary.mp4"); @@ -358,6 +378,7 @@ public class VideoTest .OutputToPipe(new StreamPipeSink(output), opt => opt .WithVideoCodec(VideoCodec.LibVpx) .ForceFormat("matroska")) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); @@ -376,6 +397,7 @@ public class VideoTest var success = FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToFile(outputFile, false) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -392,6 +414,7 @@ public class VideoTest .CopyChannel() .WithBitStreamFilter(Channel.Video, Filter.H264_Mp4ToAnnexB) .ForceFormat(VideoType.MpegTs)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -403,7 +426,7 @@ public class VideoTest [DataRow(PixelFormat.Format32bppArgb)] public async Task Video_ToTS_Args_Pipe_WindowsOnly(PixelFormat pixelFormat) { - await Video_ToTS_Args_Pipe_Internal(pixelFormat); + await Video_ToTS_Args_Pipe_Internal(pixelFormat, TestContext.CancellationToken); } [TestMethod] @@ -412,10 +435,10 @@ public class VideoTest [DataRow(SKColorType.Bgra8888)] public async Task Video_ToTS_Args_Pipe(SKColorType pixelFormat) { - await Video_ToTS_Args_Pipe_Internal(pixelFormat); + await Video_ToTS_Args_Pipe_Internal(pixelFormat, TestContext.CancellationToken); } - private static async Task Video_ToTS_Args_Pipe_Internal(dynamic pixelFormat) + private static async Task Video_ToTS_Args_Pipe_Internal(dynamic pixelFormat, CancellationToken cancellationToken) { using var output = new TemporaryFile($"out{VideoType.Ts.Extension}"); var input = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); @@ -424,6 +447,7 @@ public class VideoTest .FromPipeInput(input) .OutputToFile(output, false, opt => opt .ForceFormat(VideoType.Ts)) + .CancellableThrough(cancellationToken) .ProcessAsynchronously(); Assert.IsTrue(success); @@ -441,6 +465,7 @@ public class VideoTest .OutputToFile(outputFile, false, opt => opt .Resize(200, 200) .WithVideoCodec(VideoCodec.LibTheora)) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(); Assert.IsTrue(success); } @@ -461,6 +486,7 @@ public class VideoTest .WithVideoFilters(filterOptions => filterOptions .Scale(VideoSize.Ed)) .WithVideoCodec(VideoCodec.LibTheora)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); var analysis = FFProbe.Analyse(outputFile); @@ -478,6 +504,7 @@ public class VideoTest .OutputToFile(outputFile, false, opt => opt .UsingMultithreading(true) .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -490,7 +517,7 @@ public class VideoTest // [DataRow(PixelFormat.Format48bppRgb)] public void Video_ToMP4_Resize_Args_Pipe(PixelFormat pixelFormat) { - Video_ToMP4_Resize_Args_Pipe_Internal(pixelFormat); + Video_ToMP4_Resize_Args_Pipe_Internal(pixelFormat, TestContext.CancellationToken); } [TestMethod] @@ -499,10 +526,10 @@ public class VideoTest [DataRow(SKColorType.Bgra8888)] public void Video_ToMP4_Resize_Args_Pipe(SKColorType pixelFormat) { - Video_ToMP4_Resize_Args_Pipe_Internal(pixelFormat); + Video_ToMP4_Resize_Args_Pipe_Internal(pixelFormat, TestContext.CancellationToken); } - private static void Video_ToMP4_Resize_Args_Pipe_Internal(dynamic pixelFormat) + private static void Video_ToMP4_Resize_Args_Pipe_Internal(dynamic pixelFormat, CancellationToken cancellationToken) { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); @@ -511,6 +538,7 @@ public class VideoTest .FromPipeInput(videoFramesSource) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264)) + .CancellableThrough(cancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); } @@ -764,6 +792,7 @@ public class VideoTest FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToFile(outputFile, false, opt => opt.WithDuration(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 2))) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(File.Exists(outputFile)); @@ -807,6 +836,7 @@ public class VideoTest .WithDuration(analysis.Duration)) .NotifyOnProgress(OnPercentageProgess, analysis.Duration) .NotifyOnProgress(OnTimeProgess) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(success); @@ -832,6 +862,7 @@ public class VideoTest .WithDuration(TimeSpan.FromSeconds(2))) .NotifyOnError(_ => dataReceived = true) .Configure(opt => opt.Encoding = Encoding.UTF8) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); Assert.IsTrue(dataReceived); @@ -844,17 +875,17 @@ public class VideoTest [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_TranscodeInMemory_WindowsOnly() { - Video_TranscodeInMemory_Internal(PixelFormat.Format24bppRgb); + Video_TranscodeInMemory_Internal(PixelFormat.Format24bppRgb, TestContext.CancellationToken); } [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_TranscodeInMemory() { - Video_TranscodeInMemory_Internal(SKColorType.Rgb565); + Video_TranscodeInMemory_Internal(SKColorType.Rgb565, TestContext.CancellationToken); } - private static void Video_TranscodeInMemory_Internal(dynamic pixelFormat) + private static void Video_TranscodeInMemory_Internal(dynamic pixelFormat, CancellationToken cancellationToken) { using var resStream = new MemoryStream(); var reader = new StreamPipeSink(resStream); @@ -865,6 +896,7 @@ public class VideoTest .OutputToPipe(reader, opt => opt .WithVideoCodec("vp9") .ForceFormat("webm")) + .CancellableThrough(cancellationToken) .ProcessSynchronously(); resStream.Position = 0; @@ -884,6 +916,7 @@ public class VideoTest .OutputToPipe(new StreamPipeSink(memoryStream), opt => opt .WithVideoCodec("vp9") .ForceFormat("webm")) + .CancellableThrough(TestContext.CancellationToken) .ProcessSynchronously(); memoryStream.Position = 0; @@ -907,6 +940,8 @@ public class VideoTest .WithVideoCodec(VideoCodec.LibX264) .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(out var cancel) + .CancellableThrough(TestContext.CancellationToken) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(false); await Task.Delay(300, TestContext.CancellationToken); @@ -930,11 +965,13 @@ public class VideoTest .WithAudioCodec(AudioCodec.Aac) .WithVideoCodec(VideoCodec.LibX264) .WithSpeedPreset(Speed.VeryFast)) - .CancellableThrough(out var cancel); + .CancellableThrough(out var cancel) + .CancellableThrough(TestContext.CancellationToken); Task.Delay(300, TestContext.CancellationToken).ContinueWith(_ => cancel(), TestContext.CancellationToken); - var result = task.ProcessSynchronously(false); + var result = task.CancellableThrough(TestContext.CancellationToken) + .ProcessSynchronously(false); Assert.IsFalse(result); } @@ -954,6 +991,7 @@ public class VideoTest .WithVideoCodec(VideoCodec.LibX264) .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(out var cancel, 10000) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(false); await Task.Delay(300, TestContext.CancellationToken); @@ -987,6 +1025,7 @@ public class VideoTest .WithVideoCodec(VideoCodec.LibX264) .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(cts.Token) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(false); cts.CancelAfter(300); @@ -1013,6 +1052,7 @@ public class VideoTest .WithVideoCodec(VideoCodec.LibX264) .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(cts.Token) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(); cts.CancelAfter(300); @@ -1040,7 +1080,8 @@ public class VideoTest cts.CancelAfter(300); - Assert.ThrowsExactly(() => task.ProcessSynchronously()); + Assert.ThrowsExactly(() => task.CancellableThrough(TestContext.CancellationToken) + .ProcessSynchronously()); } [TestMethod] @@ -1062,7 +1103,8 @@ public class VideoTest .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(cts.Token); - Assert.ThrowsExactly(() => task.ProcessSynchronously()); + Assert.ThrowsExactly(() => task.CancellableThrough(TestContext.CancellationToken) + .ProcessSynchronously()); } [TestMethod] @@ -1082,6 +1124,7 @@ public class VideoTest .WithVideoCodec(VideoCodec.LibX264) .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(cts.Token, 8000) + .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(false); cts.CancelAfter(300); From 326b3e271989e9f8dec6ab19ffaff4bd35262cb3 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 22:43:25 +0200 Subject: [PATCH 06/12] Use local CancellationTokenSource --- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 27 ++++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index 0aa31ca..2f350ce 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -10,7 +10,6 @@ namespace FFMpegCore; public class FFMpegArgumentProcessor { private static readonly Regex ProgressRegex = new(@"time=(\d\d:\d\d:\d\d.\d\d?)", RegexOptions.Compiled); - private readonly CancellationTokenSource _cancellationTokenSource = new(); private readonly List> _configurations; private readonly FFMpegArguments _ffMpegArguments; private CancellationTokenRegistration? _cancellationTokenRegistration; @@ -32,12 +31,6 @@ public class FFMpegArgumentProcessor private event EventHandler CancelEvent = null!; - ~FFMpegArgumentProcessor() - { - _cancellationTokenSource.Dispose(); - _cancellationTokenRegistration?.Dispose(); - } - /// /// Register action that will be invoked during the ffmpeg processing, when a progress time is output and parsed and progress percentage is /// calculated. @@ -92,6 +85,7 @@ public class FFMpegArgumentProcessor public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0) { + _cancellationTokenRegistration?.Dispose(); _cancellationTokenRegistration = token.Register(() => Cancel(timeout)); return this; } @@ -117,11 +111,12 @@ public class FFMpegArgumentProcessor { var options = GetConfiguredOptions(ffMpegOptions); var processArguments = PrepareProcessArguments(options); + using var cancellationTokenSource = new CancellationTokenSource(); IProcessResult? processResult = null; try { - processResult = Process(processArguments).ConfigureAwait(false).GetAwaiter().GetResult(); + processResult = Process(processArguments, cancellationTokenSource).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (OperationCanceledException) { @@ -138,11 +133,12 @@ public class FFMpegArgumentProcessor { var options = GetConfiguredOptions(ffMpegOptions); var processArguments = PrepareProcessArguments(options); + using var cancellationTokenSource = new CancellationTokenSource(); IProcessResult? processResult = null; try { - processResult = await Process(processArguments).ConfigureAwait(false); + processResult = await Process(processArguments, cancellationTokenSource).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -155,11 +151,12 @@ public class FFMpegArgumentProcessor return HandleCompletion(throwOnError, processResult?.ExitCode ?? -1, processResult?.ErrorData ?? Array.Empty()); } - private async Task Process(ProcessArguments processArguments) + private async Task Process(ProcessArguments processArguments, CancellationTokenSource cancellationTokenSource) { IProcessResult processResult = null!; if (_cancelled) { + _cancellationTokenRegistration?.Dispose(); throw new OperationCanceledException("cancelled before starting processing"); } @@ -171,9 +168,9 @@ public class FFMpegArgumentProcessor { instance.SendInput("q"); - if (!_cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true)) + if (!cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true)) { - _cancellationTokenSource.Cancel(); + cancellationTokenSource.Cancel(); instance.Kill(); } } @@ -185,12 +182,13 @@ public class FFMpegArgumentProcessor await Task.WhenAll(instance.WaitForExitAsync().ContinueWith(t => { processResult = t.Result; - _cancellationTokenSource.Cancel(); + cancellationTokenSource.Cancel(); _ffMpegArguments.Post(); - }), _ffMpegArguments.During(_cancellationTokenSource.Token)).ConfigureAwait(false); + }), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false); if (_cancelled) { + _cancellationTokenRegistration?.Dispose(); throw new OperationCanceledException("ffmpeg processing was cancelled"); } @@ -199,6 +197,7 @@ public class FFMpegArgumentProcessor finally { CancelEvent -= OnCancelEvent; + _cancellationTokenRegistration?.Dispose(); } } From 40414ad008b2b21e3b727507d7d4e79fc9f6e7a9 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 22:46:45 +0200 Subject: [PATCH 07/12] Remove extranous blank line --- FFMpegCore.Test/VideoTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 522c925..ec97cec 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -217,7 +217,6 @@ public class VideoTest { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); - var frames = new List { BitmapSource.CreateVideoFrame(0, pixelFormatFrame1, 255, 255, 1, 0), BitmapSource.CreateVideoFrame(0, pixelFormatFrame2, 255, 255, 1, 0) From d0f6db1a2ab2a516e3e3be3ca0e1fa1e881ee45c Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 22:52:33 +0200 Subject: [PATCH 08/12] Dont override in test using cancellationtoken --- FFMpegCore.Test/VideoTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index ec97cec..edcf911 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -1123,7 +1123,6 @@ public class VideoTest .WithVideoCodec(VideoCodec.LibX264) .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(cts.Token, 8000) - .CancellableThrough(TestContext.CancellationToken) .ProcessAsynchronously(false); cts.CancelAfter(300); From f11b168ed9002b986b4e4e259f50f12ea1eed7c6 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 23:15:16 +0200 Subject: [PATCH 09/12] Increase timeout because of slow windows CI agents --- FFMpegCore.Test/VideoTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index edcf911..cf88c64 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -17,7 +17,7 @@ namespace FFMpegCore.Test; [TestClass] public class VideoTest { - private const int BaseTimeoutMilliseconds = 15_000; + private const int BaseTimeoutMilliseconds = 30_000; public TestContext TestContext { get; set; } From 90be0888e8578e1689a821f7c1cce25cb417cea6 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 23:15:28 +0200 Subject: [PATCH 10/12] Create BaseTimeoutMilliseconds in AudioTests --- FFMpegCore.Test/AudioTest.cs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/FFMpegCore.Test/AudioTest.cs b/FFMpegCore.Test/AudioTest.cs index 3f0f25e..d552621 100644 --- a/FFMpegCore.Test/AudioTest.cs +++ b/FFMpegCore.Test/AudioTest.cs @@ -9,6 +9,8 @@ namespace FFMpegCore.Test; [TestClass] public class AudioTest { + private const int BaseTimeoutMilliseconds = 15_000; + public TestContext TestContext { get; set; } [TestMethod] @@ -73,7 +75,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_ToAAC_Args_Pipe() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -92,7 +94,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_ToLibVorbis_Args_Pipe() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -111,7 +113,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public async Task Audio_ToAAC_Args_Pipe_Async() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -130,7 +132,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_ToAAC_Args_Pipe_ValidDefaultConfiguration() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -149,7 +151,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_ToAAC_Args_Pipe_InvalidChannels() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -165,7 +167,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_ToAAC_Args_Pipe_InvalidFormat() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -181,7 +183,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_ToAAC_Args_Pipe_InvalidSampleRate() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -197,7 +199,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_Pan_ToMono() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -217,7 +219,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_Pan_ToMonoNoDefinitions() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -237,7 +239,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_Pan_ToMonoChannelsToOutputDefinitionsMismatch() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -251,7 +253,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_Pan_ToMonoChannelsLayoutToOutputDefinitionsMismatch() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -265,7 +267,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_DynamicNormalizer_WithDefaultValues() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -281,7 +283,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Audio_DynamicNormalizer_WithNonDefaultValues() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); @@ -297,7 +299,7 @@ public class AudioTest } [TestMethod] - [Timeout(10000, CooperativeCancellation = true)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] [DataRow(2)] [DataRow(32)] [DataRow(8)] From 9a0f784c710084f087bb409b32fe59ba9d725bf2 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 23:29:13 +0200 Subject: [PATCH 11/12] Increate timeout further due to slow windows CI .... --- FFMpegCore.Test/VideoTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index cf88c64..626e00c 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -17,7 +17,7 @@ namespace FFMpegCore.Test; [TestClass] public class VideoTest { - private const int BaseTimeoutMilliseconds = 30_000; + private const int BaseTimeoutMilliseconds = 60_000; public TestContext TestContext { get; set; } From 90786394a60ec5f30228ff4d6458a00e0f0c0e43 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 23:49:53 +0200 Subject: [PATCH 12/12] Increase timeout due to slow windows CI agent ... --- FFMpegCore.Test/AudioTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore.Test/AudioTest.cs b/FFMpegCore.Test/AudioTest.cs index d552621..3172af7 100644 --- a/FFMpegCore.Test/AudioTest.cs +++ b/FFMpegCore.Test/AudioTest.cs @@ -9,7 +9,7 @@ namespace FFMpegCore.Test; [TestClass] public class AudioTest { - private const int BaseTimeoutMilliseconds = 15_000; + private const int BaseTimeoutMilliseconds = 30_000; public TestContext TestContext { get; set; }