update subtitle embedding

This commit is contained in:
Luke Pulverenti 2017-04-04 01:20:07 -04:00
parent 4a8960fc86
commit 99417105a6
2 changed files with 25 additions and 18 deletions

View File

@ -96,7 +96,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 && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultH264Preset()) + keyFrameArg; args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultH264Preset()) + keyFrameArg;

View File

@ -377,7 +377,7 @@ namespace MediaBrowser.Controller.MediaEncoding
var arg = string.Format("-i {0}", GetInputPathArgument(state)); var arg = string.Format("-i {0}", GetInputPathArgument(state));
if (state.SubtitleStream != null && request.SubtitleMethod == SubtitleDeliveryMethod.Encode) if (state.SubtitleStream != null && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode)
{ {
if (state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream) if (state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream)
{ {
@ -410,7 +410,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{ {
if (GetVideoEncoder(state, encodingOptions).IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1) if (GetVideoEncoder(state, encodingOptions).IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1)
{ {
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && request.SubtitleMethod == SubtitleDeliveryMethod.Encode; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;
var hwOutputFormat = "vaapi"; var hwOutputFormat = "vaapi";
if (hasGraphicalSubs) if (hasGraphicalSubs)
@ -782,7 +782,7 @@ namespace MediaBrowser.Controller.MediaEncoding
// Can't stream copy if we're burning in subtitles // Can't stream copy if we're burning in subtitles
if (request.SubtitleStreamIndex.HasValue) if (request.SubtitleStreamIndex.HasValue)
{ {
if (request.SubtitleMethod == SubtitleDeliveryMethod.Encode) if (state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode)
{ {
return false; return false;
} }
@ -1042,7 +1042,7 @@ namespace MediaBrowser.Controller.MediaEncoding
var pts = string.Empty; var pts = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.BaseRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode && !state.CopyTimestamps) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode && !state.CopyTimestamps)
{ {
var seconds = TimeSpan.FromTicks(state.StartTimeTicks ?? 0).TotalSeconds; var seconds = TimeSpan.FromTicks(state.StartTimeTicks ?? 0).TotalSeconds;
@ -1205,7 +1205,7 @@ namespace MediaBrowser.Controller.MediaEncoding
args += " -map -0:a"; args += " -map -0:a";
} }
var subtitleMethod = state.BaseRequest.SubtitleMethod; var subtitleMethod = state.SubtitleDeliveryMethod;
if (state.SubtitleStream == null || subtitleMethod == SubtitleDeliveryMethod.Hls) if (state.SubtitleStream == null || subtitleMethod == SubtitleDeliveryMethod.Hls)
{ {
args += " -map -0:s"; args += " -map -0:s";
@ -1421,7 +1421,7 @@ namespace MediaBrowser.Controller.MediaEncoding
var output = string.Empty; var output = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && request.SubtitleMethod == SubtitleDeliveryMethod.Encode) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode)
{ {
var subParam = GetTextSubtitleParam(state); var subParam = GetTextSubtitleParam(state);
@ -1696,6 +1696,8 @@ namespace MediaBrowser.Controller.MediaEncoding
} }
EnforceResolutionLimit(state); EnforceResolutionLimit(state);
NormalizeSubtitleEmbed(state);
} }
else else
{ {
@ -1705,6 +1707,21 @@ namespace MediaBrowser.Controller.MediaEncoding
state.MediaSource = mediaSource; state.MediaSource = mediaSource;
} }
private void NormalizeSubtitleEmbed(EncodingJobInfo state)
{
if (state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Embed)
{
return ;
}
// This is tricky to remux in, after converting to dvdsub it's not positioned correctly
// Therefore, let's just burn it in
if (string.Equals(state.SubtitleStream.Codec, "DVBSUB", StringComparison.OrdinalIgnoreCase))
{
state.SubtitleDeliveryMethod = SubtitleDeliveryMethod.Encode;
}
}
/// <summary> /// <summary>
/// Gets the name of the output video codec /// Gets the name of the output video codec
/// </summary> /// </summary>
@ -1810,16 +1827,6 @@ namespace MediaBrowser.Controller.MediaEncoding
codec = format; codec = format;
} }
// Muxing in dvbsub via either copy or -codec dvbsub does not seem to work
// It doesn't throw any errors but vlc on android will not render them
// They will need to be converted to an alternative format
// TODO: This is incorrectly assuming that dvdsub will be supported by the player
// The api will need to be expanded to accomodate this.
if (string.Equals(state.SubtitleStream.Codec, "DVBSUB", StringComparison.OrdinalIgnoreCase))
{
codec = "dvdsub";
}
var args = " -codec:s:0 " + codec; var args = " -codec:s:0 " + codec;
args += " -disposition:s:0 default"; args += " -disposition:s:0 default";
@ -1894,7 +1901,7 @@ namespace MediaBrowser.Controller.MediaEncoding
args += keyFrameArg; args += keyFrameArg;
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.BaseRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;
var hasCopyTs = false; var hasCopyTs = false;
// Add resolution params, if specified // Add resolution params, if specified