|
|
@ -346,16 +346,32 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
var isVc1 = state.VideoStream != null &&
|
|
|
|
var isVc1 = state.VideoStream != null &&
|
|
|
|
string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase);
|
|
|
|
string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
|
|
|
|
|
|
|
|
|
|
|
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
param = "-preset superfast";
|
|
|
|
if (!string.IsNullOrWhiteSpace(encodingOptions.H264Preset))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
param += "-preset " + encodingOptions.H264Preset;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
param += "-preset superfast";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (encodingOptions.H264Crf >= 0 && encodingOptions.H264Crf <= 51)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
param += " -crf " + encodingOptions.H264Crf.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
param += " -crf 23";
|
|
|
|
param += " -crf 23";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
|
|
|
|
else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
param = "-preset fast";
|
|
|
|
param += "-preset fast";
|
|
|
|
|
|
|
|
|
|
|
|
param += " -crf 28";
|
|
|
|
param += " -crf 28";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -363,14 +379,14 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
// h264 (h264_qsv)
|
|
|
|
// h264 (h264_qsv)
|
|
|
|
else if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
|
|
|
else if (string.Equals(videoCodec, "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(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
param = "-preset default";
|
|
|
|
param += "-preset default";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// webm
|
|
|
|
// webm
|
|
|
@ -394,7 +410,7 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
profileScore = Math.Min(profileScore, 2);
|
|
|
|
profileScore = Math.Min(profileScore, 2);
|
|
|
|
|
|
|
|
|
|
|
|
// http://www.webmproject.org/docs/encoder-parameters/
|
|
|
|
// http://www.webmproject.org/docs/encoder-parameters/
|
|
|
|
param = string.Format("-speed 16 -quality good -profile:v {0} -slices 8 -crf {1} -qmin {2} -qmax {3}",
|
|
|
|
param += string.Format("-speed 16 -quality good -profile:v {0} -slices 8 -crf {1} -qmin {2} -qmax {3}",
|
|
|
|
profileScore.ToString(UsCulture),
|
|
|
|
profileScore.ToString(UsCulture),
|
|
|
|
crf,
|
|
|
|
crf,
|
|
|
|
qmin,
|
|
|
|
qmin,
|
|
|
@ -403,18 +419,18 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
|
|
|
|
|
|
|
else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase))
|
|
|
|
else if (string.Equals(videoCodec, "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(videoCodec, "wmv2", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
param = "-qmin 2";
|
|
|
|
param += "-qmin 2";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
|
|
|
|
else if (string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
param = "-mbd 2";
|
|
|
|
param += "-mbd 2";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
param += GetVideoBitrateParam(state, videoCodec);
|
|
|
|
param += GetVideoBitrateParam(state, videoCodec);
|
|
|
@ -1770,6 +1786,16 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
// state.SegmentLength = 6;
|
|
|
|
// state.SegmentLength = 6;
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.VideoRequest != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(state.VideoRequest.VideoCodec))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
state.SupportedVideoCodecs = state.VideoRequest.VideoCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();
|
|
|
|
|
|
|
|
state.VideoRequest.VideoCodec = state.SupportedVideoCodecs.FirstOrDefault(i => MediaEncoder.CanEncodeToAudioCodec(i))
|
|
|
|
|
|
|
|
?? state.SupportedVideoCodecs.FirstOrDefault();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.AudioCodec))
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.AudioCodec))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
state.SupportedAudioCodecs = request.AudioCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();
|
|
|
|
state.SupportedAudioCodecs = request.AudioCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();
|
|
|
@ -2012,7 +2038,7 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Source and target codecs must match
|
|
|
|
// Source and target codecs must match
|
|
|
|
if (!string.Equals(request.VideoCodec, videoStream.Codec, StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (string.IsNullOrEmpty(videoStream.Codec) || !state.SupportedVideoCodecs.Contains(videoStream.Codec, StringComparer.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|