adjust video quality params for wmv
This commit is contained in:
parent
297e5efead
commit
5cc11294b1
|
@ -301,42 +301,73 @@ namespace MediaBrowser.Api.Playback
|
||||||
/// <param name="state">The state.</param>
|
/// <param name="state">The state.</param>
|
||||||
/// <param name="videoCodec">The video codec.</param>
|
/// <param name="videoCodec">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 videoCodec, bool isHls)
|
||||||
{
|
{
|
||||||
// webm
|
var param = string.Empty;
|
||||||
if (videoCodec.Equals("libvpx", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
// http://www.webmproject.org/docs/encoder-parameters/
|
|
||||||
return "-speed 16 -quality good -profile:v 0 -slices 8 -crf 18";
|
|
||||||
}
|
|
||||||
|
|
||||||
// asf/wmv
|
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
|
||||||
if (videoCodec.Equals("wmv2", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return "-qmin 2";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (videoCodec.Equals("libx264", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
{
|
||||||
switch (GetQualitySetting())
|
switch (GetQualitySetting())
|
||||||
{
|
{
|
||||||
case EncodingQuality.HighSpeed:
|
case EncodingQuality.HighSpeed:
|
||||||
return "-preset ultrafast -crf 18";
|
param = "-preset ultrafast -crf 18";
|
||||||
|
break;
|
||||||
case EncodingQuality.HighQuality:
|
case EncodingQuality.HighQuality:
|
||||||
return "-preset superfast -crf 18";
|
param = "-preset superfast -crf 18";
|
||||||
|
break;
|
||||||
case EncodingQuality.MaxQuality:
|
case EncodingQuality.MaxQuality:
|
||||||
return "-preset superfast -crf 18";
|
param = "-preset superfast -crf 18";
|
||||||
default:
|
break;
|
||||||
throw new Exception("Unrecognized MediaEncodingQuality value.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (videoCodec.Equals("mpeg4", StringComparison.OrdinalIgnoreCase))
|
// webm
|
||||||
|
else if (string.Equals(videoCodec, "libvpx", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
|
// http://www.webmproject.org/docs/encoder-parameters/
|
||||||
|
param = "-speed 16 -quality good -profile:v 0 -slices 8 -crf 18";
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Empty;
|
else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
param = "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
|
||||||
|
}
|
||||||
|
|
||||||
|
// asf/wmv
|
||||||
|
else if (string.Equals(videoCodec, "wmv2", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
param = "-qmin 2";
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
param = "-mbd 2";
|
||||||
|
}
|
||||||
|
|
||||||
|
param += GetVideoBitrateParam(state, videoCodec, isHls);
|
||||||
|
|
||||||
|
var framerate = GetFramerateParam(state);
|
||||||
|
if (framerate.HasValue)
|
||||||
|
{
|
||||||
|
param += string.Format(" -r {0}", framerate.Value.ToString(UsCulture));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(state.VideoSync))
|
||||||
|
{
|
||||||
|
param += " -vsync " + state.VideoSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
||||||
|
{
|
||||||
|
param += " -profile:v " + state.VideoRequest.Profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(state.VideoRequest.Level))
|
||||||
|
{
|
||||||
|
param += " -level " + state.VideoRequest.Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string GetAudioFilterParam(StreamState state, bool isHls)
|
protected string GetAudioFilterParam(StreamState state, bool isHls)
|
||||||
|
@ -723,7 +754,7 @@ namespace MediaBrowser.Api.Playback
|
||||||
}
|
}
|
||||||
if (codec == VideoCodecs.Wmv)
|
if (codec == VideoCodecs.Wmv)
|
||||||
{
|
{
|
||||||
return "wmv2";
|
return "msmpeg4";
|
||||||
}
|
}
|
||||||
if (codec == VideoCodecs.Theora)
|
if (codec == VideoCodecs.Theora)
|
||||||
{
|
{
|
||||||
|
@ -899,11 +930,40 @@ namespace MediaBrowser.Api.Playback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int? GetVideoBitrateParam(StreamState state)
|
protected int? GetVideoBitrateParamValue(StreamState state)
|
||||||
{
|
{
|
||||||
return state.VideoRequest.VideoBitRate;
|
return state.VideoRequest.VideoBitRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected string GetVideoBitrateParam(StreamState state, string videoCodec, bool isHls)
|
||||||
|
{
|
||||||
|
var bitrate = GetVideoBitrateParamValue(state);
|
||||||
|
|
||||||
|
if (bitrate.HasValue)
|
||||||
|
{
|
||||||
|
if (isHls)
|
||||||
|
{
|
||||||
|
return string.Format(" -b:v {0} -maxrate ({0}*.80) -bufsize {0}", bitrate.Value.ToString(UsCulture));
|
||||||
|
}
|
||||||
|
|
||||||
|
// With vpx when crf is used, b:v becomes a max rate
|
||||||
|
// https://trac.ffmpeg.org/wiki/vpxEncodingGuide
|
||||||
|
if (string.Equals(videoCodec, "libvpx", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return string.Format(" -b:v {0}", bitrate.Value.ToString(UsCulture));
|
||||||
|
}
|
||||||
|
if (string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return string.Format(" -b:v {0}", bitrate.Value.ToString(UsCulture));
|
||||||
|
}
|
||||||
|
return string.Format(" -maxrate {0} -bufsize {1}",
|
||||||
|
bitrate.Value.ToString(UsCulture),
|
||||||
|
(bitrate.Value * 2).ToString(UsCulture));
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
protected int? GetAudioBitrateParam(StreamState state)
|
protected int? GetAudioBitrateParam(StreamState state)
|
||||||
{
|
{
|
||||||
if (state.Request.AudioBitRate.HasValue)
|
if (state.Request.AudioBitRate.HasValue)
|
||||||
|
|
|
@ -172,7 +172,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
protected void GetPlaylistBitrates(StreamState state, out int audioBitrate, out int videoBitrate)
|
protected void GetPlaylistBitrates(StreamState state, out int audioBitrate, out int videoBitrate)
|
||||||
{
|
{
|
||||||
var audioBitrateParam = GetAudioBitrateParam(state);
|
var audioBitrateParam = GetAudioBitrateParam(state);
|
||||||
var videoBitrateParam = GetVideoBitrateParam(state);
|
var videoBitrateParam = GetVideoBitrateParamValue(state);
|
||||||
|
|
||||||
if (!audioBitrateParam.HasValue)
|
if (!audioBitrateParam.HasValue)
|
||||||
{
|
{
|
||||||
|
|
|
@ -299,14 +299,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
(state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 ||
|
(state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||||
state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1);
|
state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1);
|
||||||
|
|
||||||
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264") + keyFrameArg;
|
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg;
|
||||||
|
|
||||||
var bitrate = GetVideoBitrateParam(state);
|
|
||||||
|
|
||||||
if (bitrate.HasValue)
|
|
||||||
{
|
|
||||||
args += string.Format(" -b:v {0} -maxrate ({0}*.80) -bufsize {0}", bitrate.Value.ToString(UsCulture));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add resolution params, if specified
|
// Add resolution params, if specified
|
||||||
if (!hasGraphicalSubs)
|
if (!hasGraphicalSubs)
|
||||||
|
@ -317,27 +310,6 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var framerate = GetFramerateParam(state);
|
|
||||||
if (framerate.HasValue)
|
|
||||||
{
|
|
||||||
args += string.Format(" -r {0}", framerate.Value.ToString(UsCulture));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoSync))
|
|
||||||
{
|
|
||||||
args += " -vsync " + state.VideoSync;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
|
||||||
{
|
|
||||||
args += " -profile:v " + state.VideoRequest.Profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoRequest.Level))
|
|
||||||
{
|
|
||||||
args += " -level " + state.VideoRequest.Level;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is for internal graphical subs
|
// This is for internal graphical subs
|
||||||
if (hasGraphicalSubs)
|
if (hasGraphicalSubs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -176,14 +176,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
(state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 ||
|
(state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||||
state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1);
|
state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1);
|
||||||
|
|
||||||
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264") + keyFrameArg;
|
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg;
|
||||||
|
|
||||||
var bitrate = GetVideoBitrateParam(state);
|
|
||||||
|
|
||||||
if (bitrate.HasValue)
|
|
||||||
{
|
|
||||||
args += string.Format(" -b:v {0} -maxrate ({0}*.80) -bufsize {0}", bitrate.Value.ToString(UsCulture));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add resolution params, if specified
|
// Add resolution params, if specified
|
||||||
if (!hasGraphicalSubs)
|
if (!hasGraphicalSubs)
|
||||||
|
@ -194,27 +187,6 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var framerate = GetFramerateParam(state);
|
|
||||||
if (framerate.HasValue)
|
|
||||||
{
|
|
||||||
args += string.Format(" -r {0}", framerate.Value.ToString(UsCulture));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoSync))
|
|
||||||
{
|
|
||||||
args += " -vsync " + state.VideoSync;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
|
||||||
{
|
|
||||||
args += " -profile:v " + state.VideoRequest.Profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoRequest.Level))
|
|
||||||
{
|
|
||||||
args += " -level " + state.VideoRequest.Level;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is for internal graphical subs
|
// This is for internal graphical subs
|
||||||
if (hasGraphicalSubs)
|
if (hasGraphicalSubs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -156,50 +156,13 @@ namespace MediaBrowser.Api.Playback.Progressive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var framerate = GetFramerateParam(state);
|
var qualityParam = GetVideoQualityParam(state, codec, false);
|
||||||
if (framerate.HasValue)
|
|
||||||
{
|
|
||||||
args += string.Format(" -r {0}", framerate.Value.ToString(UsCulture));
|
|
||||||
}
|
|
||||||
|
|
||||||
var qualityParam = GetVideoQualityParam(state, codec);
|
|
||||||
|
|
||||||
var bitrate = GetVideoBitrateParam(state);
|
|
||||||
|
|
||||||
if (bitrate.HasValue)
|
|
||||||
{
|
|
||||||
if (string.Equals(codec, "libvpx", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
qualityParam += string.Format(" -b:v {0}", bitrate.Value.ToString(UsCulture));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qualityParam += string.Format(" -maxrate {0} -bufsize {1}",
|
|
||||||
bitrate.Value.ToString(UsCulture),
|
|
||||||
(bitrate.Value * 2).ToString(UsCulture));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(qualityParam))
|
if (!string.IsNullOrEmpty(qualityParam))
|
||||||
{
|
{
|
||||||
args += " " + qualityParam.Trim();
|
args += " " + qualityParam.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoSync))
|
|
||||||
{
|
|
||||||
args += " -vsync " + state.VideoSync;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
|
||||||
{
|
|
||||||
args += " -profile:v " + state.VideoRequest.Profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoRequest.Level))
|
|
||||||
{
|
|
||||||
args += " -level " + state.VideoRequest.Level;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is for internal graphical subs
|
// This is for internal graphical subs
|
||||||
if (hasGraphicalSubs)
|
if (hasGraphicalSubs)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user