VideoHelp Forum
+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 30 of 44
Thread
  1. For anyone stumbling across this thread, this is an old version of the script.
    The new version can be found
    here.

    Most of the information in this thread is outdated.

    I borrowed some ideas from the scripts AutoGK creates (credit to len0x), and turned them into a function called CropResize.

    CropResize can be used much like the standard Avisynth resizers, except instead of the resizing resulting in an aspect error if the image is resized "incorrectly", CropResize will automatically crop to prevent any aspect error (or keep it very close to zero).

    Here's some illustrations of the differences.

    Source image. Widescreen with black bars top and bottom for 16:9.
    Name:  source.jpg
Views: 1389
Size:  8.7 KB

    Spline36Resize(1280) # naturally it results in an error if no height is specified.
    Name:  1.gif
Views: 1542
Size:  4.6 KB

    CropResize(1280) # black is automatically cropped and the output height determined accordingly.
    Name:  2.jpg
Views: 1466
Size:  8.0 KB

    Spline36Resize(1280, 518) # without the correct cropping beforehand the picture is squashed.
    Name:  3.jpg
Views: 1460
Size:  6.9 KB

    CropResize(1280,518) # the black is cropped along with any additional picture as required for minimum aspect error (no additional picture cropping was required in this case).
    Name:  4.jpg
Views: 1438
Size:  8.0 KB

    CropResize(1280,720) # the black is cropped along with any additional picture as required for minimum aspect error.
    CropResize(1280, OutDar=1.777778) would produce the same result.
    Name:  5.jpg
