mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-30 11:22:53 +01:00
Added an ffprobe helper class
This commit is contained in:
parent
3e86104641
commit
803ce0968e
68
MediaBrowser.Controller/FFMpeg/FFProbe.cs
Normal file
68
MediaBrowser.Controller/FFMpeg/FFProbe.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using MediaBrowser.Common.Logging;
|
||||
using MediaBrowser.Common.Serialization;
|
||||
|
||||
namespace MediaBrowser.Controller.FFMpeg
|
||||
{
|
||||
public static class FFProbe
|
||||
{
|
||||
public static FFProbeResult Run(string path)
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
|
||||
startInfo.CreateNoWindow = true;
|
||||
|
||||
startInfo.UseShellExecute = false;
|
||||
|
||||
// Must consume both or ffmpeg may hang due to deadlocks. See comments below.
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
startInfo.RedirectStandardError = true;
|
||||
|
||||
startInfo.FileName = Kernel.Instance.ApplicationPaths.FFProbePath;
|
||||
startInfo.WorkingDirectory = Kernel.Instance.ApplicationPaths.FFMpegDirectory;
|
||||
startInfo.Arguments = string.Format("\"{0}\" -v quiet -print_format json -show_streams -show_format", path);
|
||||
|
||||
Logger.LogInfo(startInfo.FileName + " " + startInfo.Arguments);
|
||||
|
||||
Process process = new Process();
|
||||
process.StartInfo = startInfo;
|
||||
|
||||
try
|
||||
{
|
||||
process.Start();
|
||||
|
||||
// MUST read both stdout and stderr asynchronously or a deadlock may occurr
|
||||
// If we ever decide to disable the ffmpeg log then you must uncomment the below line.
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
FFProbeResult result = JsonSerializer.DeserializeFromStream<FFProbeResult>(process.StandardOutput.BaseStream);
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
Logger.LogInfo("FFMpeg exited with code " + process.ExitCode);
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogException(ex);
|
||||
|
||||
// Hate having to do this
|
||||
try
|
||||
{
|
||||
process.Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user