Merge branch 'master' into release

This commit is contained in:
Malte Rosenbjerg 2020-10-28 19:32:22 +01:00
commit 3139d776c7
3 changed files with 41 additions and 18 deletions

View file

@ -1,9 +1,18 @@
name: CI name: CI
on: [push, pull_request]
on:
push:
branches-ignore:
- release
pull_request:
branches:
- master
- release
jobs: jobs:
ci: ci:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 10 timeout-minutes: 7
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: Prepare FFMpeg - name: Prepare FFMpeg

View file

@ -656,23 +656,33 @@ public void Video_TranscodeInMemory()
[TestMethod, Timeout(10000)] [TestMethod, Timeout(10000)]
public async Task Video_Cancel_Async() public async Task Video_Cancel_Async()
{ {
await using var resStream = new MemoryStream(); var output = Input.OutputLocation(VideoType.Mp4);
var reader = new StreamPipeSink(resStream);
var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(512, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 128, 128));
var task = FFMpegArguments var task = FFMpegArguments
.FromPipeInput(writer) .FromFileInput(VideoLibrary.LocalVideo)
.OutputToPipe(reader, opt => opt .OutputToFile(output, false, opt => opt
.WithVideoCodec("vp9") .Resize(new Size(1000, 1000))
.ForceFormat("webm")) .WithAudioCodec(AudioCodec.Aac)
.WithVideoCodec(VideoCodec.LibX264)
.WithConstantRateFactor(14)
.WithSpeedPreset(Speed.VerySlow)
.Loop(3))
.CancellableThrough(out var cancel) .CancellableThrough(out var cancel)
.ProcessAsynchronously(false); .ProcessAsynchronously(false);
try
{
await Task.Delay(300); await Task.Delay(300);
cancel(); cancel();
var result = await task; var result = await task;
Assert.IsFalse(result); Assert.IsFalse(result);
} }
finally
{
if (File.Exists(output))
File.Delete(output);
}
}
} }
} }

View file

@ -51,18 +51,20 @@ public bool ProcessSynchronously(bool throwOnError = true)
void OnCancelEvent(object sender, EventArgs args) void OnCancelEvent(object sender, EventArgs args)
{ {
instance?.SendInput("q"); instance.SendInput("q");
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
instance.Started = false;
} }
CancelEvent += OnCancelEvent; CancelEvent += OnCancelEvent;
instance.Exited += delegate { cancellationTokenSource.Cancel(); }; instance.Exited += delegate { cancellationTokenSource.Cancel(); };
_ffMpegArguments.Pre();
try try
{ {
_ffMpegArguments.Pre();
Task.WaitAll(instance.FinishedRunning().ContinueWith(t => Task.WaitAll(instance.FinishedRunning().ContinueWith(t =>
{ {
errorCode = t.Result; errorCode = t.Result;
cancellationTokenSource.Cancel();
_ffMpegArguments.Post(); _ffMpegArguments.Post();
}), _ffMpegArguments.During(cancellationTokenSource.Token)); }), _ffMpegArguments.During(cancellationTokenSource.Token));
} }
@ -98,15 +100,17 @@ void OnCancelEvent(object sender, EventArgs args)
{ {
instance?.SendInput("q"); instance?.SendInput("q");
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
instance.Started = false;
} }
CancelEvent += OnCancelEvent; CancelEvent += OnCancelEvent;
_ffMpegArguments.Pre();
try try
{ {
_ffMpegArguments.Pre();
await Task.WhenAll(instance.FinishedRunning().ContinueWith(t => await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
{ {
errorCode = t.Result; errorCode = t.Result;
cancellationTokenSource.Cancel();
_ffMpegArguments.Post(); _ffMpegArguments.Post();
}), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false); }), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false);
} }