diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 994a569..e17abf9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,15 +11,15 @@ on: jobs: ci: - runs-on: ubuntu-latest - timeout-minutes: 7 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + timeout-minutes: 4 steps: - - uses: actions/checkout@v1 + - name: Checkout + uses: actions/checkout@v1 - name: Prepare FFMpeg - run: sudo apt-get update && sudo apt-get install -y ffmpeg - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 3.1.101 + uses: FedericoCarboni/setup-ffmpeg@v1-beta - name: Test with dotnet run: dotnet test --logger GitHubActions diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5f7efcd..4a05c8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,13 +7,10 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 3.1 + - name: Checkout + uses: actions/checkout@v1 - name: Build solution - run: dotnet build --output build + run: dotnet build --output build -c Release - name: Publish NuGet package - run: dotnet nuget push "build/*.nupkg" --skip-duplicate --source nuget.org --api-key ${{ secrets.NUGET_TOKEN }} + run: dotnet nuget push "build/*.nupkg" --source nuget.org --api-key ${{ secrets.NUGET_TOKEN }} diff --git a/FFMpegCore.Test/AudioTest.cs b/FFMpegCore.Test/AudioTest.cs index 378b7f7..9818e79 100644 --- a/FFMpegCore.Test/AudioTest.cs +++ b/FFMpegCore.Test/AudioTest.cs @@ -4,6 +4,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System.IO; using System.Linq; +using System.Threading.Tasks; +using FFMpegCore.Pipes; namespace FFMpegCore.Test { @@ -33,7 +35,23 @@ public void Audio_Save() Assert.IsTrue(!analysis.VideoStreams.Any()); Assert.IsTrue(analysis.AudioStreams.Any()); } - + [TestMethod] + public async Task Audio_FromRaw() + { + await using var file = File.Open(VideoLibrary.LocalAudioRaw.FullName, FileMode.Open); + var memoryStream = new MemoryStream(); + await FFMpegArguments + .FromPipeInput(new StreamPipeSource(file), options => options.ForceFormat("s16le")) + .OutputToPipe(new StreamPipeSink(memoryStream), options => + { + options.WithAudioSamplingRate(48000); + options.WithAudioCodec("libopus"); + options.WithCustomArgument("-ac 2"); + options.ForceFormat("opus"); + }) + .ProcessAsynchronously(); + } + [TestMethod] public void Audio_Add() { diff --git a/FFMpegCore.Test/FFMpegCore.Test.csproj b/FFMpegCore.Test/FFMpegCore.Test.csproj index 59f2645..b232270 100644 --- a/FFMpegCore.Test/FFMpegCore.Test.csproj +++ b/FFMpegCore.Test/FFMpegCore.Test.csproj @@ -27,6 +27,9 @@ PreserveNewest + + Always + @@ -37,7 +40,7 @@ - + diff --git a/FFMpegCore.Test/Resources/audio.raw b/FFMpegCore.Test/Resources/audio.raw new file mode 100644 index 0000000..c1811e9 Binary files /dev/null and b/FFMpegCore.Test/Resources/audio.raw differ diff --git a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs index 3225b6c..428f21b 100644 --- a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO.Pipes; using System.Threading; using System.Threading.Tasks; @@ -30,6 +31,7 @@ public void Pre() public void Post() { + Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}"); Pipe?.Dispose(); Pipe = null!; } @@ -39,9 +41,12 @@ public async Task During(CancellationToken cancellationToken = default) try { await ProcessDataAsync(cancellationToken); + Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}"); + Pipe?.Disconnect(); } catch (TaskCanceledException) { + Debug.WriteLine($"ProcessDataAsync on {GetType().Name} cancelled"); } } diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index 602f03a..90c2265 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -69,7 +69,8 @@ public static Bitmap Snapshot(IMediaAnalysis source, Size? size = null, TimeSpan .ProcessSynchronously(); ms.Position = 0; - return new Bitmap(ms); + using var bitmap = new Bitmap(ms); + return bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), bitmap.PixelFormat); } /// /// Saves a 'png' thumbnail to an in-memory bitmap diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index 54afd94..93c6d4e 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -9,10 +9,9 @@ 3.0.0.0 3.0.0.0 3.0.0.0 - - Updated dependencies -- Additional StreamPipeSink constructor + - Fix NullReferenceException on Disconnect after Dispose 8 - 3.2.0 + 3.2.1 MIT Malte Rosenbjerg, Vlad Jerca ffmpeg ffprobe convert video audio mediafile resize analyze muxing