mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
c0e1742330
commit
cdcecda648
5 changed files with 46 additions and 27 deletions
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
35
FFMpegCore.Test/FFProbeTests.cs
Normal file
35
FFMpegCore.Test/FFProbeTests.cs
Normal file
|
@ -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<JsonSerializationException>(() =>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,11 +10,13 @@ namespace FFMpegCore.FFMPEG
|
||||||
{
|
{
|
||||||
public sealed class FFProbe
|
public sealed class FFProbe
|
||||||
{
|
{
|
||||||
|
private readonly int _outputCapacity;
|
||||||
static readonly double BITS_TO_MB = 1024 * 1024 * 8;
|
static readonly double BITS_TO_MB = 1024 * 1024 * 8;
|
||||||
private readonly string _ffprobePath;
|
private readonly string _ffprobePath;
|
||||||
|
|
||||||
public FFProbe(): base()
|
public FFProbe(int outputCapacity = int.MaxValue)
|
||||||
{
|
{
|
||||||
|
_outputCapacity = outputCapacity;
|
||||||
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||||
_ffprobePath = FFMpegOptions.Options.FFProbeBinary;
|
_ffprobePath = FFMpegOptions.Options.FFProbeBinary;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +47,7 @@ public Task<VideoInfo> ParseVideoInfoAsync(string source)
|
||||||
/// <returns>A video info object containing all details necessary.</returns>
|
/// <returns>A video info object containing all details necessary.</returns>
|
||||||
public VideoInfo ParseVideoInfo(VideoInfo info)
|
public VideoInfo ParseVideoInfo(VideoInfo info)
|
||||||
{
|
{
|
||||||
var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info));
|
var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info)) {DataBufferCapacity = _outputCapacity};
|
||||||
instance.BlockUntilFinished();
|
instance.BlockUntilFinished();
|
||||||
var output = string.Join("", instance.OutputData);
|
var output = string.Join("", instance.OutputData);
|
||||||
return ParseVideoInfoInternal(info, output);
|
return ParseVideoInfoInternal(info, output);
|
||||||
|
@ -57,7 +59,7 @@ public VideoInfo ParseVideoInfo(VideoInfo info)
|
||||||
/// <returns>A video info object containing all details necessary.</returns>
|
/// <returns>A video info object containing all details necessary.</returns>
|
||||||
public async Task<VideoInfo> ParseVideoInfoAsync(VideoInfo info)
|
public async Task<VideoInfo> ParseVideoInfoAsync(VideoInfo info)
|
||||||
{
|
{
|
||||||
var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info));
|
var instance = new Instance(_ffprobePath, BuildFFProbeArguments(info)) {DataBufferCapacity = _outputCapacity};
|
||||||
await instance.FinishedRunning();
|
await instance.FinishedRunning();
|
||||||
var output = string.Join("", instance.OutputData);
|
var output = string.Join("", instance.OutputData);
|
||||||
return ParseVideoInfoInternal(info, output);
|
return ParseVideoInfoInternal(info, output);
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
<Version>1.0.12</Version>
|
<Version>1.0.12</Version>
|
||||||
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
||||||
<FileVersion>1.1.0.0</FileVersion>
|
<FileVersion>1.1.0.0</FileVersion>
|
||||||
<PackageReleaseNotes>Add support for drawtext</PackageReleaseNotes>
|
<PackageReleaseNotes>Add more argument types and make ffprobe output capacity configurable</PackageReleaseNotes>
|
||||||
<LangVersion>8</LangVersion>
|
<LangVersion>8</LangVersion>
|
||||||
<PackageVersion>1.2.0</PackageVersion>
|
<PackageVersion>1.3.0</PackageVersion>
|
||||||
<Authors>Vlad Jerca, Malte Rosenbjerg</Authors>
|
<Authors>Vlad Jerca, Malte Rosenbjerg</Authors>
|
||||||
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
||||||
<RepositoryType>GitHub</RepositoryType>
|
<RepositoryType>GitHub</RepositoryType>
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class VideoInfo
|
||||||
/// Create a video information object from a file information object.
|
/// Create a video information object from a file information object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileInfo">Video file information.</param>
|
/// <param name="fileInfo">Video file information.</param>
|
||||||
public VideoInfo(FileInfo fileInfo)
|
public VideoInfo(FileInfo fileInfo, int outputCapacity = int.MaxValue)
|
||||||
{
|
{
|
||||||
fileInfo.Refresh();
|
fileInfo.Refresh();
|
||||||
|
|
||||||
|
@ -21,14 +21,15 @@ public VideoInfo(FileInfo fileInfo)
|
||||||
|
|
||||||
_file = fileInfo;
|
_file = fileInfo;
|
||||||
|
|
||||||
new FFProbe().ParseVideoInfo(this);
|
new FFProbe(outputCapacity).ParseVideoInfo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a video information object from a target path.
|
/// Create a video information object from a target path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Path to video.</param>
|
/// <param name="path">Path to video.</param>
|
||||||
public VideoInfo(string path) : this(new FileInfo(path)) { }
|
/// <param name="outputCapacity">Max amount of outputlines</param>
|
||||||
|
public VideoInfo(string path, int outputCapacity = int.MaxValue) : this(new FileInfo(path), outputCapacity) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Duration of the video file.
|
/// Duration of the video file.
|
||||||
|
|
Loading…
Reference in a new issue