update hls subtitles

This commit is contained in:
Luke Pulverenti 2016-03-07 13:50:58 -05:00
parent a8296cba37
commit 9b8f85ea81
9 changed files with 31 additions and 26 deletions

View File

@ -214,7 +214,7 @@ namespace MediaBrowser.Api.Playback
args += " -map -0:a"; args += " -map -0:a";
} }
if (state.SubtitleStream == null) if (state.SubtitleStream == null || state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Hls)
{ {
args += " -map -0:s"; args += " -map -0:s";
} }
@ -477,7 +477,7 @@ namespace MediaBrowser.Api.Playback
var pts = string.Empty; var pts = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && !state.VideoRequest.CopyTimestamps) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode && !state.VideoRequest.CopyTimestamps)
{ {
var seconds = TimeSpan.FromTicks(state.Request.StartTimeTicks ?? 0).TotalSeconds; var seconds = TimeSpan.FromTicks(state.Request.StartTimeTicks ?? 0).TotalSeconds;
@ -575,7 +575,7 @@ namespace MediaBrowser.Api.Playback
var output = string.Empty; var output = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode)
{ {
var subParam = GetTextSubtitleParam(state); var subParam = GetTextSubtitleParam(state);
@ -865,7 +865,7 @@ namespace MediaBrowser.Api.Playback
{ {
var arg = string.Format("-i {0}", GetInputPathArgument(state)); var arg = string.Format("-i {0}", GetInputPathArgument(state));
if (state.SubtitleStream != null) if (state.SubtitleStream != null && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode)
{ {
if (state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream) if (state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream)
{ {

View File

@ -566,7 +566,7 @@ namespace MediaBrowser.Api.Playback.Hls
private void AddSubtitles(StreamState state, IEnumerable<MediaStream> subtitles, StringBuilder builder) private void AddSubtitles(StreamState state, IEnumerable<MediaStream> subtitles, StringBuilder builder)
{ {
var selectedIndex = state.SubtitleStream == null ? (int?)null : state.SubtitleStream.Index; var selectedIndex = state.SubtitleStream == null || state.VideoRequest.SubtitleMethod != SubtitleDeliveryMethod.Hls ? (int?)null : state.SubtitleStream.Index;
foreach (var stream in subtitles) foreach (var stream in subtitles)
{ {
@ -579,10 +579,11 @@ namespace MediaBrowser.Api.Playback.Hls
if (string.IsNullOrWhiteSpace(name)) name = stream.Codec ?? "Unknown"; if (string.IsNullOrWhiteSpace(name)) name = stream.Codec ?? "Unknown";
var url = string.Format("{0}/Subtitles/{1}/subtitles.m3u8?SegmentLength={2}", var url = string.Format("{0}/Subtitles/{1}/subtitles.m3u8?SegmentLength={2}&api_key={3}",
state.Request.MediaSourceId, state.Request.MediaSourceId,
stream.Index.ToString(UsCulture), stream.Index.ToString(UsCulture),
30.ToString(UsCulture)); 30.ToString(UsCulture),
AuthorizationContext.GetAuthorizationInfo(Request).Token);
var line = string.Format(format, var line = string.Format(format,
name, name,
@ -827,7 +828,7 @@ namespace MediaBrowser.Api.Playback.Hls
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"", var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",
state.SegmentLength.ToString(UsCulture)); state.SegmentLength.ToString(UsCulture));
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode;
args += " " + GetVideoQualityParam(state, GetH264Encoder(state)) + keyFrameArg; args += " " + GetVideoQualityParam(state, GetH264Encoder(state)) + keyFrameArg;
@ -853,7 +854,7 @@ namespace MediaBrowser.Api.Playback.Hls
private bool EnableCopyTs(StreamState state) private bool EnableCopyTs(StreamState state)
{ {
return state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream; return state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode;
} }
protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding)

View File

@ -9,6 +9,7 @@ using MediaBrowser.Model.Serialization;
using ServiceStack; using ServiceStack;
using System; using System;
using CommonIO; using CommonIO;
using MediaBrowser.Model.Dlna;
namespace MediaBrowser.Api.Playback.Hls namespace MediaBrowser.Api.Playback.Hls
{ {
@ -104,7 +105,7 @@ namespace MediaBrowser.Api.Playback.Hls
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"", var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",
state.SegmentLength.ToString(UsCulture)); state.SegmentLength.ToString(UsCulture));
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode;
args += " " + GetVideoQualityParam(state, GetH264Encoder(state)) + keyFrameArg; args += " " + GetVideoQualityParam(state, GetH264Encoder(state)) + keyFrameArg;

View File

@ -13,6 +13,7 @@ using System;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using CommonIO; using CommonIO;
using MediaBrowser.Model.Dlna;
namespace MediaBrowser.Api.Playback.Progressive namespace MediaBrowser.Api.Playback.Progressive
{ {
@ -161,7 +162,7 @@ namespace MediaBrowser.Api.Playback.Progressive
args += keyFrameArg; args += keyFrameArg;
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode;
var hasCopyTs = false; var hasCopyTs = false;
// Add resolution params, if specified // Add resolution params, if specified

View File

@ -164,6 +164,8 @@ namespace MediaBrowser.Api.Subtitles
long positionTicks = 0; long positionTicks = 0;
var segmentLengthTicks = TimeSpan.FromSeconds(request.SegmentLength).Ticks; var segmentLengthTicks = TimeSpan.FromSeconds(request.SegmentLength).Ticks;
var accessToken = AuthorizationContext.GetAuthorizationInfo(Request).Token;
while (positionTicks < runtime) while (positionTicks < runtime)
{ {
var remaining = runtime - positionTicks; var remaining = runtime - positionTicks;
@ -173,9 +175,10 @@ namespace MediaBrowser.Api.Subtitles
var endPositionTicks = Math.Min(runtime, positionTicks + segmentLengthTicks); var endPositionTicks = Math.Min(runtime, positionTicks + segmentLengthTicks);
var url = string.Format("stream.srt?StartPositionTicks={0}&EndPositionTicks={1}", var url = string.Format("stream.srt?StartPositionTicks={0}&EndPositionTicks={1}&api_key={2}",
positionTicks.ToString(CultureInfo.InvariantCulture), positionTicks.ToString(CultureInfo.InvariantCulture),
endPositionTicks.ToString(CultureInfo.InvariantCulture)); endPositionTicks.ToString(CultureInfo.InvariantCulture),
accessToken);
builder.AppendLine(url); builder.AppendLine(url);

View File

@ -90,8 +90,7 @@ namespace MediaBrowser.Controller.MediaEncoding
Cabac = info.Cabac; Cabac = info.Cabac;
Context = info.Context; Context = info.Context;
if (info.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode || if (info.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External)
info.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Embed)
{ {
SubtitleStreamIndex = info.SubtitleStreamIndex; SubtitleStreamIndex = info.SubtitleStreamIndex;
} }

View File

@ -20,6 +20,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommonIO; using CommonIO;
using MediaBrowser.Model.Dlna;
namespace MediaBrowser.MediaEncoding.Encoder namespace MediaBrowser.MediaEncoding.Encoder
{ {
@ -456,7 +457,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{ {
var arg = string.Format("-i {0}", GetInputPathArgument(state)); var arg = string.Format("-i {0}", GetInputPathArgument(state));
if (state.SubtitleStream != null) if (state.SubtitleStream != null && state.Options.SubtitleMethod == SubtitleDeliveryMethod.Encode)
{ {
if (state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream) if (state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream)
{ {
@ -826,7 +827,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
args += " -map -0:a"; args += " -map -0:a";
} }
if (state.SubtitleStream == null) if (state.SubtitleStream == null || state.Options.SubtitleMethod == SubtitleDeliveryMethod.Hls)
{ {
args += " -map -0:s"; args += " -map -0:s";
} }
@ -933,7 +934,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
var output = string.Empty; var output = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.Options.SubtitleMethod == SubtitleDeliveryMethod.Encode)
{ {
var subParam = GetTextSubtitleParam(state); var subParam = GetTextSubtitleParam(state);
@ -1018,7 +1019,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
var pts = string.Empty; var pts = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.Options.SubtitleMethod == SubtitleDeliveryMethod.Encode && !state.Options.CopyTimestamps)
{ {
var seconds = TimeSpan.FromTicks(state.Options.StartTimeTicks ?? 0).TotalSeconds; var seconds = TimeSpan.FromTicks(state.Options.StartTimeTicks ?? 0).TotalSeconds;

View File

@ -88,7 +88,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
args += keyFrameArg; args += keyFrameArg;
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.Options.SubtitleMethod == SubtitleDeliveryMethod.Encode;
// Add resolution params, if specified // Add resolution params, if specified
if (!hasGraphicalSubs) if (!hasGraphicalSubs)

View File

@ -783,6 +783,11 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (profile.Method == SubtitleDeliveryMethod.Hls && playMethod != PlayMethod.Transcode)
{
continue;
}
if (!profile.SupportsLanguage(subtitleStream.Language)) if (!profile.SupportsLanguage(subtitleStream.Language))
{ {
continue; continue;
@ -799,12 +804,6 @@ namespace MediaBrowser.Model.Dlna
{ {
return profile; return profile;
} }
// For sync we can handle the longer extraction times
if (context == EncodingContext.Static && subtitleStream.IsTextSubtitleStream)
{
return profile;
}
} }
} }
} }