From 24c3eb475d649b670e7ef371e21d910d80c88aba Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 1 Mar 2020 12:55:57 +0100 Subject: [PATCH] Make output capacity configureable and set higher default Fixes #42 Former-commit-id: cdcecda64873e5ee11e8c5254b22bf12249834b3 --- FFMpegCore.Test/FFMpegTest.cs | 19 ------------------ FFMpegCore.Test/FFProbeTests.cs | 35 +++++++++++++++++++++++++++++++++ FFMpegCore/FFMPEG/FFProbe.cs | 8 +++++--- FFMpegCore/FFMpegCore.csproj | 4 ++-- FFMpegCore/VideoInfo.cs | 7 ++++--- 5 files changed, 46 insertions(+), 27 deletions(-) delete mode 100644 FFMpegCore.Test/FFMpegTest.cs create mode 100644 FFMpegCore.Test/FFProbeTests.cs diff --git a/FFMpegCore.Test/FFMpegTest.cs b/FFMpegCore.Test/FFMpegTest.cs deleted file mode 100644 index ac1abf1..0000000 --- a/FFMpegCore.Test/FFMpegTest.cs +++ /dev/null @@ -1,19 +0,0 @@ -using FFMpegCore.FFMPEG; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace FFMpegCore.Test -{ - [TestClass] - public class FFMpegTest - { - [TestMethod] - public void CTOR_Default() - { - var encoder = new FFMpeg(); - var probe = new FFProbe(); - - Assert.IsNotNull(encoder); - Assert.IsNotNull(probe); - } - } -} diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs new file mode 100644 index 0000000..d66d561 --- /dev/null +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -0,0 +1,35 @@ +using System.IO; +using FFMpegCore.Enums; +using FFMpegCore.FFMPEG; +using FFMpegCore.FFMPEG.Argument; +using FFMpegCore.Test.Resources; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; + +namespace FFMpegCore.Test +{ + [TestClass] + public class FFProbeTests + { + [TestMethod] + public void Probe_TooLongOutput() + { + var output = new FFProbe(5); + + Assert.ThrowsException(() => + { + output.ParseVideoInfo(VideoLibrary.LocalVideo.FullName); + }); + } + + [TestMethod] + public void Probe_Success() + { + var output = new FFProbe(); + + var info = output.ParseVideoInfo(VideoLibrary.LocalVideo.FullName); + + Assert.AreEqual(13, info.Duration.Seconds); + } + } +} \ No newline at end of file diff --git a/FFMpegCore/FFMPEG/FFProbe.cs b/FFMpegCore/FFMPEG/FFProbe.cs index a965f71..52cb0b8 100644 --- a/FFMpegCore/FFMPEG/FFProbe.cs +++ b/FFMpegCore/FFMPEG/FFProbe.cs @@ -10,11 +10,13 @@ namespace FFMpegCore.FFMPEG { public sealed class FFProbe { + private readonly int _outputCapacity; static readonly double BITS_TO_MB = 1024 * 1024 * 8; private readonly string _ffprobePath; - public FFProbe(): base() + public FFProbe(int outputCapacity = int.MaxValue) { + _outputCapacity = outputCapacity; FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory); _ffprobePath = FFMpegOptions.Options.FFProbeBinary; } @@ -45,7 +47,7 @@ public Task ParseVideoInfoAsync(string source) /// A video info object containing all details necessary. public VideoInfo ParseVideoInfo(VideoInfo info) { - var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info)); + var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info)) {DataBufferCapacity = _outputCapacity}; instance.BlockUntilFinished(); var output = string.Join("", instance.OutputData); return ParseVideoInfoInternal(info, output); @@ -57,7 +59,7 @@ public VideoInfo ParseVideoInfo(VideoInfo info) /// A video info object containing all details necessary. public async Task ParseVideoInfoAsync(VideoInfo info) { - var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info)); + var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info)) {DataBufferCapacity = _outputCapacity}; await instance.FinishedRunning(); var output = string.Join("", instance.OutputData); return ParseVideoInfoInternal(info, output); diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index 4bee5f9..a1c4854 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -10,9 +10,9 @@ 1.0.12 1.1.0.0 1.1.0.0 - Add support for drawtext + Add more argument types and make ffprobe output capacity configurable 8 - 1.2.0 + 1.3.0 Vlad Jerca, Malte Rosenbjerg ffmpeg ffprobe convert video audio mediafile resize analyze muxing GitHub diff --git a/FFMpegCore/VideoInfo.cs b/FFMpegCore/VideoInfo.cs index 58da8f5..b6f97d7 100644 --- a/FFMpegCore/VideoInfo.cs +++ b/FFMpegCore/VideoInfo.cs @@ -12,7 +12,7 @@ public class VideoInfo /// Create a video information object from a file information object. /// /// Video file information. - public VideoInfo(FileInfo fileInfo) + public VideoInfo(FileInfo fileInfo, int outputCapacity = int.MaxValue) { fileInfo.Refresh(); @@ -21,14 +21,15 @@ public VideoInfo(FileInfo fileInfo) _file = fileInfo; - new FFProbe().ParseVideoInfo(this); + new FFProbe(outputCapacity).ParseVideoInfo(this); } /// /// Create a video information object from a target path. /// /// Path to video. - public VideoInfo(string path) : this(new FileInfo(path)) { } + /// Max amount of outputlines + public VideoInfo(string path, int outputCapacity = int.MaxValue) : this(new FileInfo(path), outputCapacity) { } /// /// Duration of the video file.