Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
13th April 2019, 20:07 | #1 | Link |
Registered User
Join Date: Dec 2018
Posts: 140
|
How make automatical resize (downscaling) with avs?
I'm newbe, do not hit me)
I wanna make something like downscaling to, for example, 1366/768 display So 1) Resizing should works only as downscaling 2) Target width/height should be devided to 2 without float (resizing limitation at least in SVP) Ideally it should be like TargetRes="1366,768" But TargetWidth=1366 TargetHeight=768 is okay too I'm not familiar with avisynth, imho it should be like WidthDen=width/TargetWidth HeightDen=height/TargetHeight WidthDen OR HeightDen > 1 eval(""" WidthDen > HeightDen eval(""" cropstring="BicubicResize(round(width/WidthDen),round(height/WidthDen),b=0,c=0.75)" """) : eval (""" cropstring="BicubicResize(round(width/HeightDen),round(height/HeightDen),b=0,c=0.75)" """) : cropstring="" But them also should be rounded to bigger number than must be devided to 2 |
13th April 2019, 22:20 | #2 | Link |
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
|
What you are looking for is ResizeKAR:
In your case, just use: Code:
ResizeKAR(1366, 768, "BicubicResize") Code:
# ResizeKAR() - May 8th, 2008 # Resize the source keeping the aspect ratio, by adding a border when needed. # # Input: # clip c: input clip. # int width: output width # int height: output height # Optional: # string ResizeMethod: Default(BilinearResize) # int BackgroundColor: Default($000000) # bool NoBorders: Resizes without adding borders. Default(False) # # Notes: # Respects ColorSpace Restrictions function ResizeKAR(clip c, int width, int height, string "ResizeMethod", int "BackgroundColor", bool "NoBorders") { BackgroundColor = Default(BackgroundColor, $000000) ResizeMethod = Default(ResizeMethod, "BilinearResize") NoBorders = Default(NoBorders, False) ratioS = Float(width(c))/Float(height(c)) ratioD = Float(width)/Float(height) newW = Round(height*ratioS/2)*2 newH = Round(width/ratioS/2)*2 BorderH = (NoBorders==True) ? 0 : Round((height-newH)/2) BorderW = (NoBorders==True) ? 0 : Round((width-newW)/2) #Dest Higher Then Source; Dest Wider Then Source; Same Ratio c = \ (ratioS>ratioD) ? \ Eval(ResizeMethod + "(c, " + String(width) + ", " + String(newH) + ")"). \ AddBorders(0, BorderH, 0, BorderH, BackgroundColor) : \ (ratioS<ratioD) ? \ Eval(ResizeMethod + "(c, " + String(newW) + ", " + String(height) + ")"). \ AddBorders(BorderW, 0, BorderW, 0, BackgroundColor) : \ (ratioS==ratioD) ? \ Eval(ResizeMethod + "(c, " + String(width) + ", " + String(height) + ")" ) : \ nop() #fix 1px changes, works only with 4:4:4 c = \ (IsRGB(c)) && (width>width(c)) && (NoBorders==false) ? c.AddBorders(0, 0, 1, 0) : \ (IsRGB(c)) && (height>height(c)) && (NoBorders==false) ? c.AddBorders(0, 0, 0, 1) : \ c return c } |
14th April 2019, 00:03 | #3 | Link |
Registered User
Join Date: Mar 2011
Posts: 4,823
|
For the record, a simple way to round is to do this (rounded down to mod2 in this example)
floor(NonRoundedNumber / 2.0) * 2 Normally you'd crop the existing picture to 16:9 first, or resize and then add borders as required for 16:9. If the source is 16:9 already, you can just resize to 16:9 dimensions. You can crop with the resizers though, and the cropping can be float. The function below would crop for the correct aspect ratio rather than add borders as FranceBB's function does. Code:
function MyResizing(clip Source, int "NewWidth", int "NewHeight") { SourceWidth = float(width(Source)) SourceHeight = float(height(Source)) SourceAspect = SourceWidth / SourceHeight NewWidth = default(NewWidth, 1366) NewHeight = default(NewHeight, 768) NewAspect = float(NewWidth) / float(NewHeight) SourceAspect < NewAspect ? eval(""" HeightCrop = SourceHeight - (SourceWidth / NewAspect) WidthCrop = 0 """) : SourceAspect > NewAspect ? eval(""" WidthCrop = SourceWidth - (SourceHeight * NewAspect) HeightCrop = 0 """) : eval(""" WidthCrop = 0 HeightCrop = 0 """) return Source.BicubicResize(NewWidth,NewHeight, \ src_left=WidthCrop/2.0, src_top=HeightCrop/2.0, \ src_width=SourceWidth-WidthCrop, src_height=SourceHeight-HeightCrop, \ b=0,c=0.75) } That's only been tested in my head, but it should be okay. It's pretty much the basis of this function, although it can crop or add borders. Unfortunately it won't resize with BicubicResize (unless it resizes with the Resize8 script), but it'd be easy enough to find the resizing in the function and change Spline36Resize to BicubicResize. The screenshots in the opening post I linked to have gone AWOL and I haven't replaced them as there's a new version of the function on the way. It will allow the use of any resizer but I've still got a few things to test. I've no idea how any of that would relate to SVP. I've never used it. Last edited by hello_hello; 14th April 2019 at 00:55. |
14th April 2019, 14:22 | #4 | Link |
Registered User
Join Date: Dec 2018
Posts: 140
|
Thanks, hello_hello, I will try
SVP is smoothvideo project, imho the best available pc's motion interpolator. It was paid-free and free to change settings to 3* version, it becomes shareware from 4* version with free libraries, but... Even "pro" version of this is not really pro, it do not allow you to control avisynth behaviour, just has slider, which makes mostly nothing. Slider's backend should be smart, but imho, it's stupid, not optimized. So I port SVPPro to clear avs with full access muhaha Wtf why am I must use float(number) to get correct result Last edited by Dreamject; 14th April 2019 at 14:43. |
14th April 2019, 17:11 | #5 | Link |
Registered User
Join Date: Mar 2011
Posts: 4,823
|
Avisynth does integer maths by default. So...
4 / 3 = 1 whereas 4.0 / 3.0 = 1.33333333 (only one needs to be float and Avisynth should convert the other to float automatically) I don't know what you're referring to specifically, but you can specify a number as float by adding a decimal point, so 4.0 is the same as float(4). Where are you having to use float? Are you referring to SVP or your port?? Many functions require a numerator and denominator as integers. ie AssumeFPS(24000, 1001) I sometimes find it annoying, especially when you have to type something like FPSNum=24000, FPSDen=1001. For my CropResize script, which has a few aspect ratio arguments, I chose to do the equivalent of Aspect=1.7777 or Aspect=16.0/9.0 It forces you to specify fractions as float though, because Aspect=16/9 would be the same as Aspect=1, and obviously wouldn't produce the expected result. That's hopefully the explanation, although without knowing specifically what you're referring to. Last edited by hello_hello; 14th April 2019 at 17:30. |
14th April 2019, 19:50 | #6 | Link |
Registered User
Join Date: Dec 2018
Posts: 140
|
I though I could increase speed using resize, but ffdshow's raw filter with PP veeery slow. I've made sending avs to registry to make it usable, but it's very slow (and my current laptop slow too). I can finish, but I wanted to friendly with svp's native functions Originally it uses resize string for resize settings like Code:
function interpolate(clip src) { input = crop_string=="" ? src : eval("src."+crop_string) input = resize_string=="" ? input : eval("input."+resize_string) #MT-MODE-1 #do not remove this line! super=SVSuper(input, super_params) vectors=SVAnalyse(super, analyse_params, src=input) smooth=SVSmoothFps(input, super, vectors, smoothfps_params, mt=threads, src=src) #MT-MODE-2 #do not remove this line! return demo_mode==0 ? smooth : demo(input,smooth) } Code:
NewWidth = 1366 NewHeight = 768 SourceAspect = float(source_width) / float(source_height) MyAspect = float(NewWidth) / float(NewHeight) SourceAspect > MyAspect ? eval(""" ResizedWidth=NewWidth ResizedHeight=round(float(source_height) * float(NewWidth) / float(source_width) / 2.0) * 2 """) : eval(""" ResizedHeight=NewHeight ResizedWidth=round(float(source_width) * float(NewHeight) / float(source_height) / 2.0 ) * 2 """) resize_string="BicubicResize("+String(ResizedWidth)+","+ResizedHeight+",b=0,c=0.75)" Also I wanted to use RoboCrop for autocroping, but it's not works in my cases https://forum.doom9.org/showthread.p...85#post1633485 .In best case it should 1 Detect black borders and remove it with auto crop 2 Check that height or width of cropped image bigger than target resolution and call resize ..but as I get I it's still be worse than PP's internal avisynth, the only advantage is autocropping |
14th April 2019, 23:24 | #7 | Link | |
Registered User
Join Date: Mar 2011
Posts: 4,823
|
Can't the Interpolate() function call a function to do the resizing and give it the clip so there's no having to worry about creating strings? I assume demo() is another function too, so it's the same idea. Using the previous MyResizing() function to do the work (which is already configured to default to a 1366x768 output).
Code:
function interpolate(clip src) { input = src.MyResizing() #MT-MODE-1 #do not remove this line! super=SVSuper(input, super_params) vectors=SVAnalyse(super, analyse_params, src=input) smooth=SVSmoothFps(input, super, vectors, smoothfps_params, mt=threads, src=src) #MT-MODE-2 #do not remove this line! return demo_mode==0 ? smooth : demo(input,smooth) } Quote:
source_width = float(width(Source)) source_height = float(height(Source)) SourceAspect = source_width / source_height If you defined the new width, height and aspect in a similar way, you wouldn't have to type float() so much. Code:
function ResizeString(clip Source, int "NewWidth", int "NewHeight") { NewWidth = default(NewWidth, 1366) NewHeight = default(NewHeight, 768) SourceAspect = float(source_width) / float(source_height) MyAspect = float(NewWidth) / float(NewHeight) SourceAspect > MyAspect ? eval(""" ResizedWidth=NewWidth ResizedHeight=round(float(source_height) * float(NewWidth) / float(source_width) / 2.0) * 2 """) : eval(""" ResizedHeight=NewHeight ResizedWidth=round(float(source_width) * float(NewHeight) / float(source_height) / 2.0 ) * 2 """) return "BicubicResize("+String(ResizedWidth)+","+ResizedHeight+",b=0,c=0.75)" } Code:
function interpolate(clip src) { input = CropString()=="" ? src : eval("src."+CropString()) input = ResizeString()=="" ? input : eval("input."+ResizeString()) #MT-MODE-1 #do not remove this line! super=SVSuper(input, super_params) vectors=SVAnalyse(super, analyse_params, src=input) smooth=SVSmoothFps(input, super, vectors, smoothfps_params, mt=threads, src=src) #MT-MODE-2 #do not remove this line! return demo_mode==0 ? smooth : demo(input,smooth) } Last edited by hello_hello; 14th April 2019 at 23:43. |
|
17th April 2019, 05:53 | #9 | Link |
Registered User
Join Date: Mar 2011
Posts: 4,823
|
I had another thought, although it seems odd to me the Interpolate() function always crops and resizes before it does the frame interpolation stuff. If your source is standard definition it'd be faster to interpolate frames first, then upscale.
When I use ffdshow's Avisynth filter, I usually aim to change the resolution as little as possible and then let the player upscale to fullscreen. That way you can crop if need be, but there's no need to add borders as the player will do it in fullscreen mode. I'm still not exactly sure what you're doing though. Anyway.... I also did this for myself, to see if I understand how to pass strings for cropping/resizing correctly. It seems to be working. It's much the same MyResizing() function as before, except it only creates global strings for cropping and resizing (it seems mental not to calculate them together) and passes the source through untouched. So assuming the global environment works with the way you're doing things, you should be able to load the function and use MyResizing() before Interpolate() to create the strings. Why you'd do it that way, I'm not sure, but this might give you some ideas. Code:
function MyResizing(clip Source, int "NewWidth", int "NewHeight") { SourceWidth = width(Source) SourceHeight = height(Source) SourceAspect = float(SourceWidth) / float(SourceHeight) NewWidth = default(NewWidth, 1366) >= SourceWidth ? SourceWidth : default(NewWidth, 1366) NewHeight = default(NewHeight, 768) >= SourceHeight ? SourceHeight : default(NewHeight, 768) NewAspect = float(NewWidth) / float(NewHeight) SourceAspect < NewAspect ? eval(""" HeightCrop = round(max(0, SourceHeight - (float(SourceWidth) / NewAspect) / 2.0)) * 2 CL = 0 CT = floor(HeightCrop / 4.0) * 2 CR = 0 CB = HeightCrop - CT """) : SourceAspect > NewAspect ? eval(""" WidthCrop = round(max(0, SourceWidth - (float(SourceHeight) * NewAspect) / 2.0)) * 2 CL = floor(WidthCrop / 4.0) * 2 CT = 0 CR = WidthCrop - CL CB = 0 """) : eval(""" CL=0 CT=0 CR=0 CB=0 """) global crop_string = (CL == CT == CR == CB == 0) ? "" : \ "Crop("+string(CL)+","+string(CT)+","+string(-CR)+","+string(-CB)+")" global resize_string = (SourceWidth == NewWidth) && (SourceHeight == NewHeight) ? "" : \ "BicubicResize("+string(NewWidth)+","+string(NewHeight)+",b=0,c=0.75)" return source } Code:
function TestingTesting(clip src) { input = crop_string=="" ? src : eval("src."+crop_string) input = resize_string=="" ? input : eval("input."+resize_string) return input } Edit1: MyResizing() changed to only downscale. The default for NewWidth is 1366, but when NewWidth >= the source width, it's ignored. The default for NewHeight is 768, but when NewHeight >= the source height, it's ignored. Edit2: Fixed the cropping. Last edited by hello_hello; 18th April 2019 at 20:34. |
17th April 2019, 10:22 | #10 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
by HH,
Quote:
Also there is also a liimit to vector length and so upscaling beforehand would make it more likely that good vectors are sometimes not found. EDIT: Actually, this is thread title "How make automatical resize (downscaling) with avs?" so unless OP changed his mind, might be better to interpolate after downscale.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 17th April 2019 at 10:55. |
|
19th April 2019, 22:32 | #15 | Link |
Registered User
Join Date: Dec 2018
Posts: 140
|
Mostly I can't test script, cause I do not know how to avisynth on any player expect PP, it seems to difficult and unusable to test it, anyway ffdshow even in x768 does not give improvements in perfomance in my case, I watch movies from laptop not very often, I need autocrop not very often too, etc). If it's not difficult, you can use this script/library https://vk.com/doc275347426_499703245 , I add it.
|
Thread Tools | Search this Thread |
Display Modes | |
|
|