|
@@ -337,9 +337,9 @@ namespace MediaBrowser.Api.Playback
|
|
/// Gets the video bitrate to specify on the command line
|
|
/// Gets the video bitrate to specify on the command line
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="state">The state.</param>
|
|
/// <param name="state">The state.</param>
|
|
- /// <param name="videoCodec">The video codec.</param>
|
|
|
|
|
|
+ /// <param name="videoEncoder">The video codec.</param>
|
|
/// <returns>System.String.</returns>
|
|
/// <returns>System.String.</returns>
|
|
- protected string GetVideoQualityParam(StreamState state, string videoCodec)
|
|
|
|
|
|
+ protected string GetVideoQualityParam(StreamState state, string videoEncoder)
|
|
{
|
|
{
|
|
var param = string.Empty;
|
|
var param = string.Empty;
|
|
|
|
|
|
@@ -348,7 +348,7 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
|
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
|
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
|
|
|
|
|
- if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ if (string.Equals(videoEncoder, "libx264", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(encodingOptions.H264Preset))
|
|
if (!string.IsNullOrWhiteSpace(encodingOptions.H264Preset))
|
|
{
|
|
{
|
|
@@ -369,7 +369,7 @@ namespace MediaBrowser.Api.Playback
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (string.Equals(videoEncoder, "libx265", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
param += "-preset fast";
|
|
param += "-preset fast";
|
|
|
|
|
|
@@ -377,20 +377,20 @@ namespace MediaBrowser.Api.Playback
|
|
}
|
|
}
|
|
|
|
|
|
// h264 (h264_qsv)
|
|
// h264 (h264_qsv)
|
|
- else if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
param += "-preset 7 -look_ahead 0";
|
|
param += "-preset 7 -look_ahead 0";
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// h264 (h264_nvenc)
|
|
// h264 (h264_nvenc)
|
|
- else if (string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
param += "-preset default";
|
|
param += "-preset default";
|
|
}
|
|
}
|
|
|
|
|
|
// webm
|
|
// webm
|
|
- else if (string.Equals(videoCodec, "libvpx", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (string.Equals(videoEncoder, "libvpx", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
// Values 0-3, 0 being highest quality but slower
|
|
// Values 0-3, 0 being highest quality but slower
|
|
var profileScore = 0;
|
|
var profileScore = 0;
|
|
@@ -417,23 +417,23 @@ namespace MediaBrowser.Api.Playback
|
|
qmax);
|
|
qmax);
|
|
}
|
|
}
|
|
|
|
|
|
- else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (string.Equals(videoEncoder, "mpeg4", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
param += "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
|
|
param += "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
|
|
}
|
|
}
|
|
|
|
|
|
// asf/wmv
|
|
// asf/wmv
|
|
- else if (string.Equals(videoCodec, "wmv2", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (string.Equals(videoEncoder, "wmv2", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
param += "-qmin 2";
|
|
param += "-qmin 2";
|
|
}
|
|
}
|
|
|
|
|
|
- else if (string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (string.Equals(videoEncoder, "msmpeg4", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
param += "-mbd 2";
|
|
param += "-mbd 2";
|
|
}
|
|
}
|
|
|
|
|
|
- param += GetVideoBitrateParam(state, videoCodec);
|
|
|
|
|
|
+ param += GetVideoBitrateParam(state, videoEncoder);
|
|
|
|
|
|
var framerate = GetFramerateParam(state);
|
|
var framerate = GetFramerateParam(state);
|
|
if (framerate.HasValue)
|
|
if (framerate.HasValue)
|
|
@@ -448,8 +448,8 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
|
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
|
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
|
{
|
|
{
|
|
- if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
- !string.Equals(videoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ if (!string.Equals(videoEncoder, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
+ !string.Equals(videoEncoder, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
// not supported by h264_omx
|
|
// not supported by h264_omx
|
|
param += " -profile:v " + state.VideoRequest.Profile;
|
|
param += " -profile:v " + state.VideoRequest.Profile;
|
|
@@ -458,11 +458,13 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
|
if (!string.IsNullOrEmpty(state.VideoRequest.Level))
|
|
if (!string.IsNullOrEmpty(state.VideoRequest.Level))
|
|
{
|
|
{
|
|
|
|
+ var level = NormalizeTranscodingLevel(state.OutputVideoCodec, state.VideoRequest.Level);
|
|
|
|
+
|
|
// h264_qsv and h264_nvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format
|
|
// h264_qsv and h264_nvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format
|
|
- if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
- string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ if (string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
+ string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
- switch (state.VideoRequest.Level)
|
|
|
|
|
|
+ switch (level)
|
|
{
|
|
{
|
|
case "30":
|
|
case "30":
|
|
param += " -level 3";
|
|
param += " -level 3";
|
|
@@ -492,20 +494,20 @@ namespace MediaBrowser.Api.Playback
|
|
param += " -level 5.2";
|
|
param += " -level 5.2";
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- param += " -level " + state.VideoRequest.Level;
|
|
|
|
|
|
+ param += " -level " + level;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ else if (!string.Equals(videoEncoder, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
- param += " -level " + state.VideoRequest.Level;
|
|
|
|
|
|
+ param += " -level " + level;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
- !string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
- !string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
- !string.Equals(videoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ if (!string.Equals(videoEncoder, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
+ !string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
+ !string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
+ !string.Equals(videoEncoder, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
param = "-pix_fmt yuv420p " + param;
|
|
param = "-pix_fmt yuv420p " + param;
|
|
}
|
|
}
|
|
@@ -513,6 +515,25 @@ namespace MediaBrowser.Api.Playback
|
|
return param;
|
|
return param;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private string NormalizeTranscodingLevel(string videoCodec, string level)
|
|
|
|
+ {
|
|
|
|
+ double requestLevel;
|
|
|
|
+
|
|
|
|
+ // Clients may direct play higher than level 41, but there's no reason to transcode higher
|
|
|
|
+ if (double.TryParse(level, NumberStyles.Any, UsCulture, out requestLevel))
|
|
|
|
+ {
|
|
|
|
+ if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ if (requestLevel > 41)
|
|
|
|
+ {
|
|
|
|
+ return "41";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return level;
|
|
|
|
+ }
|
|
|
|
+
|
|
protected string GetAudioFilterParam(StreamState state, bool isHls)
|
|
protected string GetAudioFilterParam(StreamState state, bool isHls)
|
|
{
|
|
{
|
|
var volParam = string.Empty;
|
|
var volParam = string.Empty;
|