2012-09-11 01:34:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.FFMpeg;
|
2012-09-08 19:05:18 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
2012-08-22 20:48:18 +00:00
|
|
|
|
using System.Collections.Generic;
|
2012-08-21 03:32:59 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-08-20 19:16:51 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
|
|
|
|
{
|
2012-09-08 19:05:18 +00:00
|
|
|
|
[Export(typeof(BaseMetadataProvider))]
|
2012-08-24 16:24:29 +00:00
|
|
|
|
public class VideoInfoProvider : BaseMediaInfoProvider<Video>
|
2012-08-20 19:16:51 +00:00
|
|
|
|
{
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
// Give this second priority
|
2012-08-21 03:32:59 +00:00
|
|
|
|
// Give metadata xml providers a chance to fill in data first, so that we can skip this whenever possible
|
2012-08-20 19:16:51 +00:00
|
|
|
|
get { return MetadataProviderPriority.Second; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-24 16:24:29 +00:00
|
|
|
|
protected override string CacheDirectory
|
2012-08-20 19:16:51 +00:00
|
|
|
|
{
|
2012-08-24 16:24:29 +00:00
|
|
|
|
get { return Kernel.Instance.ApplicationPaths.FFProbeVideoCacheDirectory; }
|
2012-08-20 19:16:51 +00:00
|
|
|
|
}
|
2012-08-24 16:24:29 +00:00
|
|
|
|
|
|
|
|
|
protected override void Fetch(Video video, FFProbeResult data)
|
2012-08-21 03:32:59 +00:00
|
|
|
|
{
|
2012-08-25 15:30:37 +00:00
|
|
|
|
if (data.format != null)
|
2012-08-22 20:57:29 +00:00
|
|
|
|
{
|
2012-08-25 15:30:37 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(data.format.duration))
|
|
|
|
|
{
|
|
|
|
|
video.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration)).Ticks;
|
|
|
|
|
}
|
2012-08-22 20:57:29 +00:00
|
|
|
|
|
2012-08-25 15:30:37 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(data.format.bit_rate))
|
|
|
|
|
{
|
|
|
|
|
video.BitRate = int.Parse(data.format.bit_rate);
|
|
|
|
|
}
|
2012-08-21 03:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-25 15:30:37 +00:00
|
|
|
|
if (data.streams != null)
|
2012-08-21 03:32:59 +00:00
|
|
|
|
{
|
2012-08-25 15:30:37 +00:00
|
|
|
|
// For now, only read info about first video stream
|
|
|
|
|
// Files with multiple video streams are possible, but extremely rare
|
|
|
|
|
bool foundVideo = false;
|
2012-08-21 03:32:59 +00:00
|
|
|
|
|
2012-08-25 15:30:37 +00:00
|
|
|
|
foreach (MediaStream stream in data.streams)
|
2012-08-22 12:56:44 +00:00
|
|
|
|
{
|
2012-08-25 15:30:37 +00:00
|
|
|
|
if (stream.codec_type.Equals("video", StringComparison.OrdinalIgnoreCase))
|
2012-08-22 12:56:44 +00:00
|
|
|
|
{
|
2012-08-25 15:30:37 +00:00
|
|
|
|
if (!foundVideo)
|
|
|
|
|
{
|
|
|
|
|
FetchFromVideoStream(video, stream);
|
|
|
|
|
}
|
2012-08-22 12:56:44 +00:00
|
|
|
|
|
2012-08-25 15:30:37 +00:00
|
|
|
|
foundVideo = true;
|
|
|
|
|
}
|
|
|
|
|
else if (stream.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
FetchFromAudioStream(video, stream);
|
|
|
|
|
}
|
2012-08-22 12:56:44 +00:00
|
|
|
|
}
|
2012-08-21 03:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FetchFromVideoStream(Video video, MediaStream stream)
|
|
|
|
|
{
|
|
|
|
|
video.Codec = stream.codec_name;
|
|
|
|
|
video.Width = stream.width;
|
|
|
|
|
video.Height = stream.height;
|
|
|
|
|
video.AspectRatio = stream.display_aspect_ratio;
|
2012-08-22 12:56:44 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(stream.avg_frame_rate))
|
|
|
|
|
{
|
|
|
|
|
string[] parts = stream.avg_frame_rate.Split('/');
|
|
|
|
|
|
|
|
|
|
if (parts.Length == 2)
|
|
|
|
|
{
|
|
|
|
|
video.FrameRate = float.Parse(parts[0]) / float.Parse(parts[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
video.FrameRate = float.Parse(parts[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FetchFromAudioStream(Video video, MediaStream stream)
|
|
|
|
|
{
|
2012-09-11 19:37:14 +00:00
|
|
|
|
var audio = new AudioStream{};
|
2012-08-22 12:56:44 +00:00
|
|
|
|
|
|
|
|
|
audio.Codec = stream.codec_name;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(stream.bit_rate))
|
|
|
|
|
{
|
|
|
|
|
audio.BitRate = int.Parse(stream.bit_rate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
audio.Channels = stream.channels;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(stream.sample_rate))
|
|
|
|
|
{
|
|
|
|
|
audio.SampleRate = int.Parse(stream.sample_rate);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-24 16:24:29 +00:00
|
|
|
|
audio.Language = GetDictionaryValue(stream.tags, "language");
|
2012-08-22 12:56:44 +00:00
|
|
|
|
|
2012-08-24 12:45:54 +00:00
|
|
|
|
List<AudioStream> streams = video.AudioStreams ?? new List<AudioStream>();
|
2012-08-22 12:56:44 +00:00
|
|
|
|
streams.Add(audio);
|
|
|
|
|
video.AudioStreams = streams;
|
2012-08-21 03:32:59 +00:00
|
|
|
|
}
|
2012-08-25 15:30:37 +00:00
|
|
|
|
|
|
|
|
|
private void FetchFromSubtitleStream(Video video, MediaStream stream)
|
|
|
|
|
{
|
2012-09-11 19:37:14 +00:00
|
|
|
|
var subtitle = new SubtitleStream{};
|
2012-08-25 15:30:37 +00:00
|
|
|
|
|
|
|
|
|
subtitle.Language = GetDictionaryValue(stream.tags, "language");
|
|
|
|
|
|
|
|
|
|
List<SubtitleStream> streams = video.Subtitles ?? new List<SubtitleStream>();
|
|
|
|
|
streams.Add(subtitle);
|
|
|
|
|
video.Subtitles = streams;
|
|
|
|
|
}
|
2012-08-21 03:32:59 +00:00
|
|
|
|
|
2012-08-20 19:16:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if there's already enough info in the Video object to allow us to skip running ffprobe
|
|
|
|
|
/// </summary>
|
2012-08-24 16:24:29 +00:00
|
|
|
|
protected override bool CanSkipFFProbe(Video video)
|
2012-08-20 19:16:51 +00:00
|
|
|
|
{
|
2012-08-24 16:24:29 +00:00
|
|
|
|
if (video.VideoType != VideoType.VideoFile)
|
|
|
|
|
{
|
|
|
|
|
// Not supported yet
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 19:16:51 +00:00
|
|
|
|
if (video.AudioStreams == null || !video.AudioStreams.Any())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 03:32:59 +00:00
|
|
|
|
if (string.IsNullOrEmpty(video.AspectRatio))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 19:16:51 +00:00
|
|
|
|
if (string.IsNullOrEmpty(video.Codec))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(video.ScanType))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 03:32:59 +00:00
|
|
|
|
if (!video.RunTimeTicks.HasValue || video.RunTimeTicks.Value == 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-11 19:37:14 +00:00
|
|
|
|
if (Convert.ToInt32(video.FrameRate) == 0 || video.Height == 0 || video.Width == 0 || video.BitRate == 0)
|
2012-08-20 19:16:51 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|