fix webm resizing to odd dimensions

This commit is contained in:
Luke Pulverenti 2014-06-04 15:40:05 -04:00
parent bdc526cd58
commit 03a49672fa
2 changed files with 18 additions and 37 deletions

View File

@ -363,11 +363,11 @@ namespace MediaBrowser.Api.Playback
switch (qualitySetting) switch (qualitySetting)
{ {
case EncodingQuality.HighSpeed: case EncodingQuality.HighSpeed:
crf = "14"; crf = "16";
profileScore = 2; profileScore = 2;
break; break;
case EncodingQuality.HighQuality: case EncodingQuality.HighQuality:
crf = "8"; crf = "10";
profileScore = 1; profileScore = 1;
break; break;
case EncodingQuality.MaxQuality: case EncodingQuality.MaxQuality:
@ -518,16 +518,12 @@ namespace MediaBrowser.Api.Playback
return string.Format("{4} -vf \"{0}scale=trunc(min(iw\\,{1})/2)*2:trunc(min((iw/dar)\\,{2})/2)*2{3}\"", yadifParam, maxWidthParam, maxHeightParam, assSubtitleParam, copyTsParam); return string.Format("{4} -vf \"{0}scale=trunc(min(iw\\,{1})/2)*2:trunc(min((iw/dar)\\,{2})/2)*2{3}\"", yadifParam, maxWidthParam, maxHeightParam, assSubtitleParam, copyTsParam);
} }
var isH264Output = outputVideoCodec.Equals("libx264", StringComparison.OrdinalIgnoreCase);
// If a fixed width was requested // If a fixed width was requested
if (request.Width.HasValue) if (request.Width.HasValue)
{ {
var widthParam = request.Width.Value.ToString(UsCulture); var widthParam = request.Width.Value.ToString(UsCulture);
return isH264Output ? return string.Format("{3} -vf \"{0}scale={1}:trunc(ow/a/2)*2{2}\"", yadifParam, widthParam, assSubtitleParam, copyTsParam);
string.Format("{3} -vf \"{0}scale={1}:trunc(ow/a/2)*2{2}\"", yadifParam, widthParam, assSubtitleParam, copyTsParam) :
string.Format("{3} -vf \"{0}scale={1}:-1{2}\"", yadifParam, widthParam, assSubtitleParam, copyTsParam);
} }
// If a fixed height was requested // If a fixed height was requested
@ -535,9 +531,7 @@ namespace MediaBrowser.Api.Playback
{ {
var heightParam = request.Height.Value.ToString(UsCulture); var heightParam = request.Height.Value.ToString(UsCulture);
return isH264Output ? return string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:{1}{2}\"", yadifParam, heightParam, assSubtitleParam, copyTsParam);
string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:{1}{2}\"", yadifParam, heightParam, assSubtitleParam, copyTsParam) :
string.Format("{3} -vf \"{0}scale=-1:{1}{2}\"", yadifParam, heightParam, assSubtitleParam, copyTsParam);
} }
// If a max width was requested // If a max width was requested
@ -545,9 +539,7 @@ namespace MediaBrowser.Api.Playback
{ {
var maxWidthParam = request.MaxWidth.Value.ToString(UsCulture); var maxWidthParam = request.MaxWidth.Value.ToString(UsCulture);
return isH264Output ? return string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):trunc(ow/dar/2)*2{2}\"", yadifParam, maxWidthParam, assSubtitleParam, copyTsParam);
string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):trunc(ow/dar/2)*2{2}\"", yadifParam, maxWidthParam, assSubtitleParam, copyTsParam) :
string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):-1{2}\"", yadifParam, maxWidthParam, assSubtitleParam, copyTsParam);
} }
// If a max height was requested // If a max height was requested
@ -555,9 +547,7 @@ namespace MediaBrowser.Api.Playback
{ {
var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture); var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture);
return isH264Output ? return string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:min(ih\\,{1}){2}\"", yadifParam, maxHeightParam, assSubtitleParam, copyTsParam);
string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:min(ih\\,{1}){2}\"", yadifParam, maxHeightParam, assSubtitleParam, copyTsParam) :
string.Format("{3} -vf \"{0}scale=-1:min(ih\\,{1}){2}\"", yadifParam, maxHeightParam, assSubtitleParam, copyTsParam);
} }
if (state.VideoStream == null) if (state.VideoStream == null)
@ -574,17 +564,10 @@ namespace MediaBrowser.Api.Playback
var outputSize = DrawingUtils.Resize(currentWidth, currentHeight, request.Width, request.Height, request.MaxWidth, request.MaxHeight); var outputSize = DrawingUtils.Resize(currentWidth, currentHeight, request.Width, request.Height, request.MaxWidth, request.MaxHeight);
// If we're encoding with libx264, it can't handle odd numbered widths or heights, so we'll have to fix that var manualWidthParam = outputSize.Width.ToString(UsCulture);
if (isH264Output) var manualHeightParam = outputSize.Height.ToString(UsCulture);
{
var widthParam = outputSize.Width.ToString(UsCulture);
var heightParam = outputSize.Height.ToString(UsCulture);
return string.Format("{4} -vf \"{0}scale=trunc({1}/2)*2:trunc({2}/2)*2{3}\"", yadifParam, widthParam, heightParam, assSubtitleParam, copyTsParam); return string.Format("{4} -vf \"{0}scale=trunc({1}/2)*2:trunc({2}/2)*2{3}\"", yadifParam, manualWidthParam, manualHeightParam, assSubtitleParam, copyTsParam);
}
// Otherwise use -vf scale since ffmpeg will ensure internally that the aspect ratio is preserved
return string.Format("{3} -vf \"{0}scale={1}:-1{2}\"", yadifParam, Convert.ToInt32(outputSize.Width), assSubtitleParam, copyTsParam);
} }
/// <summary> /// <summary>
@ -1067,10 +1050,7 @@ namespace MediaBrowser.Api.Playback
{ {
string useragent = null; string useragent = null;
if (state.RemoteHttpHeaders != null) state.RemoteHttpHeaders.TryGetValue("User-Agent", out useragent);
{
state.RemoteHttpHeaders.TryGetValue("User-Agent", out useragent);
}
if (string.IsNullOrWhiteSpace(useragent)) if (string.IsNullOrWhiteSpace(useragent))
{ {
@ -1925,7 +1905,12 @@ namespace MediaBrowser.Api.Playback
if (state.IsRemote) if (state.IsRemote)
{ {
inputModifier += " " + GetUserAgentParam(state); var userAgentParam = GetUserAgentParam(state);
if (!string.IsNullOrWhiteSpace(userAgentParam))
{
inputModifier += " " + userAgentParam;
}
} }
inputModifier = inputModifier.Trim(); inputModifier = inputModifier.Trim();

View File

@ -28,12 +28,6 @@ namespace MediaBrowser.Api.Playback
get { return Request as VideoStreamRequest; } get { return Request as VideoStreamRequest; }
} }
public StreamState()
{
PlayableStreamFileNames = new List<string>();
RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
public Dictionary<string, string> RemoteHttpHeaders { get; set; } public Dictionary<string, string> RemoteHttpHeaders { get; set; }
/// <summary> /// <summary>
@ -82,6 +76,8 @@ namespace MediaBrowser.Api.Playback
_liveTvManager = liveTvManager; _liveTvManager = liveTvManager;
_logger = logger; _logger = logger;
SupportedAudioCodecs = new List<string>(); SupportedAudioCodecs = new List<string>();
PlayableStreamFileNames = new List<string>();
RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
} }
public string InputAudioSync { get; set; } public string InputAudioSync { get; set; }