From 9ff34b250f3e36ba0098be8338354cd94f2f7c9e Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 12 Aug 2020 17:17:34 +1200 Subject: [PATCH 1/7] Add IMediaAnalysis interface Former-commit-id: 8c77ce0cdf1f7e44811b7692c90812285748131d --- FFMpegCore/FFProbe/IMediaAnalysis.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 FFMpegCore/FFProbe/IMediaAnalysis.cs diff --git a/FFMpegCore/FFProbe/IMediaAnalysis.cs b/FFMpegCore/FFProbe/IMediaAnalysis.cs new file mode 100644 index 0000000..04e2ae3 --- /dev/null +++ b/FFMpegCore/FFProbe/IMediaAnalysis.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FFMpegCore +{ + public interface IMediaAnalysis + { + string Path { get; } + string Extension { get; } + TimeSpan Duration { get; } + MediaFormat Format { get; } + AudioStream PrimaryAudioStream { get; } + VideoStream PrimaryVideoStream { get; } + List VideoStreams { get; } + List AudioStreams { get; } + } +} From 79607c580fc2a55c6a74f86b81caaa7122be4780 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 12 Aug 2020 17:18:10 +1200 Subject: [PATCH 2/7] Implement IMediaAnalysis in MediaAnalysis class Former-commit-id: 725c8b31ee95a9e70797097d217b6808e50793bc --- FFMpegCore/FFProbe/MediaAnalysis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index 019815a..3c30e57 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -5,7 +5,7 @@ namespace FFMpegCore { - public class MediaAnalysis + public class MediaAnalysis : IMediaAnalysis { private static readonly Regex DurationRegex = new Regex("^(\\d{1,2}:\\d{1,2}:\\d{1,2}(.\\d{1,7})?)", RegexOptions.Compiled); internal MediaAnalysis(string path, FFProbeAnalysis analysis) From b25d2874222b768b64e5d15c06d3bc48b8f5a329 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 12 Aug 2020 17:22:10 +1200 Subject: [PATCH 3/7] Update existing references to use IMediaAnalysis Former-commit-id: 37a04a37cdcb3653dbc0dc93d75e425a48ce2f8b --- FFMpegCore.Test/VideoTest.cs | 2 +- FFMpegCore/FFMpeg/FFMpeg.cs | 16 ++++++++-------- FFMpegCore/FFProbe/FFProbe.cs | 10 +++++----- FFMpegCore/Helpers/FFMpegHelper.cs | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index e677370..e51fdea 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -159,7 +159,7 @@ private void ConvertToStreamPipe(params IArgument[] inputArguments) } } - public void Convert(ContainerFormat type, Action validationMethod, params IArgument[] inputArguments) + public void Convert(ContainerFormat type, Action validationMethod, params IArgument[] inputArguments) { var output = Input.OutputLocation(type); diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index ca94825..cee64d8 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -21,7 +21,7 @@ public static class FFMpeg /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. /// Bitmap with the requested snapshot. - public static bool Snapshot(MediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null) + public static bool Snapshot(IMediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null) { if (Path.GetExtension(output) != FileExtension.Png) output = Path.GetFileNameWithoutExtension(output) + FileExtension.Png; @@ -40,7 +40,7 @@ public static bool Snapshot(MediaAnalysis source, string output, Size? size = nu /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. /// Bitmap with the requested snapshot. - public static Task SnapshotAsync(MediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null) + public static Task SnapshotAsync(IMediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null) { if (Path.GetExtension(output) != FileExtension.Png) output = Path.GetFileNameWithoutExtension(output) + FileExtension.Png; @@ -58,7 +58,7 @@ public static Task SnapshotAsync(MediaAnalysis source, string output, Size /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. /// Bitmap with the requested snapshot. - public static Bitmap Snapshot(MediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) + public static Bitmap Snapshot(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) { var arguments = BuildSnapshotArguments(source, size, captureTime); using var ms = new MemoryStream(); @@ -78,7 +78,7 @@ public static Bitmap Snapshot(MediaAnalysis source, Size? size = null, TimeSpan? /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. /// Bitmap with the requested snapshot. - public static async Task SnapshotAsync(MediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) + public static async Task SnapshotAsync(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) { var arguments = BuildSnapshotArguments(source, size, captureTime); using var ms = new MemoryStream(); @@ -92,7 +92,7 @@ await arguments return new Bitmap(ms); } - private static FFMpegArguments BuildSnapshotArguments(MediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) + private static FFMpegArguments BuildSnapshotArguments(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) { captureTime ??= TimeSpan.FromSeconds(source.Duration.TotalSeconds / 3); size = PrepareSnapshotSize(source, size); @@ -104,7 +104,7 @@ private static FFMpegArguments BuildSnapshotArguments(MediaAnalysis source, Size .Resize(size); } - private static Size? PrepareSnapshotSize(MediaAnalysis source, Size? wantedSize) + private static Size? PrepareSnapshotSize(IMediaAnalysis source, Size? wantedSize) { if (wantedSize == null || (wantedSize.Value.Height <= 0 && wantedSize.Value.Width <= 0)) return null; @@ -143,7 +143,7 @@ private static FFMpegArguments BuildSnapshotArguments(MediaAnalysis source, Size /// Is encoding multithreaded. /// Output video information. public static bool Convert( - MediaAnalysis source, + IMediaAnalysis source, string output, ContainerFormat format, Speed speed = Speed.SuperFast, @@ -235,7 +235,7 @@ public static bool PosterWithAudio(string image, string audio, string output) /// Output video file. /// List of vides that need to be joined together. /// Output video information. - public static bool Join(string output, params MediaAnalysis[] videos) + public static bool Join(string output, params IMediaAnalysis[] videos) { var temporaryVideoParts = videos.Select(video => { diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index 4cf1b33..131f465 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -11,13 +11,13 @@ namespace FFMpegCore { public static class FFProbe { - public static MediaAnalysis Analyse(string filePath, int outputCapacity = int.MaxValue) + public static IMediaAnalysis Analyse(string filePath, int outputCapacity = int.MaxValue) { using var instance = PrepareInstance(filePath, outputCapacity); instance.BlockUntilFinished(); return ParseOutput(filePath, instance); } - public static MediaAnalysis Analyse(System.IO.Stream stream, int outputCapacity = int.MaxValue) + public static IMediaAnalysis Analyse(System.IO.Stream stream, int outputCapacity = int.MaxValue) { var streamPipeSource = new StreamPipeSource(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); @@ -40,13 +40,13 @@ public static MediaAnalysis Analyse(System.IO.Stream stream, int outputCapacity return ParseOutput(pipeArgument.PipePath, instance); } - public static async Task AnalyseAsync(string filePath, int outputCapacity = int.MaxValue) + public static async Task AnalyseAsync(string filePath, int outputCapacity = int.MaxValue) { using var instance = PrepareInstance(filePath, outputCapacity); await instance.FinishedRunning(); return ParseOutput(filePath, instance); } - public static async Task AnalyseAsync(System.IO.Stream stream, int outputCapacity = int.MaxValue) + public static async Task AnalyseAsync(System.IO.Stream stream, int outputCapacity = int.MaxValue) { var streamPipeSource = new StreamPipeSource(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); @@ -73,7 +73,7 @@ public static async Task AnalyseAsync(System.IO.Stream stream, in return ParseOutput(pipeArgument.PipePath, instance); } - private static MediaAnalysis ParseOutput(string filePath, Instance instance) + private static IMediaAnalysis ParseOutput(string filePath, Instance instance) { var json = string.Join(string.Empty, instance.OutputData); var ffprobeAnalysis = JsonSerializer.Deserialize(json, new JsonSerializerOptions diff --git a/FFMpegCore/Helpers/FFMpegHelper.cs b/FFMpegCore/Helpers/FFMpegHelper.cs index f280b08..8553573 100644 --- a/FFMpegCore/Helpers/FFMpegHelper.cs +++ b/FFMpegCore/Helpers/FFMpegHelper.cs @@ -12,7 +12,7 @@ public static void ConversionSizeExceptionCheck(Image image) ConversionSizeExceptionCheck(image.Size); } - public static void ConversionSizeExceptionCheck(MediaAnalysis info) + public static void ConversionSizeExceptionCheck(IMediaAnalysis info) { ConversionSizeExceptionCheck(new Size(info.PrimaryVideoStream.Width, info.PrimaryVideoStream.Height)); } From 16df2f4424cf83a075bb0775d11c9ad4f28cfd94 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 12 Aug 2020 17:22:32 +1200 Subject: [PATCH 4/7] Update MediaAnalysis's access modifier to internal Former-commit-id: 1c79e139fdc4eb1104b62c0a700d6ed85bf7c6a1 --- FFMpegCore/FFProbe/MediaAnalysis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index 3c30e57..4717a6f 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -5,7 +5,7 @@ namespace FFMpegCore { - public class MediaAnalysis : IMediaAnalysis + internal class MediaAnalysis : IMediaAnalysis { private static readonly Regex DurationRegex = new Regex("^(\\d{1,2}:\\d{1,2}:\\d{1,2}(.\\d{1,7})?)", RegexOptions.Compiled); internal MediaAnalysis(string path, FFProbeAnalysis analysis) From ea5f01ac64794ff33728ddace28f6e93e46412fe Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 12 Aug 2020 17:02:35 +0200 Subject: [PATCH 5/7] Update ci.yml Former-commit-id: 3fb3b8fe64a1a899d4bb04fbfb829c34a935ddf2 --- .github/workflows/ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46718fb..ae51d97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,5 @@ name: CI -on: - push: - branches: - - master +on: [push, pull_request] jobs: ci: runs-on: ubuntu-latest From 2fcf389aba4834f9d834506765d7574268adcf8d Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 21 Aug 2020 20:10:57 +0900 Subject: [PATCH 6/7] Fix pipe path for unix. Replace fixed '/tmp' with Path.GetTempPath(). Former-commit-id: 4ecf05ec79f5ffba5b1606aaad552ce6f982b593 --- FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs b/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs index ddd788c..1b2ae9d 100644 --- a/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs +++ b/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs @@ -5,6 +5,8 @@ namespace FFMpegCore.Pipes { static class PipeHelpers { + static readonly string PipePrefix = Path.Combine(Path.GetTempPath(), "CoreFxPipe_"); + public static string GetUnqiuePipeName() => "FFMpegCore_" + Guid.NewGuid(); public static string GetPipePath(string pipeName) @@ -12,7 +14,7 @@ public static string GetPipePath(string pipeName) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return $@"\\.\pipe\{pipeName}"; else - return $"unix:/tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 + return $"unix:{PipePrefix}{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 } } } From e49a17bab15f36cebc4acc8e019a806cef13969b Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 21 Aug 2020 21:39:28 +0900 Subject: [PATCH 7/7] Add using System.IO Former-commit-id: e99b1b106f75a280c8872a0f0b68332e5c803c4f --- FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs b/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs index 1b2ae9d..7e79f55 100644 --- a/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs +++ b/FFMpegCore/FFMpeg/Pipes/PipeHelpers.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Runtime.InteropServices; namespace FFMpegCore.Pipes