From f89deb346a405e1d431841218a51f64acf743a0e Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 13 Jan 2014 12:27:41 +1100 Subject: [PATCH 1/2] Add automatic deinterlace --- .../Playback/BaseStreamingService.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index d9bd873cd..329fd2576 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -387,6 +387,7 @@ namespace MediaBrowser.Api.Playback var assSubtitleParam = string.Empty; var copyTsParam = string.Empty; + var yadif = "yadif=0:-1:0,"; var request = state.VideoRequest; @@ -408,7 +409,7 @@ namespace MediaBrowser.Api.Playback var widthParam = request.Width.Value.ToString(UsCulture); var heightParam = request.Height.Value.ToString(UsCulture); - return string.Format("{3} -vf \"scale=trunc({0}/2)*2:trunc({1}/2)*2{2}\"", widthParam, heightParam, assSubtitleParam, copyTsParam); + return string.Format("{4} -vf \"{0}scale=trunc({1}/2)*2:trunc({2}/2)*2{3}\"",yadif, widthParam, heightParam, assSubtitleParam, copyTsParam); } var isH264Output = outputVideoCodec.Equals("libx264", StringComparison.OrdinalIgnoreCase); @@ -419,8 +420,8 @@ namespace MediaBrowser.Api.Playback var widthParam = request.Width.Value.ToString(UsCulture); return isH264Output ? - string.Format("{2} -vf \"scale={0}:trunc(ow/a/2)*2{1}\"", widthParam, assSubtitleParam, copyTsParam) : - string.Format("{2} -vf \"scale={0}:-1{1}\"", widthParam, assSubtitleParam, copyTsParam); + string.Format("{3} -vf \"{0}scale={1}:trunc(ow/a/2)*2{2}\"",yadif, widthParam, assSubtitleParam, copyTsParam) : + string.Format("{3} -vf \"{0}scale={1}:-1{2}\"",yadif, widthParam, assSubtitleParam, copyTsParam); } // If a fixed height was requested @@ -429,8 +430,8 @@ namespace MediaBrowser.Api.Playback var heightParam = request.Height.Value.ToString(UsCulture); return isH264Output ? - string.Format("{2} -vf \"scale=trunc(oh*a*2)/2:{0}{1}\"", heightParam, assSubtitleParam, copyTsParam) : - string.Format("{2} -vf \"scale=-1:{0}{1}\"", heightParam, assSubtitleParam, copyTsParam); + string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:{1}{2}\"",yadif, heightParam, assSubtitleParam, copyTsParam) : + string.Format("{3} -vf \"{0}scale=-1:{1}{2}\"",yadif, heightParam, assSubtitleParam, copyTsParam); } // If a max width was requested @@ -439,8 +440,8 @@ namespace MediaBrowser.Api.Playback var maxWidthParam = request.MaxWidth.Value.ToString(UsCulture); return isH264Output ? - string.Format("{2} -vf \"scale=min(iw\\,{0}):trunc(ow/a/2)*2{1}\"", maxWidthParam, assSubtitleParam, copyTsParam) : - string.Format("{2} -vf \"scale=min(iw\\,{0}):-1{1}\"", maxWidthParam, assSubtitleParam, copyTsParam); + string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):trunc(ow/a/2)*2{2}\"", maxWidthParam, assSubtitleParam, copyTsParam) : + string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):-1{2}\"",yadif, maxWidthParam, assSubtitleParam, copyTsParam); } // If a max height was requested @@ -449,8 +450,8 @@ namespace MediaBrowser.Api.Playback var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture); return isH264Output ? - string.Format("{2} -vf \"scale=trunc(oh*a*2)/2:min(ih\\,{0}){1}\"", maxHeightParam, assSubtitleParam, copyTsParam) : - string.Format("{2} -vf \"scale=-1:min(ih\\,{0}){1}\"", maxHeightParam, assSubtitleParam, copyTsParam); + string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:min(ih\\,{1}){2}\"",yadif, maxHeightParam, assSubtitleParam, copyTsParam) : + string.Format("{3} -vf \"{0}scale=-1:min(ih\\,{1}){2}\"",yadif, maxHeightParam, assSubtitleParam, copyTsParam); } if (state.VideoStream == null) @@ -473,11 +474,11 @@ namespace MediaBrowser.Api.Playback var widthParam = outputSize.Width.ToString(UsCulture); var heightParam = outputSize.Height.ToString(UsCulture); - return string.Format("{3} -vf \"scale=trunc({0}/2)*2:trunc({1}/2)*2{2}\"", widthParam, heightParam, assSubtitleParam, copyTsParam); + return string.Format("{4} -vf \"{0}scale=trunc({1}/2)*2:trunc({2}/2)*2{3}\"",yadif, widthParam, heightParam, assSubtitleParam, copyTsParam); } // Otherwise use -vf scale since ffmpeg will ensure internally that the aspect ratio is preserved - return string.Format("{2} -vf \"scale={0}:-1{1}\"", Convert.ToInt32(outputSize.Width), assSubtitleParam, copyTsParam); + return string.Format("{3} -vf \"{0}scale={1}:-1{2}\"",yadif, Convert.ToInt32(outputSize.Width), assSubtitleParam, copyTsParam); } /// From 4bcbe3269e5e37d202689956080fa227993b5cf9 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 13 Jan 2014 12:39:11 +1100 Subject: [PATCH 2/2] Chang yadif to yadifParam --- .../Playback/BaseStreamingService.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 270067685..017e8e346 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -386,7 +386,7 @@ namespace MediaBrowser.Api.Playback var assSubtitleParam = string.Empty; var copyTsParam = string.Empty; - var yadif = "yadif=0:-1:0,"; + var yadifParam = "yadif=0:-1:0,"; var request = state.VideoRequest; @@ -408,7 +408,7 @@ namespace MediaBrowser.Api.Playback var widthParam = request.Width.Value.ToString(UsCulture); var heightParam = request.Height.Value.ToString(UsCulture); - return string.Format("{4} -vf \"{0}scale=trunc({1}/2)*2:trunc({2}/2)*2{3}\"",yadif, widthParam, heightParam, assSubtitleParam, copyTsParam); + return string.Format("{4} -vf \"{0}scale=trunc({1}/2)*2:trunc({2}/2)*2{3}\"",yadifParam, widthParam, heightParam, assSubtitleParam, copyTsParam); } var isH264Output = outputVideoCodec.Equals("libx264", StringComparison.OrdinalIgnoreCase); @@ -419,8 +419,8 @@ namespace MediaBrowser.Api.Playback var widthParam = request.Width.Value.ToString(UsCulture); return isH264Output ? - string.Format("{3} -vf \"{0}scale={1}:trunc(ow/a/2)*2{2}\"",yadif, widthParam, assSubtitleParam, copyTsParam) : - string.Format("{3} -vf \"{0}scale={1}:-1{2}\"",yadif, 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 @@ -429,8 +429,8 @@ namespace MediaBrowser.Api.Playback var heightParam = request.Height.Value.ToString(UsCulture); return isH264Output ? - string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:{1}{2}\"",yadif, heightParam, assSubtitleParam, copyTsParam) : - string.Format("{3} -vf \"{0}scale=-1:{1}{2}\"",yadif, 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 @@ -440,7 +440,7 @@ namespace MediaBrowser.Api.Playback return isH264Output ? string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):trunc(ow/a/2)*2{2}\"", maxWidthParam, assSubtitleParam, copyTsParam) : - string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):-1{2}\"",yadif, maxWidthParam, assSubtitleParam, copyTsParam); + string.Format("{3} -vf \"{0}scale=min(iw\\,{1}):-1{2}\"",yadifParam, maxWidthParam, assSubtitleParam, copyTsParam); } // If a max height was requested @@ -449,8 +449,8 @@ namespace MediaBrowser.Api.Playback var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture); return isH264Output ? - string.Format("{3} -vf \"{0}scale=trunc(oh*a*2)/2:min(ih\\,{1}){2}\"",yadif, maxHeightParam, assSubtitleParam, copyTsParam) : - string.Format("{3} -vf \"{0}scale=-1:min(ih\\,{1}){2}\"",yadif, 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) @@ -473,11 +473,11 @@ namespace MediaBrowser.Api.Playback 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}\"",yadif, widthParam, heightParam, assSubtitleParam, copyTsParam); + return string.Format("{4} -vf \"{0}scale=trunc({1}/2)*2:trunc({2}/2)*2{3}\"",yadifParam, widthParam, heightParam, 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}\"",yadif, Convert.ToInt32(outputSize.Width), assSubtitleParam, copyTsParam); + return string.Format("{3} -vf \"{0}scale={1}:-1{2}\"",yadifParam, Convert.ToInt32(outputSize.Width), assSubtitleParam, copyTsParam); } ///