diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-19 11:58:35 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-19 11:58:35 -0400 |
| commit | d794eecec4f4b9a46df422b28c86e136bfd92abf (patch) | |
| tree | a0a063c127106ea064525d72426bcdb1052ff8da /MediaBrowser.Controller/FFMpeg | |
| parent | 803ce0968e95232c7cdc72fc7af44d134590d6c7 (diff) | |
Added initial implementation of the metadata provider network, along with the first few providers
Diffstat (limited to 'MediaBrowser.Controller/FFMpeg')
| -rw-r--r-- | MediaBrowser.Controller/FFMpeg/FFProbe.cs | 50 | ||||
| -rw-r--r-- | MediaBrowser.Controller/FFMpeg/FFProbeResult.cs | 54 |
2 files changed, 63 insertions, 41 deletions
diff --git a/MediaBrowser.Controller/FFMpeg/FFProbe.cs b/MediaBrowser.Controller/FFMpeg/FFProbe.cs index efd5491de..fd9b2ff43 100644 --- a/MediaBrowser.Controller/FFMpeg/FFProbe.cs +++ b/MediaBrowser.Controller/FFMpeg/FFProbe.cs @@ -1,13 +1,41 @@ using System;
using System.Diagnostics;
+using System.IO;
+using System.Threading.Tasks;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
+using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.FFMpeg
{
+ /// <summary>
+ /// Runs FFProbe against a media file and returns metadata.
+ /// </summary>
public static class FFProbe
{
- public static FFProbeResult Run(string path)
+ public async static Task<FFProbeResult> Run(Audio item, string outputCachePath)
+ {
+ // Use try catch to avoid having to use File.Exists
+ try
+ {
+ using (FileStream stream = File.OpenRead(outputCachePath))
+ {
+ return JsonSerializer.DeserializeFromStream<FFProbeResult>(stream);
+ }
+ }
+ catch (FileNotFoundException)
+ {
+ }
+
+ await Run(item.Path, outputCachePath);
+
+ using (FileStream stream = File.OpenRead(outputCachePath))
+ {
+ return JsonSerializer.DeserializeFromStream<FFProbeResult>(stream);
+ }
+ }
+
+ private async static Task Run(string input, string output)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
@@ -21,13 +49,15 @@ namespace MediaBrowser.Controller.FFMpeg 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);
+ startInfo.Arguments = string.Format("\"{0}\" -v quiet -print_format json -show_streams -show_format", input);
- Logger.LogInfo(startInfo.FileName + " " + startInfo.Arguments);
+ //Logger.LogInfo(startInfo.FileName + " " + startInfo.Arguments);
Process process = new Process();
process.StartInfo = startInfo;
+ FileStream stream = new FileStream(output, FileMode.Create);
+
try
{
process.Start();
@@ -36,18 +66,23 @@ namespace MediaBrowser.Controller.FFMpeg // 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);
+ await process.StandardOutput.BaseStream.CopyToAsync(stream);
process.WaitForExit();
- Logger.LogInfo("FFMpeg exited with code " + process.ExitCode);
+ stream.Dispose();
- return result;
+ if (process.ExitCode != 0)
+ {
+ Logger.LogInfo("FFProbe exited with code {0} for {1}", process.ExitCode, input);
+ }
}
catch (Exception ex)
{
Logger.LogException(ex);
+ stream.Dispose();
+
// Hate having to do this
try
{
@@ -56,8 +91,7 @@ namespace MediaBrowser.Controller.FFMpeg catch
{
}
-
- return null;
+ File.Delete(output);
}
finally
{
diff --git a/MediaBrowser.Controller/FFMpeg/FFProbeResult.cs b/MediaBrowser.Controller/FFMpeg/FFProbeResult.cs index cc449991d..43167b521 100644 --- a/MediaBrowser.Controller/FFMpeg/FFProbeResult.cs +++ b/MediaBrowser.Controller/FFMpeg/FFProbeResult.cs @@ -13,6 +13,11 @@ namespace MediaBrowser.Controller.FFMpeg public MediaFormat format { get; set; }
}
+ /// <summary>
+ /// Represents a stream within the output
+ /// A number of properties are commented out to improve deserialization performance
+ /// Enable them as needed.
+ /// </summary>
public class MediaStream
{
public int index { get; set; }
@@ -20,28 +25,28 @@ namespace MediaBrowser.Controller.FFMpeg public string codec_name { get; set; }
public string codec_long_name { get; set; }
public string codec_type { get; set; }
- public string codec_time_base { get; set; }
- public string codec_tag { get; set; }
- public string codec_tag_string { get; set; }
- public string sample_fmt { get; set; }
+ //public string codec_time_base { get; set; }
+ //public string codec_tag { get; set; }
+ //public string codec_tag_string { get; set; }
+ //public string sample_fmt { get; set; }
public string sample_rate { get; set; }
public int channels { get; set; }
- public int bits_per_sample { get; set; }
- public string r_frame_rate { get; set; }
- public string avg_frame_rate { get; set; }
- public string time_base { get; set; }
- public string start_time { get; set; }
+ //public int bits_per_sample { get; set; }
+ //public string r_frame_rate { get; set; }
+ //public string avg_frame_rate { get; set; }
+ //public string time_base { get; set; }
+ //public string start_time { get; set; }
public string duration { get; set; }
public string bit_rate { get; set; }
public int width { get; set; }
public int height { get; set; }
- public int has_b_frames { get; set; }
- public string sample_aspect_ratio { get; set; }
- public string display_aspect_ratio { get; set; }
- public string pix_fmt { get; set; }
- public int level { get; set; }
- public MediaTags tags { get; set; }
+ //public int has_b_frames { get; set; }
+ //public string sample_aspect_ratio { get; set; }
+ //public string display_aspect_ratio { get; set; }
+ //public string pix_fmt { get; set; }
+ //public int level { get; set; }
+ public Dictionary<string,string> tags { get; set; }
}
public class MediaFormat
@@ -54,23 +59,6 @@ namespace MediaBrowser.Controller.FFMpeg public string duration { get; set; }
public string size { get; set; }
public string bit_rate { get; set; }
- public MediaTags tags { get; set; }
- }
-
- public class MediaTags
- {
- public string title { get; set; }
- public string comment { get; set; }
- public string artist { get; set; }
- public string album { get; set; }
- public string album_artist { get; set; }
- public string composer { get; set; }
- public string copyright { get; set; }
- public string publisher { get; set; }
- public string track { get; set; }
- public string disc { get; set; }
- public string genre { get; set; }
- public string date { get; set; }
- public string language { get; set; }
+ public Dictionary<string, string> tags { get; set; }
}
}
|