Views: 1381
Size:  8.8 KB

    As you can see from the last picture, CropResize will crop the black, then it'll crop as much picture as required to give you the requested dimensions or display aspect ratio without aspect distortion. As a result, you'd normally use CropResize as follows and let it take care of the rest:
    CropResize(1280) or CropResize(1280,0)
    The idea of being able to specify a height or output display aspect ratio is mostly for a nice clean 16:9 or 4:3 output when your source is already close to 16:9 or 4:3 after cropping, as then only a small amount of picture will need to be cropped. CropResize can be used to specify any output display aspect ratio though, and as much picture will be removed as required to get you there.

    You may be aware Avisynth's resizers can also crop, and they're not limited to mod2 cropping:
    Spline36Resize(1280, 528, 2, 4, -1, -3)
    CropResize can now use much the same format. The difference being the cropping specified is cropping in addition to the auto-cropping and all values must be positive for additional cropping. That way if the auto-cropping doesn't give you perfectly clean edges, it's easy to adjust it. If the output height specified is zero, it's determined by the cropping (assuming no OutDAR is specified). The specified cropping doesn't have to be mod2, but autocrop can only crop mod2 so odd numbers will be rounded. Therefore it'd pay to stick to mod2 cropping
    CropResize(1280, 0, 2, 4, 2, 4)
    And while it's not mentioned in the autocrop help file, negative cropping seems to reduce the auto-cropping rather than increase it as positive values do.
    CropResize(1280, 0, -2, -4, -2, -4)

    CropResize() only requires autocrop.dll (included in the zip file) and always scales using Avisynth's "Spline36Resize".
    CropResize8() requires the Resize8 script which in turn requires RgTools.

    CropResize(OutWidth=Width, OutHeight=0, CL=0, CT=0, CR=0, CB=0, Cthresh=30, Cstart=0, Csample=5, OutDAR=0.0, Hmod=4, InDAR=0.0)

    CropResize8(OutWidth=Width, OutHeight=0, CL=0, CT=0, CR=0, CB=0, Cthresh=30, Cstart=0, Csample=5, OutDAR=0.0, Hmod=4, InDAR=0.0, Resizer="Spline36", ResizerC="Spline36")


    The Output DAR can also be used to specify an exact output resolution, assuming the Output Width and resolution width are the same:
    CropResize(1280, OutDAR=1280.0/720.0) # The difference between simply setting a width and height of 1280 & 720 is the Hmod setting takes preference over the height when OutDAR is used.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    OutWidth (default, same as source width)
    The desired Output Width (1280, 1024 etc). Specifying an Output Width of zero will output the same width as the source.
    OutHeight (default, determined by cropping)
    The desired Output Height (720, 576 etc). Output Height will be determined by auto-cropping and/or OutDAR if specified as zero. If the specified Output Height is greater than zero, the OutDAR & Hmod settings have no effect. If an Output Height is specified, as much picture will be cropped as required for minimum aspect error.
    CL, CT, CR, CB (defaults, 0)
    Cropping amounts in addition to the auto cropping. Left, top, right, bottom. Negative values decrease the auto-cropping.
    Cthresh (default, 30)
    How keenly the auto-cropping crops (range 0 - 255). Zero should disable autocropping and only the specified cropping (if any) will be applied.
    Cstart (default, 0)
    The first frame for the auto-cropping to check (in case there's a lot of black at the beginning and it over-crops).
    Csample (default, 5)
    How many frames autocrop checks.
    OutDAR (default, determined by cropping) Has no effect if OutHeight is specified and greater than zero.
    Must be float (ie 1.777778 or 16.0/9.0 etc). More than six decimal places is probably pointless. For specifying the desired Output Display Aspect Ratio, otherwise it's determined by the cropping (also if OutDAR=0.0). Use in preference to OutHeight if you want CropResize to determine the height automatically, but still want a predefined output aspect ratio. If you specify an Output DAR, as much picture will be cropped as required for minimum aspect error. The HMod setting takes precedence for determining the exact output height.
    HMod (default, 4) Has no effect if OutHeight is specified and greater than zero.
    The mod OutDAR should adjust the height to. Mod4 is the default.
    InDAR (default, same as source resolution) Required for correct resizing of anamorphic sources.
    The Input Display Aspect Ratio. Must be float (ie 1.777778 or 16.0/9.0 etc). If InDAR is not specified the source is assumed to have square pixels. More than six decimal places is probably pointless.
    CPreview (default, 0)
    When the cropping preview is enabled (CPreview=1) autocrop's suggested cropping information is overlayed on the existing clip. Resizing is disabled when the cropping preview is enabled so the video will always display at it's original resolution. See this post for an example.

    -------------------------------------------------------------------------------------------------------------

    CropResize8() works the same way as CropResize(), but instead of always resizing with Avisynth's Spline36Resize, it resizes using the Resize8 script. It has two additional options:

    Resizer (defaults, "Lanczos4" for luma upscaling, "Spline36" for luma downscaling, the same as the defaults for Resize8)
    Specifies any resizer supported by the Resize8 script for luma scaling. ie Resizer="Spline36" or Resizer="Bilinear" etc (it corresponds to the "kernel" option for the Resize8 script).
    ResizerC (defaults, "Lanczos" for chroma upscaling, "Spline36" for chroma downscaling, the same as the defaults for Resize8)
    Specifies any resizer supported by the Resize8 script for chroma scaling. ie ResizerC="Spline36" or ResizerC="Bilinear" etc (it corresponds to the "kernel_c" option for the Resize8 script).
    If "Resizer" is specified, but "ResizerC" is not, the scaling specified with the "Resizer" option is also applied to "ResizerC" (unlike the Resize8 script where specifying a luma resizer has no effect on the resizer used for chroma scaling).

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    The zip file contains the script and autocrop.dll
    CropResize 2017-03-06

    CropResize 2017-03-09 (Fixed the CPreview option)
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Last edited by hello_hello; 7th Aug 2019 at 10:22.
    Quote Quote  
  2. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    A fraction is identical to a mathematical division

    ie 4:3 == 4/3 == 1.333333333

    AVISynth should handle that automatically.

    ie Output_DAR=4/3 == Output_DAR=1.3333333_

    Or am I missing something?
    Quote Quote  
  3. autocrop.dll seems to always overcrop depending on mode. I never used mode higher than 4 (in autocrop.dll terms wMultOf,hMultOf, the word "mode" , it uses for something else) Not sure what it does if mode set to 8
    Quote Quote  
  4. Originally Posted by ndjamena View Post
    A fraction is identical to a mathematical division

    ie 4:3 == 4/3 == 1.333333333

    AVISynth should handle that automatically.

    ie Output_DAR=4/3 == Output_DAR=1.3333333_

    Or am I missing something?
    I think Avisynth rounds to whole numbers (integer?), unless you specify float and I wasn't sure how to do that, so I'm pretty sure 4/3=1 unless you tell Avisynth otherwise, although I could be wrong. 4.0/3.0 would equal 1.33333333_ or maybe float(4)/3 or something like that. I'm a little new to this so as I said I could be misunderstanding.
    Quote Quote  
  5. Originally Posted by _Al_ View Post
    autocrop.dll seems to always overcrop depending on mode. I never used mode higher than 4 (in autocrop.dll terms wMultOf,hMultOf, the word "mode" , it uses for something else) Not sure what it does if mode set to 8
    Mode in autocrop terms tells autocrop.dll whether or not to crop. For mode=0 it crops, mode=1 draws a line to show you where the cropping would be, mode=2 writes a log file and for mode=3 it crops and writes a log. It's always mode=0 in the script, but I could add the mode setting. It didn't seem necessary though.

    The default "mod" for autocrop.dll is mod4 for the width and mod2 for the height (wMultOf, hMultOf), but the default mod for the CropResize script is mod4 for the height. The width is the same as the source width or whatever width you specify, so if you specify a width of 718 it'll be mod2.

    The height_mod setting in the script determines the "mod" of the height...... mod2, mod4 etc.

    If it's over-cropping a little it'd probably be because it needs to to give you the specified output without distorting the picture. If you don't specify an output display aspect ratio, or a large mod, I don't think it's likely to over-crop much, if at all. At the other extreme though, if you have a 1.33333 picture and specify a 1.77777 Output DAR for the script, it'll massively over-crop the top and bottom of the picture to give you 1.7777777.
    Last edited by hello_hello; 21st Feb 2017 at 13:58.
    Quote Quote  
  6. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Originally Posted by hello_hello View Post
    Originally Posted by ndjamena View Post
    A fraction is identical to a mathematical division

    ie 4:3 == 4/3 == 1.333333333

    AVISynth should handle that automatically.

    ie Output_DAR=4/3 == Output_DAR=1.3333333_

    Or am I missing something?
    I think Avisynth rounds to whole numbers (integer?), unless you specify float and I wasn't sure how to do that, so I'm pretty sure 4/3=1 unless you tell Avisynth otherwise, although I could be wrong. 4.0/3.0 would equal 1.33333333_ or maybe float(4)/3 or something like that. I'm a little new to this so as I said I could be misunderstanding.
    You're right, so basically you want this:

    Code:
    ceil((4.0/3.0)*1000000.0)/1000000.0
    -edit- or I guess more to the point:

    Code:
    ceil((flaot(4)/float(3))*1000000.0)/1000000.0
    Quote Quote  
  7. ndjamena,
    It's adding it to the script so Input_DAR can be entered as both a decimal and fraction that I haven't got my head around though.

    Maybe it's staring me in the face when I read your reply but I don't realise it yet. Currently I have the Input_DAR set like this so it's the same as the source resolution by default, and it has to be specified as float as an option.

    Input_DAR = default(Input_DAR, Float(c.width)/Float(c.height))

    Then there's a line in the script to set the "picture aspect ratio" to the same as the source resolution if the user sets Input_DAR to zero, otherwise Picture_Aspect_Ratio uses the Input_DAR specified, which is once again the source resolution if the Input_DAR isn't specified at all.

    Picture_Aspect_Ratio = (Input_DAR == 0) ? (Float(c.width)/Float(c.height)) : (Input_DAR)

    That seems to work fine but I'm still not certain how to make it work so Input_DAR can be entered as a fraction or even as a whole number.
    ie In_DAR=1.333334 or Input_Dar = 16/9 or Input_DAR=2 etc.

    I assume the magic will be in the boolean functions such as IsFloat or IsInt etc, but I haven't made it that far yet. It's literally my first function so I'm still taking baby steps. I'll look more closely at that in a little while to see if I can work it out, once I find "ceil" so I know what it does.
    Last edited by hello_hello; 21st Feb 2017 at 06:02.
    Quote Quote  
  8. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Unless you ask for a string instead of a number, what you're thinking is impossible.
    Code:
    CropResize(var Input_Dar)
    
    Pos = IsString(Input_Dar) ? FindStr(Input_Dar, ":") : 0
    Pos = Pos==0 ? Pos = IsString(Input_Dar) ? FindStr(Input_Dar, "/") : 0 : Pos
    
    Num = Pos!=0 ? LeftStr(Input_Dar, Pos-1) : IsString(Input_Dar) ? Value(Input_Dar) : float(Input_Dar)
    Den = Pos!=0 ? MidStr(Input_Dar, Pos+1) : 1.0
    
    Dar = float(Num) / float(Den)
    ...

    I don't know if that will work, I've just been writing based on what I think might work, but there's no "equation" variable and dividing integers returns an integer so...
    Last edited by ndjamena; 21st Feb 2017 at 06:38.
    Quote Quote  
  9. Once I understand what you've written I'll play around, because at least I'll learn a bit more, but maybe it's be easier to leave it as a decimal.

    Unless there were two Input_DAR options. Nah.... there's probably no point.

    I'll play around though.
    Thanks.
    Quote Quote  
  10. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    It's just a basic outline of what might be needed, not being able to concentrate makes proof reading difficult, I think I've fixed all the obvious errors... I think it could do with more checking and I'm not sure if avisynth will spit out errors if Input_Dar isn't a string but I've pretty much burnt myself out for now and don't really know what you need or will find acceptable.
    Quote Quote  
  11. Thanks anyway. You given me more to think about.

    After a little penny dropping, it appears a fraction can be float, which I think is fine for this purpose if it's entered that way.
    4:3 can be entered as the Input_DAR as long as it's entered as 4.0/3.0, whereas 4/3 will produce the wrong aspect ratio, and it should be fairly obvious.

    I thought because I specified Input_DAR as float rather than integer it'd have to be entered that way, but 4/3 doesn't produce an error so maybe what I need to do is add a line that checks Input_DAR is float and spits out an error if it's not, so 4.0/3.0 will work but 4/3 won't. I'll investigate.... I haven't done that before.

    Cheers.
    Quote Quote  
  12. Try this script:
    Code:
    BlankClip()
    Subtitle("4/3="+string(4/3)+" vs. 4.0/3.0="+String(4.0/3.0))
    Quote Quote  
  13. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    This works:
    Code:
    subtitle("4/3=" + string(eval("1.0*"+"4/3")))
    if you want to enforce entering a string using '/' and not ':'
    Last edited by ndjamena; 21st Feb 2017 at 11:42.
    Quote Quote  
  14. Originally Posted by hello_hello View Post
    Originally Posted by _Al_ View Post
    autocrop.dll seems to always overcrop depending on mode. I never used mode higher than 4 (in autocrop.dll terms wMultOf,hMultOf, the word "mode" , it uses for something else) Not sure what it does if mode set to 8
    Mode in autocrop terms tells autocrop.dll whether or not to crop. For mode=0 it crops, mode=1 draws a line to show you where the cropping would be, mode=3 writes a log file and for mode=4 it crops and writes a log. It's always mode=0 in the script, but I could add the mode setting. It didn't seem necessary though.

    The default "mod" for autocrop.dll is mod2 (wMultOf, hMultOf), but the default mod for the CropResize script is mod4 for the height. The width is the same as the source width or whatever width you specify, so if you specify a width of 718 it'll be mod2.

    The height_mod setting in the script determines the "mod" of the height...... mod2, mod4 etc.

    If it's over-cropping a little it'd probably be because it needs to to give you the specified output without distorting the picture. If you don't specify an output display aspect ratio, or a large mod, I don't think it's likely to over-crop much, if at all. At the other extreme though, if you have a 1.33333 picture and specify a 1.77777 Output DAR for the script, it'll massively over-crop the top and bottom of the picture to give you 1.7777777.
    ..and I use mode2 (different version of autocrop?), that you did not mention, it just creates crop line into a log, understand you can run autocrop.dll in a script first, just loading into avsmeter or virtualdub running command line, just to get that crop line and nothing else

    about those aspect ratios, ....... please not again , do your thing in here in this thread, do some calculations etc, get some lines from guys here that would do it, but I stay away from this, because it is not needed, just fyi, do not try to explain it yet again ...

    I just want to stress the approach, I do not create final avisynth script with all that programming avisynth language, rather doing it in batch scripts, much, much easier, avisynth just runs autocrop.dll mode2, generating crop line,
    echo autocrop(2,%wMultOf%,%hMultOf%) >> autocrop.avs
    and batch script (or whatever programing language, if you program it in different language) decides what to do afterwards, adding that cropping line into real avisynth script, or not if it is fishy,because it is a real world, autocrop.dll has to be checked upon etc.

    adding this mode autocrop info, as I said, using 2, to just get that crop line info, nothing else, you juxtaposed mode 2 and 3 to 3 and 4:
    0 - Crop - Crops the image
    1 - Preview - Suggested cropping information is overlayed on the existing clip, including
    a crop command that you can use to replace AutoCrop with.
    2 - Log - Logs the cropping parameters to the file "AutoCrop.log" in the current
    directory.
    3- Crop & Log - combination of modes 0 and 2
    Last edited by _Al_; 21st Feb 2017 at 09:14.
    Quote Quote  
  15. Originally Posted by ndjamena View Post
    This works:
    Code:
    subtitle("4/3" + string(eval("1.0*"+"4/3")))
    if you want to enforce entering a string using '/' and not ':'
    Nice workaround.
    Quote Quote  
  16. Originally Posted by _Al_ View Post
    about those aspect ratios, ....... please not again , do your thing in here in this thread, do some calculations etc, get some lines from guys here that would do it, but I stay away from this, because it is not needed, just fyi, do not try to explain it yet again ...
    How do you get to keep telling someone they're doing it wrong and then tell them not to reply?

    Just because you're happy to do it a certain way or happy not to crop, it doesn't mean everyone else is, and if you want to output a certain width or aspect ratio with nice clean cropping you need to do some aspect ratio calculations. That's what this script is designed for, to semi automate the process so there's no need to mess around with aspect error calculators yourself if you don't want to.

    I've already found one use for it. A couple of people in the house prefer to watch video filling the screen and don't have a way to easily zoom as I do (they don't use a PC for playback), and whether you think it's "as the director intended" sacrilege or not, the script makes it very easy for me to knock off a quick copy for one-time viewing using fast x264 settings and without having to manually crop and calculate resizing any more.

    This:
    Name:  before.jpg
Views: 1669
Size:  10.8 KB

    Becomes this:
    Name:  after.jpg
Views: 1641
Size:  14.5 KB

    and the closest I have to come to thinking about it now is this:

    CropResize(OutWidth=1280, OutDAR=16.0/9.0)
    or this:
    CropResize(1280, 16.0/9.0)

    Originally Posted by _Al_ View Post
    I just want to stress the approach, I do not create final avisynth script with all that programming avisynth language, rather doing it in batch scripts, much, much easier, avisynth just runs autocrop.dll mode2, generating crop line,
    echo autocrop(2,%wMultOf%,%hMultOf%) >> autocrop.avs
    and batch script (or whatever programing language, if you program it in different language) decides what to do afterwards, adding that cropping line into real avisynth script, or not if it is fishy,because it is a real world, autocrop.dll has to be checked upon etc.
    Well I just open the script to preview it and make sure the cropping is clean. Or crop it manually the same way. Usually with MeGUI's preview

    Originally Posted by _Al_ View Post
    adding this mode autocrop info, as I said, using 2, to just get that crop line info, nothing else, you juxtaposed mode 2 and 3 to 3 and 4:
    So I did. I'll fix that.

    Anyway, back to checking out what goodies ndjamena and jagabo have offered.....
    Last edited by hello_hello; 2nd Mar 2017 at 10:19.
    Quote Quote  
  17. I haven't even looked at the script. I was just pointing out that if you use an equation with only integer values it is handled as integers. If you use a floating point value it's handled as floating point.
    Last edited by jagabo; 21st Feb 2017 at 15:50.
    Quote Quote  
  18. jagabo,

    Ideally, I'm wanting to be able to enter a fraction as the Input_DAR and have it converted to float automatically so it's handled correctly. Currently 1.33333 works for the input DAR and you can enter it as a fraction like this 4.0/3.0, but if you enter it as 4/3 it's converted to integer so the output DAR ends up wrong. Input_DAR only has to be specified for anamorphic sources but that's when 4/3 or 16/9 might be incorrectly specified.

    So I understand the problem, I just need to be able to enter 4/3 as the Input_DAR and have it converted to 4.0/3.0 so it's handled correctly, or alternatively 4/3 would produce an error to prevent it's use. It's not the end of the world but it'd be nice if either were possible.

    When you specify an option, ie
    function CropResize(clip c, int "Out_Width", float "Input_DAR", float "Output_DAR")
    I assumed specifying "float" would force the value to be entered that way (ie 1.0) or it'd produce an error, but I guess that's not what happens.

    It's a fairly simple script but it's a learning experience for me. I haven't experimented with the Input_DAR setting any further yet because I found a small aspect error of a couple of pixels in the width while testing. Sometimes the simplest things.... it turned out autcrop's default cropping is mod4 for the width and mod2 for the height, and I misread the instructions and thought it was mod2 for both, so now and then there was a small aspect error I couldn't find until the penny dropped. That's fixed now so I'll replace the script in the opening post with the fixed version in a little while.

    Cheers.
    Quote Quote  
  19. So use ndjamena workaround. Enter DAR as a text variable then use eval() to convert it to a float:

    Code:
    DAR="4/3"
    FP_DAR=eval("1.0*"+DAR)
    subtitle(string(FP_DAR))
    Again, I haven't looked at the script but you should be able to work with that.

    Or enter your aspect ratios as integer numerator and denominator. Then convert to fp:

    Code:
    DAR_NUM=4
    DAR_DENOM=3
    DAR = float(DAR_NUM) / float(DAR_DENOM)
    subtitle(string(DAR))
    Last edited by jagabo; 21st Feb 2017 at 16:02.
    Quote Quote  
  20. I understand what you've written but can't work out to make it work in the script at the moment. I'll try again later when I have more time and can tolerate another error message without punching the screen. Thanks.

    Edit: So eventually I got it to work by adding this line to the script:

    Float_Input_DAR = eval("1.0*" + Input_DAR)

    and changing the Input_DAR type to string, so 4/3 can be entered, but now all aspect ratios have to be entered with quotes. ie

    CropResize(Input_DAR="1.33333")

    Which seems to make the cure worse than the problem unless there's a better way I missing?
    Last edited by hello_hello; 22nd Feb 2017 at 06:35.
    Quote Quote  
  21. The use of a string type is to allow you to use integers within the string.

    Code:
    CropResize(Input_DAR="4/3")
    Then when you eval() it is handled as text:

    Code:
    Float_Input_DAR = eval("1.0*" + Input_DAR)
    The two strings are appended (via the + operator) to become:

    Code:
    Float_Input_DAR = eval("1.0*4/3")
    Since one of the values is floating point the whole operation is handled as floating point and the result is floating point. If you forget the quotes AviSynth will return an error -- so the mistake can be easily recognized and fixed.
    Quote Quote  
  22. At least I know how that works now, so I'm slowly learning. Cheers.

    I just can't decide whether having to use quotes in order to enter the aspect ratio would be less annoying than not having to use quotes but for an aspect ratio such as 4/3 to produce an incorrect output, which should be obvious.

    If it can be done, which I imagine it can be, I might try adding something that returns an error if the aspect ratio entered is integer. So 4.0/3.0 will work but 4/3 will produce an error, and then there won't be any quotes needed, cause I think that might annoy me more. Thanks.
    Last edited by hello_hello; 22nd Feb 2017 at 10:41. Reason: spelling
    Quote Quote  
  23. Originally Posted by hello_hello View Post
    If it can be done, which I imagine it can be, I might try adding something that returns an error if the aspect ratio entered is integer. So 4.0/3.0 will work but 4/3 will produce an error
    It cannot be done because the 4/3 is evaluated at the calling function, not the called function. The called function has no idea what string of text resulted in the value. So:

    Code:
    CropResize(Input_DAR=4/3)
    is converted to:

    Code:
    CropResize(Input_DAR=1)
    before CropResize() is called. CropResize() only sees

    Code:
    Input_DAR=1
    and has no idea how that 1 got there.
    Quote Quote  
  24. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    a "var" variable is undefined and can be anything. All he'd need to do is define "Output_DAR" as { var "Output_DAR" } instead of { float "Output_DAR" }, then he can test what it is using IsFloat, IsInt or IsString... he could even use IsClip if he just want to copy the DAR from one clip to anther... I'm not sure how he'd use IsBool though...
    Quote Quote  
  25. Avisynth can be torture.

    I thought this would work until I discovered IsFloat treats integer as float. I'm not sure what the logic behind that is.
    Assert(Input_DAR.IsFloat(),"Error")
    so an integer input isn't caught even when I define Input_DAR as integer and this still works instead of producing an error.
    CropResize(Input_DAR=1)

    When I added this instead (just for testing), it apparently assumed everything was float because Input_Dar is defined as float.
    Assert(Input_DAR.IsInt(),"Error")
    so even integer input results in "Error", which isn't what I expected.
    CropResize(Input_DAR=1)

    Defining Input_DAR as var doesn't seem to change any of that, so I'll have to find another way to tackle it.... or give up.
    Last edited by hello_hello; 22nd Feb 2017 at 15:27.
    Quote Quote  
  26. I changed some of the option names and their order to save some typing, so there'll be a newer version shortly (CropResize 2017-02-23).

    OutWidth was Out_Width
    OutDAR was Output_DAR
    Hmod was Height_Mod
    InDAR was Input_DAR
    Quote Quote  
  27. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    http://avisynth.nl/index.php/Internal_functions#IsFloat

    IsFloat(2) = true # ints are considered to be floats by this function
    Stupid thing.

    Unless you want to discount 2:1 and 1:1 resolutions (both of which are real things) there's no actual way of checking if someone tried to pass 4/3 other than by requesting a string.
    Quote Quote  
  28. Originally Posted by ndjamena View Post
    IsFloat(2) = true # ints are considered to be floats by this function
    That is strange, man. I think I found a workaround though:
    Code:
    function IsReallyFloat(val v)
    {
        s = ""
        try { 
            s = Hex(v) [* fails on float arguments! *]
        }
        catch(err_msg) { 
            s = "true"
        }
        return (IsFloat(v)) 
        \ ? (s=="true") [* s<>"true" if Hex succeeds *]
        \ : false       [* eliminate clips, strings, booleans  *]
    }
    Last edited by raffriff42; 22nd Feb 2017 at 18:18.
    Quote Quote  
  29. raffriff42,
    Thanks, but I think I'm going to need some instructions when it comes to adding that to the script. I'll come back to it a bit later when I'm over the 3417 error messages I've seen so far trying to get it to work, but I'm not 100% sure how to add a function to a function. It's probably easy once you know.
    Cheers.
    Quote Quote  
  30. Originally Posted by hello_hello View Post
    I'm not 100% sure how to add a function to a function. It's probably easy once you know.
    Just include the text of the new function in your script and call it when needed.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!