aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Playback/BaseStreamingService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/Playback/BaseStreamingService.cs')
-rw-r--r--MediaBrowser.Api/Playback/BaseStreamingService.cs86
1 files changed, 54 insertions, 32 deletions
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
index 6545d995c..7f568183e 100644
--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs
+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs
@@ -870,33 +870,47 @@ namespace MediaBrowser.Api.Playback
inputChannels = null;
}
- int? resultChannels = null;
+ int? transcoderChannelLimit = null;
var codec = outputAudioCodec ?? string.Empty;
if (codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1)
{
// wmav2 currently only supports two channel output
- resultChannels = Math.Min(2, inputChannels ?? 2);
+ transcoderChannelLimit = 2;
}
- else if (request.MaxAudioChannels.HasValue)
+ else if (codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ // libmp3lame currently only supports two channel output
+ transcoderChannelLimit = 2;
+ }
+ else
{
- var channelLimit = codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1
- ? 2
- : 6;
+ // If we don't have any media info then limit it to 6 to prevent encoding errors due to asking for too many channels
+ transcoderChannelLimit = 6;
+ }
- if (inputChannels.HasValue)
- {
- channelLimit = Math.Min(channelLimit, inputChannels.Value);
- }
+ var isTranscodingAudio = !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase);
+
+ int? resultChannels = null;
+ if (isTranscodingAudio)
+ {
+ resultChannels = request.TranscodingMaxAudioChannels;
+ }
+ resultChannels = resultChannels ?? request.MaxAudioChannels ?? request.AudioChannels;
- // If we don't have any media info then limit it to 5 to prevent encoding errors due to asking for too many channels
- resultChannels = Math.Min(request.MaxAudioChannels.Value, channelLimit);
+ if (inputChannels.HasValue)
+ {
+ resultChannels = resultChannels.HasValue
+ ? Math.Min(resultChannels.Value, inputChannels.Value)
+ : inputChannels.Value;
}
- if (request.TranscodingMaxAudioChannels.HasValue && !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
+ if (isTranscodingAudio && transcoderChannelLimit.HasValue)
{
- resultChannels = Math.Min(request.TranscodingMaxAudioChannels.Value, resultChannels ?? inputChannels ?? request.TranscodingMaxAudioChannels.Value);
+ resultChannels = resultChannels.HasValue
+ ? Math.Min(resultChannels.Value, transcoderChannelLimit.Value)
+ : transcoderChannelLimit.Value;
}
return resultChannels ?? request.AudioChannels;
@@ -1054,7 +1068,19 @@ namespace MediaBrowser.Api.Playback
arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), Convert.ToInt32(height).ToString(CultureInfo.InvariantCulture));
}
- arg += " -i \"" + state.SubtitleStream.Path + "\"";
+
+ var subtitlePath = state.SubtitleStream.Path;
+
+ if (string.Equals(Path.GetExtension(subtitlePath), ".sub", StringComparison.OrdinalIgnoreCase))
+ {
+ var idxFile = Path.ChangeExtension(subtitlePath, ".idx");
+ if (FileSystem.FileExists(idxFile))
+ {
+ subtitlePath = idxFile;
+ }
+ }
+
+ arg += " -i \"" + subtitlePath + "\"";
}
}
@@ -1467,7 +1493,7 @@ namespace MediaBrowser.Api.Playback
}
// h264
- return string.Format(" -b:v {0} -maxrate {0} -bufsize {1}",
+ return string.Format(" -maxrate {0} -bufsize {1}",
bitrate.Value.ToString(UsCulture),
(bitrate.Value * 2).ToString(UsCulture));
}
@@ -1756,13 +1782,6 @@ namespace MediaBrowser.Api.Playback
{
if (videoRequest != null)
{
- videoRequest.EnableSplittingOnNonKeyFrames = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
- }
- }
- else if (i == 30)
- {
- if (videoRequest != null)
- {
videoRequest.RequireAvc = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
}
}
@@ -1948,10 +1967,15 @@ namespace MediaBrowser.Api.Playback
state.OutputVideoCodec = state.VideoRequest.VideoCodec;
state.OutputVideoBitrate = GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec);
- if (state.OutputVideoBitrate.HasValue)
+ if (videoRequest != null)
+ {
+ TryStreamCopy(state, videoRequest);
+ }
+
+ if (state.OutputVideoBitrate.HasValue && !string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
var resolution = ResolutionNormalizer.Normalize(
- state.VideoStream == null ? (int?)null : state.VideoStream.BitRate,
+ state.VideoStream == null ? (int?) null : state.VideoStream.BitRate,
state.OutputVideoBitrate.Value,
state.VideoStream == null ? null : state.VideoStream.Codec,
state.OutputVideoCodec,
@@ -1961,13 +1985,12 @@ namespace MediaBrowser.Api.Playback
videoRequest.MaxWidth = resolution.MaxWidth;
videoRequest.MaxHeight = resolution.MaxHeight;
}
- }
- ApplyDeviceProfileSettings(state);
-
- if (videoRequest != null)
+ ApplyDeviceProfileSettings(state);
+ }
+ else
{
- TryStreamCopy(state, videoRequest);
+ ApplyDeviceProfileSettings(state);
}
state.OutputFilePath = GetOutputFilePath(state);
@@ -2096,7 +2119,7 @@ namespace MediaBrowser.Api.Playback
state.MediaSource = mediaSource;
}
- protected virtual bool CanStreamCopyVideo(StreamState state)
+ protected bool CanStreamCopyVideo(StreamState state)
{
var request = state.VideoRequest;
var videoStream = state.VideoStream;
@@ -2381,7 +2404,6 @@ namespace MediaBrowser.Api.Playback
{
state.VideoRequest.CopyTimestamps = transcodingProfile.CopyTimestamps;
state.VideoRequest.EnableSubtitlesInManifest = transcodingProfile.EnableSubtitlesInManifest;
- state.VideoRequest.EnableSplittingOnNonKeyFrames = transcodingProfile.EnableSplittingOnNonKeyFrames;
}
}
}