VideoHelp Forum




+ Reply to Thread
Results 1 to 9 of 9
  1. Member
    Join Date
    Jul 2007
    Location
    United States
    Search Comp PM
    Hi everyone,

    I have been trying to figure out a script that will allow me to autoresize an image using AviSynth.
    The objective is to create menus or slideshows for DVD's. This is what I have so far... but doesn't work!

    ImageSource(file="C:\********.jpg") #Reads my image
    ow=last.width #gets image original width
    oh=last.height #gets image original height
    nw=int(round(452/oh)*ow) #computes new width, based on a height of 452
    LanczosResize(nw,452)

    Example: The image originally is 455x600. The new size should be, (452/600)*455) = 343 pixels width. So output should be an image 343x452. But I get error message: Resize: Width must be bigger than or equal to 8.

    Help !
    Quote Quote  
  2. Member Soopafresh's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    Yup, for video, your dimensions must be multiples of 8, preferably 16
    Quote Quote  
  3. Member
    Join Date
    Mar 2007
    Location
    United Kingdom
    Search Comp PM
    shudnt the size be dividable by 8 or 16?

    EDIT: Posted at the same time :P
    Quote Quote  
  4. I believe the frame dimensions are integers so multiply before dividing. From your code:

    nw = int(round(452/oh)*ow) = int(round(452/600)*455) = int(round(0)*455) = 0

    Try on of these:

    nw=452*ow/oh #may not work for YUY2 or YV12
    nw=(452*ow/oh+2)/4*4 #for nearest mod 4 frame size
    nw=(452*ow/oh+4)/8*8 #for nearest mod 8 frame size
    nw=(452*ow/oh+8)/16*16 #for nearest mod 16 frame size
    Quote Quote  
  5. Member
    Join Date
    Jul 2007
    Location
    United States
    Search Comp PM
    Originally Posted by jagabo
    I believe the frame dimensions are integers so multiply before dividing. From your code:

    nw = int(round(452/oh)*ow) = int(round(452/600)*455) = int(round(0)*455) = 0

    Try on of these:

    nw=452*ow/oh #may not work for YUY2 or YV12
    nw=(452*ow/oh+2)/4*4 #for nearest mod 4 frame size
    nw=(452*ow/oh+4)/8*8 #for nearest mod 8 frame size
    nw=(452*ow/oh+8 )/16*16 #for nearest mod 16 frame size
    Thank you Jagabo! The first line works for me. Now I just fave to figure how to create a autoBorder using AddBorders. The output should be a 720x480, which the height will be given but for the width I have to use IF conditions. Then whatever value I would get has to be divided by 2, for equal distribution. Something that I need to learn.
    Quote Quote  
  6. I suspected the question of border sizes would come up next!

    Without accounting for aspect ratio corrections:

    lb = (704-nw)/2 #size of left border
    rb = 704-nw-lb #size of right border
    addborders(lb, 14, rb, 14)

    But if you're making a DVD you need to correct for the aspect ratio. Aspect ratio has to be taken into account in the resizing too. I'll have to think about it a bit...
    Quote Quote  
  7. Member
    Join Date
    Jul 2007
    Location
    United States
    Search Comp PM
    Hi Jagabo!
    If is not too much already, would you please help me with Aspect Ratios (AR). I'm using DVDLab Pro 1.?? I know that DVDLab takes cares of ARs but the reason for finding a script was to polish the picture. That is, denoising and sharping it and trying to give them a homogeneous size.
    Thanks for the prior code...
    Quote Quote  
  8. OK, I'm not real familiar with AVISynth syntax but I've come up with this:

    Code:
    function PadHeight(clip image, int width, int height, int AR_WIDTH, int AR_HEIGHT)
    {
    	# the frame is wider than we want, pad the top and bottom
    
    	# calculate what final height we need
    	nh = width * AR_HEIGHT / AR_WIDTH
    
    	# calculate the top and bottom borders
    	tb = (nh - height) / 2
    	bb = nh - height - tb
    	AddBorders(image, 0, tb, 0, bb)
    }
    
    function PadWidth(clip image, int width, int height, int AR_WIDTH, int AR_HEIGHT)
    {
    	# the frame is taller than we want, pad the left and right
    
    	# calculate the final width we need
    	nw = height * AR_WIDTH / AR_HEIGHT
    
    	# calculate the left and right borders
    	lb = (nw - width) / 2
    	rb = nw - width - lb
    	AddBorders(image, lb, 0, rb, 0)
    }
    
    
    ImageSource("E:\VCR\AVS\AutoResize.jpg")
    
    # if you want 16:9 change these values to 16 and 9
    AR_WIDTH = 4
    AR_HEIGHT = 3
    
    width = last.width
    height = last.height
    
    ((width * AR_HEIGHT) > (height * AR_WIDTH)) \
       ? PadHeight(last, width, height, AR_WIDTH, AR_HEIGHT)\
       : PadWidth(last, width, height, AR_WIDTH, AR_HEIGHT)
    
    # the frame is now padded to the correct square pixel aspect ratio
    
    # resize for DVD
    LanczosResize(704, 480)
    AddBorders(8, 0, 8, 0) #optional
    That doesn't account for the overscan compensation you had in mind. You can just change the LanczosResize() and AddBorders() to fix that.

    LanczosResize(664, 452)
    AddBorders(28, 14, 28, 14)

    Or even better (everything mod 16):

    LanczosResize(656, 448)
    AddBorders(32, 16, 32, 16)

    Note that the above script won't work for certain frame sizes in YUY2 and YV12.
    Quote Quote  
  9. Member
    Join Date
    Jul 2007
    Location
    United States
    Search Comp PM
    Thanks Jagabo!
    Well the original autoresize works by making the picture height 452 and addborders(0, 14, 0, 14) for 480. DvdLab will do the rest in terms of aspect ratio.
    Quote Quote  



Similar Threads

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