From 6414fc9486a56dbf49de9dc42251c33acb10b148 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Dec 2015 10:51:38 -0500 Subject: remove MediaInfo --- .../Probing/ProbeResultNormalizer.cs | 34 +++++++--------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index d4df19af2..55b3398bb 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.IO; -using MediaBrowser.MediaInfo; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; @@ -26,7 +25,7 @@ namespace MediaBrowser.MediaEncoding.Probing _fileSystem = fileSystem; } - public Model.MediaInfo.MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) + public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) { var info = new Model.MediaInfo.MediaInfo { @@ -109,7 +108,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (videoStream != null && videoType == VideoType.VideoFile) { - UpdateFromMediaInfo(info, videoStream); + DetectInterlaced(info, videoStream); } } @@ -934,29 +933,18 @@ namespace MediaBrowser.MediaEncoding.Probing return TransportStreamTimestamp.None; } - private void UpdateFromMediaInfo(MediaSourceInfo video, MediaStream videoStream) + private void DetectInterlaced(MediaSourceInfo video, MediaStream videoStream) { - if (video.Protocol == MediaProtocol.File && videoStream != null) + if (video.Protocol != MediaProtocol.File || videoStream == null) { - try - { - _logger.Debug("Running MediaInfo against {0}", video.Path); - - var result = new MediaInfoLib().GetVideoInfo(video.Path); + return; + } - videoStream.IsCabac = result.IsCabac ?? videoStream.IsCabac; - videoStream.IsInterlaced = result.IsInterlaced ?? videoStream.IsInterlaced; - videoStream.BitDepth = result.BitDepth ?? videoStream.BitDepth; - videoStream.RefFrames = result.RefFrames ?? videoStream.RefFrames; - } - catch (TypeLoadException) - { - // This is non-essential. Don't spam the log - } - catch (Exception ex) - { - _logger.ErrorException("Error running MediaInfo on {0}", ex, video.Path); - } + // Take a shortcut and limit this to containers that are likely to have interlaced content + if (!string.Equals(video.Container, "ts", StringComparison.OrdinalIgnoreCase) && + !string.Equals(video.Container, "wtv", StringComparison.OrdinalIgnoreCase)) + { + return; } } } -- cgit v1.2.3 From 5c610d71f61f4f834a07102e9947d847f6a4efbf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Dec 2015 11:46:32 -0500 Subject: remove call from probe result normalizer --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 77 ++++++++++++++++++++++ .../Probing/ProbeResultNormalizer.cs | 22 ------- 2 files changed, 77 insertions(+), 22 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index c8361ea04..d4a626da0 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -262,6 +262,8 @@ namespace MediaBrowser.MediaEncoding.Encoder var mediaInfo = new ProbeResultNormalizer(_logger, FileSystem).GetMediaInfo(result, videoType, isAudio, primaryPath, protocol); + await DetectInterlaced(mediaInfo, inputPath, probeSizeArgument).ConfigureAwait(false); + if (extractKeyFrameInterval && mediaInfo.RunTimeTicks.HasValue) { if (ConfigurationManager.Configuration.EnableVideoFrameByFrameAnalysis && mediaInfo.Size.HasValue) @@ -304,6 +306,81 @@ namespace MediaBrowser.MediaEncoding.Encoder throw new ApplicationException(string.Format("FFProbe failed for {0}", inputPath)); } + private async Task DetectInterlaced(MediaSourceInfo video, string inputPath, string probeSizeArgument) + { + var videoStream = video.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); + + if (video.Protocol != MediaProtocol.File || videoStream == null) + { + return; + } + + // Take a shortcut and limit this to containers that are likely to have interlaced content + if (!string.Equals(video.Container, "ts", StringComparison.OrdinalIgnoreCase) && + !string.Equals(video.Container, "wtv", StringComparison.OrdinalIgnoreCase)) + { + //return; + } + + var args = "{0} -i {1} -map 0:v:{2} -filter:v idet -frames:v 500 -an -f null /dev/null"; + + var process = new Process + { + StartInfo = new ProcessStartInfo + { + CreateNoWindow = true, + UseShellExecute = false, + + // Must consume both or ffmpeg may hang due to deadlocks. See comments below. + RedirectStandardOutput = true, + RedirectStandardError = true, + RedirectStandardInput = true, + FileName = FFMpegPath, + Arguments = string.Format(args, probeSizeArgument, inputPath, videoStream.Index.ToString(CultureInfo.InvariantCulture)).Trim(), + + WindowStyle = ProcessWindowStyle.Hidden, + ErrorDialog = false + }, + + EnableRaisingEvents = true + }; + + _logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); + + using (var processWrapper = new ProcessWrapper(process, this, _logger)) + { + try + { + StartProcess(processWrapper); + } + catch (Exception ex) + { + _logger.ErrorException("Error starting ffprobe", ex); + + throw; + } + + try + { + process.BeginOutputReadLine(); + + using (var reader = new StreamReader(process.StandardError.BaseStream)) + { + var result = await reader.ReadToEndAsync().ConfigureAwait(false); + + File.WriteAllText("D:\\\\1.txt", result); + } + + } + catch + { + StopProcess(processWrapper, 100, true); + + throw; + } + } + } + private bool EnableKeyframeExtraction(MediaSourceInfo mediaSource, MediaStream videoStream) { if (videoStream.Type == MediaStreamType.Video && string.Equals(videoStream.Codec, "h264", StringComparison.OrdinalIgnoreCase) && diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 55b3398bb..d9fda220d 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -103,13 +103,6 @@ namespace MediaBrowser.MediaEncoding.Probing } ExtractTimestamp(info); - - var videoStream = info.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); - - if (videoStream != null && videoType == VideoType.VideoFile) - { - DetectInterlaced(info, videoStream); - } } return info; @@ -932,20 +925,5 @@ namespace MediaBrowser.MediaEncoding.Probing return TransportStreamTimestamp.None; } - - private void DetectInterlaced(MediaSourceInfo video, MediaStream videoStream) - { - if (video.Protocol != MediaProtocol.File || videoStream == null) - { - return; - } - - // Take a shortcut and limit this to containers that are likely to have interlaced content - if (!string.Equals(video.Container, "ts", StringComparison.OrdinalIgnoreCase) && - !string.Equals(video.Container, "wtv", StringComparison.OrdinalIgnoreCase)) - { - return; - } - } } } -- cgit v1.2.3