mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
efe61e8bad
commit
a5aad904e7
3 changed files with 38 additions and 3 deletions
|
@ -4,6 +4,8 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using RunProcessAsTask;
|
||||||
|
|
||||||
namespace FFMpegCore.FFMPEG
|
namespace FFMpegCore.FFMPEG
|
||||||
{
|
{
|
||||||
|
@ -78,5 +80,10 @@ public void Kill()
|
||||||
IsKillFaulty = true;
|
IsKillFaulty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected async Task<string> RunProcessAsync(string filePath, string arguments)
|
||||||
|
{
|
||||||
|
var result = await ProcessEx.RunAsync(filePath, arguments);
|
||||||
|
return string.Join("", result.StandardOutput);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,8 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using RunProcessAsTask;
|
||||||
|
|
||||||
namespace FFMpegCore.FFMPEG
|
namespace FFMpegCore.FFMPEG
|
||||||
{
|
{
|
||||||
|
@ -28,6 +30,15 @@ public VideoInfo ParseVideoInfo(string source)
|
||||||
{
|
{
|
||||||
return ParseVideoInfo(new VideoInfo(source));
|
return ParseVideoInfo(new VideoInfo(source));
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Probes the targeted video file asynchronously and retrieves all available details.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">Source video file.</param>
|
||||||
|
/// <returns>A task for the video info object containing all details necessary.</returns>
|
||||||
|
public Task<VideoInfo> ParseVideoInfoAsync(string source)
|
||||||
|
{
|
||||||
|
return ParseVideoInfoAsync(new VideoInfo(source));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Probes the targeted video file and retrieves all available details.
|
/// Probes the targeted video file and retrieves all available details.
|
||||||
|
@ -36,10 +47,26 @@ public VideoInfo ParseVideoInfo(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 jsonOutput =
|
var output = RunProcess(BuildFFProbeArguments(info));
|
||||||
RunProcess($"-v quiet -print_format json -show_streams \"{info.FullName}\"");
|
return ParseVideoInfoInternal(info, output);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Probes the targeted video file asynchronously and retrieves all available details.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Source video file.</param>
|
||||||
|
/// <returns>A video info object containing all details necessary.</returns>
|
||||||
|
public async Task<VideoInfo> ParseVideoInfoAsync(VideoInfo info)
|
||||||
|
{
|
||||||
|
var output = await RunProcessAsync(_ffprobePath, BuildFFProbeArguments(info));
|
||||||
|
return ParseVideoInfoInternal(info, output);
|
||||||
|
}
|
||||||
|
|
||||||
var metadata = JsonConvert.DeserializeObject<FFMpegStreamMetadata>(jsonOutput);
|
private static string BuildFFProbeArguments(VideoInfo info) =>
|
||||||
|
$"-v quiet -print_format json -show_streams \"{info.FullName}\"";
|
||||||
|
|
||||||
|
private VideoInfo ParseVideoInfoInternal(VideoInfo info, string probeOutput)
|
||||||
|
{
|
||||||
|
var metadata = JsonConvert.DeserializeObject<FFMpegStreamMetadata>(probeOutput);
|
||||||
|
|
||||||
if (metadata.Streams == null || metadata.Streams.Count == 0)
|
if (metadata.Streams == null || metadata.Streams.Count == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,6 +130,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||||
|
<PackageReference Include="RunProcessAsTask" Version="1.2.4" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
|
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue