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.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using RunProcessAsTask;
|
||||
|
||||
namespace FFMpegCore.FFMPEG
|
||||
{
|
||||
|
@ -78,5 +80,10 @@ public void Kill()
|
|||
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.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using RunProcessAsTask;
|
||||
|
||||
namespace FFMpegCore.FFMPEG
|
||||
{
|
||||
|
@ -28,6 +30,15 @@ public VideoInfo ParseVideoInfo(string 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>
|
||||
/// 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>
|
||||
public VideoInfo ParseVideoInfo(VideoInfo info)
|
||||
{
|
||||
var jsonOutput =
|
||||
RunProcess($"-v quiet -print_format json -show_streams \"{info.FullName}\"");
|
||||
var output = RunProcess(BuildFFProbeArguments(info));
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -130,6 +130,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
<PackageReference Include="RunProcessAsTask" Version="1.2.4" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Reference in a new issue