adjust video quality params for wmv

pull/702/head
Luke Pulverenti 11 years ago
parent 297e5efead
commit 5cc11294b1

@ -301,42 +301,73 @@ namespace MediaBrowser.Api.Playback
/// <param name="state">The state.</param>
/// <param name="videoCodec">The video codec.</param>
/// <returns>System.String.</returns>
protected string GetVideoQualityParam(StreamState state, string videoCodec)
protected string GetVideoQualityParam(StreamState state, string videoCodec, bool isHls)
{
var param = string.Empty;
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
{
switch (GetQualitySetting())
{
case EncodingQuality.HighSpeed:
param = "-preset ultrafast -crf 18";
break;
case EncodingQuality.HighQuality:
param = "-preset superfast -crf 18";
break;
case EncodingQuality.MaxQuality:
param = "-preset superfast -crf 18";
break;
}
}
// webm
if (videoCodec.Equals("libvpx", StringComparison.OrdinalIgnoreCase))
else if (string.Equals(videoCodec, "libvpx", StringComparison.OrdinalIgnoreCase))
{
// http://www.webmproject.org/docs/encoder-parameters/
return "-speed 16 -quality good -profile:v 0 -slices 8 -crf 18";
param = "-speed 16 -quality good -profile:v 0 -slices 8 -crf 18";
}
else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase))
{
param = "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
}
// asf/wmv
if (videoCodec.Equals("wmv2", StringComparison.OrdinalIgnoreCase))
else if (string.Equals(videoCodec, "wmv2", StringComparison.OrdinalIgnoreCase))
{
return "-qmin 2";
param = "-qmin 2";
}
if (videoCodec.Equals("libx264", StringComparison.OrdinalIgnoreCase))
else if (string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
{
switch (GetQualitySetting())
{
case EncodingQuality.HighSpeed:
return "-preset ultrafast -crf 18";
case EncodingQuality.HighQuality:
return "-preset superfast -crf 18";
case EncodingQuality.MaxQuality:
return "-preset superfast -crf 18";
default:
throw new Exception("Unrecognized MediaEncodingQuality value.");
}
param = "-mbd 2";
}
if (videoCodec.Equals("mpeg4", StringComparison.OrdinalIgnoreCase))
param += GetVideoBitrateParam(state, videoCodec, isHls);
var framerate = GetFramerateParam(state);
if (framerate.HasValue)
{
return "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
param += string.Format(" -r {0}", framerate.Value.ToString(UsCulture));
}
return string.Empty;
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)
@ -723,7 +754,7 @@ namespace MediaBrowser.Api.Playback
}
if (codec == VideoCodecs.Wmv)
{
return "wmv2";
return "msmpeg4";
}
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;
}
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)
{
if (state.Request.AudioBitRate.HasValue)
@ -1180,7 +1240,7 @@ namespace MediaBrowser.Api.Playback
var probeSize = GetProbeSizeArgument(state.MediaPath, state.IsInputVideo, state.VideoType, state.IsoType);
inputModifier += " " + probeSize;
inputModifier = inputModifier.Trim();
inputModifier += " " + GetUserAgentParam(state.MediaPath);
inputModifier = inputModifier.Trim();

@ -172,7 +172,7 @@ namespace MediaBrowser.Api.Playback.Hls
protected void GetPlaylistBitrates(StreamState state, out int audioBitrate, out int videoBitrate)
{
var audioBitrateParam = GetAudioBitrateParam(state);
var videoBitrateParam = GetVideoBitrateParam(state);
var videoBitrateParam = GetVideoBitrateParamValue(state);
if (!audioBitrateParam.HasValue)
{

@ -299,14 +299,7 @@ namespace MediaBrowser.Api.Playback.Hls
(state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 ||
state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1);
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264") + keyFrameArg;
var bitrate = GetVideoBitrateParam(state);
if (bitrate.HasValue)
{
args += string.Format(" -b:v {0} -maxrate ({0}*.80) -bufsize {0}", bitrate.Value.ToString(UsCulture));
}
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg;
// Add resolution params, if specified
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
if (hasGraphicalSubs)
{

@ -176,14 +176,7 @@ namespace MediaBrowser.Api.Playback.Hls
(state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 ||
state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1);
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264") + keyFrameArg;
var bitrate = GetVideoBitrateParam(state);
if (bitrate.HasValue)
{
args += string.Format(" -b:v {0} -maxrate ({0}*.80) -bufsize {0}", bitrate.Value.ToString(UsCulture));
}
var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg;
// Add resolution params, if specified
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
if (hasGraphicalSubs)
{

@ -156,50 +156,13 @@ namespace MediaBrowser.Api.Playback.Progressive
}
}
var framerate = GetFramerateParam(state);
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));
}
}
var qualityParam = GetVideoQualityParam(state, codec, false);
if (!string.IsNullOrEmpty(qualityParam))
{
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
if (hasGraphicalSubs)
{

Loading…
Cancel
Save