From 3f7b9121faa9b760a2fadbfd8f64a45fbdcb59e5 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Tue, 27 Oct 2020 12:08:18 +0100 Subject: [PATCH 1/3] Update ci.yml Former-commit-id: 5797fbf38e50bc22927915eceae72c600b664ddd --- .github/workflows/ci.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf07a86..a8c0244 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,20 @@ name: CI -on: [push, pull_request] + +on: + push: + branches: + - master + branches-ignore: + - release + pull_request: + branches: + - master + - release + jobs: ci: runs-on: ubuntu-latest - timeout-minutes: 10 + timeout-minutes: 7 steps: - uses: actions/checkout@v1 - name: Prepare FFMpeg From 049cbc1dc629fb4071e34f108a0db44a832f3324 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 28 Oct 2020 19:26:33 +0100 Subject: [PATCH 2/3] Fix cancellation Former-commit-id: 179cb15ba8aa64c383b35f71e76876aacafad0e8 --- FFMpegCore.Test/VideoTest.cs | 36 +++++++++++++------- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 10 ++++-- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index bc44f20..e4f750d 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -656,23 +656,33 @@ public void Video_TranscodeInMemory() [TestMethod, Timeout(10000)] public async Task Video_Cancel_Async() { - await using var resStream = new MemoryStream(); - var reader = new StreamPipeSink(resStream); - var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(512, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 128, 128)); - + var output = Input.OutputLocation(VideoType.Mp4); + var task = FFMpegArguments - .FromPipeInput(writer) - .OutputToPipe(reader, opt => opt - .WithVideoCodec("vp9") - .ForceFormat("webm")) + .FromFileInput(VideoLibrary.LocalVideo) + .OutputToFile(output, false, opt => opt + .Resize(new Size(1000, 1000)) + .WithAudioCodec(AudioCodec.Aac) + .WithVideoCodec(VideoCodec.LibX264) + .WithConstantRateFactor(14) + .WithSpeedPreset(Speed.VerySlow) + .Loop(3)) .CancellableThrough(out var cancel) .ProcessAsynchronously(false); - - await Task.Delay(300); - cancel(); - var result = await task; - Assert.IsFalse(result); + try + { + await Task.Delay(300); + cancel(); + + var result = await task; + Assert.IsFalse(result); + } + finally + { + if (File.Exists(output)) + File.Delete(output); + } } } } diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index 2307787..92fa6fe 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -51,18 +51,20 @@ public bool ProcessSynchronously(bool throwOnError = true) void OnCancelEvent(object sender, EventArgs args) { - instance?.SendInput("q"); + instance.SendInput("q"); cancellationTokenSource.Cancel(); + instance.Started = false; } CancelEvent += OnCancelEvent; instance.Exited += delegate { cancellationTokenSource.Cancel(); }; - _ffMpegArguments.Pre(); try { + _ffMpegArguments.Pre(); Task.WaitAll(instance.FinishedRunning().ContinueWith(t => { errorCode = t.Result; + cancellationTokenSource.Cancel(); _ffMpegArguments.Post(); }), _ffMpegArguments.During(cancellationTokenSource.Token)); } @@ -98,15 +100,17 @@ void OnCancelEvent(object sender, EventArgs args) { instance?.SendInput("q"); cancellationTokenSource.Cancel(); + instance.Started = false; } CancelEvent += OnCancelEvent; - _ffMpegArguments.Pre(); try { + _ffMpegArguments.Pre(); await Task.WhenAll(instance.FinishedRunning().ContinueWith(t => { errorCode = t.Result; + cancellationTokenSource.Cancel(); _ffMpegArguments.Post(); }), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false); } From edf3e304a90e5d6c402e27ccb531c1484098f9aa Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 28 Oct 2020 19:28:36 +0100 Subject: [PATCH 3/3] Update ci.yml Former-commit-id: 683f200ddc555506beee2a46e9a7997441738da8 --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8c0244..994a569 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,6 @@ name: CI on: push: - branches: - - master branches-ignore: - release pull_request: