From 38789162eb178c1d43395a3ea66f09ae937abe46 Mon Sep 17 00:00:00 2001 From: Phillip Fisher Date: Sat, 25 Feb 2023 11:29:41 -0600 Subject: [PATCH 01/10] Add chapters to FFProbe --- .../FFMpeg/Builders/MetaData/ChapterData.cs | 4 +++ FFMpegCore/FFProbe/FFProbe.cs | 2 +- FFMpegCore/FFProbe/FFProbeAnalysis.cs | 27 +++++++++++++++++++ FFMpegCore/FFProbe/IMediaAnalysis.cs | 5 +++- FFMpegCore/FFProbe/MediaAnalysis.cs | 13 +++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs index 77a47bd..d0b5bcb 100644 --- a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs +++ b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs @@ -6,11 +6,15 @@ public class ChapterData public TimeSpan Start { get; private set; } public TimeSpan End { get; private set; } + public TimeSpan Duration { get; private set; } + public ChapterData(string title, TimeSpan start, TimeSpan end) { Title = title; Start = start; End = end; + + Duration = end - start; } } } diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index 8a7069e..d1032c6 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -213,7 +213,7 @@ private static void ThrowIfExitCodeNotZero(IProcessResult result) } private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams \"{filePath}\"", ffOptions); + => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams -show_chapters \"{filePath}\"", ffOptions); private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions) => PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions); private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions) diff --git a/FFMpegCore/FFProbe/FFProbeAnalysis.cs b/FFMpegCore/FFProbe/FFProbeAnalysis.cs index b053d98..f3193ea 100644 --- a/FFMpegCore/FFProbe/FFProbeAnalysis.cs +++ b/FFMpegCore/FFProbe/FFProbeAnalysis.cs @@ -11,6 +11,9 @@ public class FFProbeAnalysis [JsonPropertyName("format")] public Format Format { get; set; } = null!; + [JsonPropertyName("chapters")] + public List Chapters { get; set; } = null!; + [JsonIgnore] public IReadOnlyList ErrorData { get; set; } = new List(); } @@ -129,6 +132,30 @@ public class Format : ITagsContainer public Dictionary Tags { get; set; } = null!; } + public class Chapter : ITagsContainer + { + [JsonPropertyName("id")] + public int Id { get; set; } + + [JsonPropertyName("time_base")] + public string TimeBase { get; set; } = null!; + + [JsonPropertyName("start")] + public int Start { get; set; } + + [JsonPropertyName("start_time")] + public string StartTime { get; set; } = null!; + + [JsonPropertyName("end")] + public int End { get; set; } + + [JsonPropertyName("end_time")] + public string EndTime { get; set; } = null!; + + [JsonPropertyName("tags")] + public Dictionary Tags { get; set; } = null!; + } + public interface IDispositionContainer { Dictionary Disposition { get; set; } diff --git a/FFMpegCore/FFProbe/IMediaAnalysis.cs b/FFMpegCore/FFProbe/IMediaAnalysis.cs index 47f47e4..d99992a 100644 --- a/FFMpegCore/FFProbe/IMediaAnalysis.cs +++ b/FFMpegCore/FFProbe/IMediaAnalysis.cs @@ -1,9 +1,12 @@ -namespace FFMpegCore +using FFMpegCore.Builders.MetaData; + +namespace FFMpegCore { public interface IMediaAnalysis { TimeSpan Duration { get; } MediaFormat Format { get; } + List Chapters { get; } AudioStream? PrimaryAudioStream { get; } VideoStream? PrimaryVideoStream { get; } SubtitleStream? PrimarySubtitleStream { get; } diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index 9fce0fe..887baeb 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -1,4 +1,5 @@ using System.Text.RegularExpressions; +using FFMpegCore.Builders.MetaData; namespace FFMpegCore { @@ -7,6 +8,7 @@ internal class MediaAnalysis : IMediaAnalysis internal MediaAnalysis(FFProbeAnalysis analysis) { Format = ParseFormat(analysis.Format); + Chapters = analysis.Chapters.Select(c => ParseChapter(c)).ToList(); VideoStreams = analysis.Streams.Where(stream => stream.CodecType == "video").Select(ParseVideoStream).ToList(); AudioStreams = analysis.Streams.Where(stream => stream.CodecType == "audio").Select(ParseAudioStream).ToList(); SubtitleStreams = analysis.Streams.Where(stream => stream.CodecType == "subtitle").Select(ParseSubtitleStream).ToList(); @@ -28,6 +30,15 @@ private MediaFormat ParseFormat(Format analysisFormat) }; } + private ChapterData ParseChapter(Chapter analysisChapter) + { + var title = analysisChapter.Tags.FirstOrDefault(t => t.Key == "title").Value; + var start = MediaAnalysisUtils.ParseDuration(analysisChapter.StartTime); + var end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime); + + return new ChapterData(title, start, end); + } + public TimeSpan Duration => new[] { Format.Duration, @@ -37,6 +48,8 @@ private MediaFormat ParseFormat(Format analysisFormat) public MediaFormat Format { get; } + public List Chapters { get; } + public AudioStream? PrimaryAudioStream => AudioStreams.OrderBy(stream => stream.Index).FirstOrDefault(); public VideoStream? PrimaryVideoStream => VideoStreams.OrderBy(stream => stream.Index).FirstOrDefault(); public SubtitleStream? PrimarySubtitleStream => SubtitleStreams.OrderBy(stream => stream.Index).FirstOrDefault(); From ba78512cb92c9f59d22d713a026da68118a9e9f4 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 12 Apr 2023 16:30:46 +0200 Subject: [PATCH 02/10] ChapterData.Duration as computed property --- FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs index d0b5bcb..e278408 100644 --- a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs +++ b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs @@ -6,15 +6,13 @@ public class ChapterData public TimeSpan Start { get; private set; } public TimeSpan End { get; private set; } - public TimeSpan Duration { get; private set; } + public TimeSpan Duration => End - Start; public ChapterData(string title, TimeSpan start, TimeSpan end) { Title = title; Start = start; End = end; - - Duration = end - start; } } } From 0ac351493c2065945777b73e65fc527c92e7c310 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 12 Apr 2023 16:31:26 +0200 Subject: [PATCH 03/10] Verify Chapters property is initialized to non-null in test --- FFMpegCore.Test/FFProbeTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 9da819a..38ec6cf 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -105,6 +105,7 @@ public void Probe_Success() { var info = FFProbe.Analyse(TestResources.Mp4Video); Assert.AreEqual(3, info.Duration.Seconds); + Assert.AreEqual(0, info.Chapters.Count); Assert.AreEqual("5.1", info.PrimaryAudioStream!.ChannelLayout); Assert.AreEqual(6, info.PrimaryAudioStream.Channels); From b2488303cf8451a679af5717b28dc5b6769d6b85 Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 21:47:36 +0200 Subject: [PATCH 04/10] feature: custom ffprobe arguments --- FFMpegCore/FFProbe/FFProbe.cs | 64 +++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index 8a7069e..ddff026 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -10,52 +10,52 @@ namespace FFMpegCore { public static class FFProbe { - public static IMediaAnalysis Analyse(string filePath, FFOptions? ffOptions = null) + public static IMediaAnalysis Analyse(string filePath, FFOptions? ffOptions = null, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var processArguments = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var processArguments = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = processArguments.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static FFProbeFrames GetFrames(string filePath, FFOptions? ffOptions = null) + public static FFProbeFrames GetFrames(string filePath, FFOptions? ffOptions = null, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseFramesOutput(result); } - public static FFProbePackets GetPackets(string filePath, FFOptions? ffOptions = null) + public static FFProbePackets GetPackets(string filePath, FFOptions? ffOptions = null, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParsePacketsOutput(result); } - public static IMediaAnalysis Analyse(Uri uri, FFOptions? ffOptions = null) + public static IMediaAnalysis Analyse(Uri uri, FFOptions? ffOptions = null, string? customArguments = null) { - var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null) + public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null, string? customArguments = null) { var streamPipeSource = new StreamPipeSource(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); - var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current, customArguments); pipeArgument.Pre(); var task = instance.StartAndWaitForExitAsync(); @@ -75,57 +75,57 @@ public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null) return ParseOutput(result); } - public static async Task AnalyseAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task AnalyseAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static FFProbeFrames GetFrames(Uri uri, FFOptions? ffOptions = null) + public static FFProbeFrames GetFrames(Uri uri, FFOptions? ffOptions = null, string? customArguments = null) { - var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseFramesOutput(result); } - public static async Task GetFramesAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task GetFramesAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); return ParseFramesOutput(result); } - public static async Task GetPacketsAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task GetPacketsAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); return ParsePacketsOutput(result); } - public static async Task AnalyseAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task AnalyseAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { - var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static async Task AnalyseAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task AnalyseAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { var streamPipeSource = new StreamPipeSource(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); - var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current, customArguments); pipeArgument.Pre(); var task = instance.StartAndWaitForExitAsync(cancellationToken); @@ -148,9 +148,9 @@ public static async Task AnalyseAsync(Stream stream, FFOptions? return ParseOutput(result); } - public static async Task GetFramesAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task GetFramesAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { - var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); return ParseFramesOutput(result); } @@ -212,18 +212,18 @@ private static void ThrowIfExitCodeNotZero(IProcessResult result) } } - private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams \"{filePath}\"", ffOptions); - private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions); - private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_packets -v quiet -sexagesimal \"{filePath}\"", ffOptions); + private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments) + => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams \"{filePath}\"", ffOptions, customArguments); + private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments) + => PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions, customArguments); + private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments) + => PrepareInstance($"-loglevel error -print_format json -show_packets -v quiet -sexagesimal \"{filePath}\"", ffOptions, customArguments); - private static ProcessArguments PrepareInstance(string arguments, FFOptions ffOptions) + private static ProcessArguments PrepareInstance(string arguments, FFOptions ffOptions, string? customArguments) { FFProbeHelper.RootExceptionCheck(); FFProbeHelper.VerifyFFProbeExists(ffOptions); - var startInfo = new ProcessStartInfo(GlobalFFOptions.GetFFProbeBinaryPath(ffOptions), arguments) + var startInfo = new ProcessStartInfo(GlobalFFOptions.GetFFProbeBinaryPath(ffOptions), $"{arguments} {customArguments}") { StandardOutputEncoding = ffOptions.Encoding, StandardErrorEncoding = ffOptions.Encoding, From 4b0cd9239e563f630e0f54f5482f415f003e80ee Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 21:57:20 +0200 Subject: [PATCH 05/10] Add test --- FFMpegCore.Test/FFProbeTests.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 9da819a..0d58f43 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -1,4 +1,4 @@ -using FFMpegCore.Test.Resources; +using FFMpegCore.Test.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace FFMpegCore.Test @@ -235,5 +235,12 @@ public async Task Probe_Success_32BitWavBitDepth_Async() Assert.IsNotNull(info.PrimaryAudioStream); Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth); } + + [TestMethod] + public void Probe_Success_Custom_Arguments() + { + var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: world\""); + Assert.AreEqual(3, info.Duration.Seconds); + } } } From 66c166f2e8b2f3d486f2b2477ec546e625cf1bac Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 22:07:22 +0200 Subject: [PATCH 06/10] Try fix encoding --- FFMpegCore.Test/FFProbeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 0d58f43..ffdf9e9 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -239,7 +239,7 @@ public async Task Probe_Success_32BitWavBitDepth_Async() [TestMethod] public void Probe_Success_Custom_Arguments() { - var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: world\""); + var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\""); Assert.AreEqual(3, info.Duration.Seconds); } } From 338274b5009c11a4c69b5cdfef4886942b48a630 Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 22:10:37 +0200 Subject: [PATCH 07/10] Try fix encoding 2 --- FFMpegCore.Test/FFProbeTests.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index ffdf9e9..9da819a 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -1,4 +1,4 @@ -using FFMpegCore.Test.Resources; +using FFMpegCore.Test.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace FFMpegCore.Test @@ -235,12 +235,5 @@ public async Task Probe_Success_32BitWavBitDepth_Async() Assert.IsNotNull(info.PrimaryAudioStream); Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth); } - - [TestMethod] - public void Probe_Success_Custom_Arguments() - { - var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\""); - Assert.AreEqual(3, info.Duration.Seconds); - } } } From bf06a8059be2730a462848f601cf5d5d2bf70873 Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 22:14:23 +0200 Subject: [PATCH 08/10] Add test again --- FFMpegCore.Test/FFProbeTests.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 9da819a..05ec92f 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -235,5 +235,12 @@ public async Task Probe_Success_32BitWavBitDepth_Async() Assert.IsNotNull(info.PrimaryAudioStream); Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth); } + + [TestMethod] + public void Probe_Success_Custom_Arguments() + { + var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\""); + Assert.AreEqual(3, info.Duration.Seconds); + } } } From a920ab2bc15aaed67817dac09276141d63ab6f11 Mon Sep 17 00:00:00 2001 From: Devedse Date: Fri, 5 May 2023 12:42:27 +0200 Subject: [PATCH 09/10] Fix issue where ffmpeg can't be found if x64/x86 folders exist without ffmpeg in there --- FFMpegCore/GlobalFFOptions.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/FFMpegCore/GlobalFFOptions.cs b/FFMpegCore/GlobalFFOptions.cs index 209e137..49cac16 100644 --- a/FFMpegCore/GlobalFFOptions.cs +++ b/FFMpegCore/GlobalFFOptions.cs @@ -30,12 +30,23 @@ private static string GetFFBinaryPath(string name, FFOptions ffOptions) } var target = Environment.Is64BitProcess ? "x64" : "x86"; - if (Directory.Exists(Path.Combine(ffOptions.BinaryFolder, target))) + var possiblePaths = new List() { - ffName = Path.Combine(target, ffName); + Path.Combine(ffOptions.BinaryFolder, target), + ffOptions.BinaryFolder + }; + + foreach (var possiblePath in possiblePaths) + { + var possibleFFMpegPath = Path.Combine(possiblePath, ffName); + if (File.Exists(possibleFFMpegPath)) + { + return possibleFFMpegPath; + } } - return Path.Combine(ffOptions.BinaryFolder, ffName); + //Fall back to the assumption this tool exists in the PATH + return ffName; } private static FFOptions LoadFFOptions() From ed30b146871df5bade326d6306a058dac0f1ae5b Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 5 Oct 2023 09:24:44 +0200 Subject: [PATCH 10/10] Align with main branch --- FFMpegCore/FFProbe/FFProbeAnalysis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFProbe/FFProbeAnalysis.cs b/FFMpegCore/FFProbe/FFProbeAnalysis.cs index 09a1cd9..1966242 100644 --- a/FFMpegCore/FFProbe/FFProbeAnalysis.cs +++ b/FFMpegCore/FFProbe/FFProbeAnalysis.cs @@ -153,7 +153,7 @@ public class Chapter : ITagsContainer public string EndTime { get; set; } = null!; [JsonPropertyName("tags")] - public Dictionary Tags { get; set; } = null!; + public Dictionary? Tags { get; set; } } public interface IDispositionContainer