From 25cdbf014e16c7607605ee7287adcc953bba6211 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 24 Apr 2015 23:30:44 -0400 Subject: [PATCH] fix refFrames not being recorded --- MediaBrowser.Api/ItemRefreshService.cs | 13 ++++++++-- .../Encoder/MediaEncoder.cs | 6 +++-- .../Probing/ProbeResultNormalizer.cs | 8 +++--- MediaBrowser.Model/Dlna/StreamBuilder.cs | 26 ++++++++++++++++--- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.Api/ItemRefreshService.cs b/MediaBrowser.Api/ItemRefreshService.cs index 419077f212..f56fd32828 100644 --- a/MediaBrowser.Api/ItemRefreshService.cs +++ b/MediaBrowser.Api/ItemRefreshService.cs @@ -1,7 +1,9 @@ -using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Providers; using ServiceStack; +using System.Threading; namespace MediaBrowser.Api { @@ -52,7 +54,14 @@ namespace MediaBrowser.Api var options = GetRefreshOptions(request); - _providerManager.QueueRefresh(item.Id, options); + if (item is Folder) + { + _providerManager.QueueRefresh(item.Id, options); + } + else + { + _providerManager.RefreshFullItem(item, options, CancellationToken.None); + } } private MetadataRefreshOptions GetRefreshOptions(BaseRefreshRequest request) diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index d076a5b6ba..a01f37f91d 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -119,7 +119,7 @@ namespace MediaBrowser.MediaEncoding.Encoder var extractKeyFrameInterval = request.ExtractKeyFrameInterval && request.Protocol == MediaProtocol.File && request.VideoType == VideoType.VideoFile; return GetMediaInfoInternal(GetInputArgument(inputFiles, request.Protocol), request.InputPath, request.Protocol, extractChapters, extractKeyFrameInterval, - GetProbeSizeArgument(inputFiles, request.Protocol), request.MediaType == DlnaProfileType.Audio, cancellationToken); + GetProbeSizeArgument(inputFiles, request.Protocol), request.MediaType == DlnaProfileType.Audio, request.VideoType, cancellationToken); } /// @@ -155,6 +155,7 @@ namespace MediaBrowser.MediaEncoding.Encoder /// if set to true [extract key frame interval]. /// The probe size argument. /// if set to true [is audio]. + /// Type of the video. /// The cancellation token. /// Task{MediaInfoResult}. /// @@ -165,6 +166,7 @@ namespace MediaBrowser.MediaEncoding.Encoder bool extractKeyFrameInterval, string probeSizeArgument, bool isAudio, + VideoType videoType, CancellationToken cancellationToken) { var args = extractChapters @@ -236,7 +238,7 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - var mediaInfo = new ProbeResultNormalizer(_logger, FileSystem).GetMediaInfo(result, isAudio, primaryPath, protocol); + var mediaInfo = new ProbeResultNormalizer(_logger, FileSystem).GetMediaInfo(result, videoType, isAudio, primaryPath, protocol); if (extractKeyFrameInterval && mediaInfo.RunTimeTicks.HasValue) { diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 267ff875a9..2ef1c0cbd4 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -25,7 +25,7 @@ namespace MediaBrowser.MediaEncoding.Probing _fileSystem = fileSystem; } - public Model.MediaInfo.MediaInfo GetMediaInfo(InternalMediaInfoResult data, bool isAudio, string path, MediaProtocol protocol) + public Model.MediaInfo.MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) { var info = new Model.MediaInfo.MediaInfo { @@ -79,7 +79,7 @@ namespace MediaBrowser.MediaEncoding.Probing var videoStream = info.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); - if (videoStream != null) + if (videoStream != null && videoType == VideoType.VideoFile) { UpdateFromMediaInfo(info, videoStream); } @@ -863,12 +863,14 @@ namespace MediaBrowser.MediaEncoding.Probing private void UpdateFromMediaInfo(MediaSourceInfo video, MediaStream videoStream) { - if (video.VideoType == VideoType.VideoFile && video.Protocol == MediaProtocol.File) + if (video.Protocol == MediaProtocol.File) { if (videoStream != null) { try { + _logger.Debug("Running MediaInfo against {0}", video.Path); + var result = new MediaInfoLib().GetVideoInfo(video.Path); videoStream.IsCabac = result.IsCabac ?? videoStream.IsCabac; diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 30da8bb4c9..7cda57f4be 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -456,7 +456,7 @@ namespace MediaBrowser.Model.Dlna playlistItem.MaxAudioChannels = Math.Min(options.MaxAudioChannels.Value, currentValue); } - int audioBitrate = GetAudioBitrate(playlistItem.TargetAudioChannels, playlistItem.TargetAudioCodec); + int audioBitrate = GetAudioBitrate(playlistItem.TargetAudioChannels, playlistItem.TargetAudioCodec, audioStream); playlistItem.AudioBitrate = Math.Min(playlistItem.AudioBitrate ?? audioBitrate, audioBitrate); int? maxBitrateSetting = options.GetMaxBitrate(); @@ -479,17 +479,35 @@ namespace MediaBrowser.Model.Dlna return playlistItem; } - private int GetAudioBitrate(int? channels, string codec) + private int GetAudioBitrate(int? channels, string outputCodec, MediaStream audioStream) { + var defaultBitrate = 128000; + if (channels.HasValue) { if (channels.Value >= 5) { - return 320000; + defaultBitrate = 320000; + } + } + + int encoderAudioBitrateLimit = int.MaxValue; + + if (audioStream != null) + { + // Seeing webm encoding failures when source has 1 audio channel and 22k bitrate. + // Any attempts to transcode over 64k will fail + if (audioStream.Channels.HasValue && + audioStream.Channels.Value == 1) + { + if ((audioStream.BitRate ?? 0) < 64000) + { + encoderAudioBitrateLimit = 64000; + } } } - return 128000; + return Math.Min(defaultBitrate, encoderAudioBitrateLimit); } private PlayMethod? GetVideoDirectPlayProfile(DeviceProfile profile,