Log in

View Full Version : Crop and Recalculate Resize Dimensions


MysteryX
10th December 2014, 18:39
I have VCD videos in 352x288 format with a DAR of 4:3 and PAR of 12:11

I currently do something like this which works great

smoothD2c(12, ncpu=4)
eedi3_rpow2 (2)
nnedi3_rpow2 (2)
Spline36Resize(960, 720)

Now, what if I want to crop black borders in the video? I could add this: Crop(2,40,-2,-40)

Problem is that the Resize width won't be 960 anymore. I would need to calculate the proper width based on crop settings.

What would be the best way to
1) facilitate finding which crop settings are valid (it says it must be dividable by 4)
2) calculate the proper width for the resize function

Asmodian
10th December 2014, 20:07
SAR × PAR = DAR

352/288 * 12/11 = 4/3
720 * (4/3) = 960

Plug in the new numbers for resolution. Take the new DAR and multiply it by 720. (edit: round to the closest even number)

SAR = signal aspect ratio
PAR = pixel aspect ratio
DAR = display aspect ratio

hello_hello
10th December 2014, 20:10
Try the Yoda Resize Calculator (http://www.mediafire.com/download/09v9bldu9a6hm00/YodaResizeCalculator.exe). It's an exe but it's safe. You set the input resolution and/or aspect ratio along with your desired cropping and resizing, and It'll calculate the aspect ratio distortion for you. I just fiddle with the cropping and/or resizing a bit until the distortion is at a minimum. Sometimes keeping it close to zero means cropping a few pixels from the picture somewhere.
According to the calculator you could resize to 960x526 after the cropping you specified.

The calculator will apply mod1 cropping, but the AVIsynth crop function works in increments of two. If you're like me, and a little OCD at times, you can use the resize filter to apply extra mod1 cropping to the video (in case you weren't aware). If, for example (I'm just making up numbers at the moment), ideally you'd like to reduce the aspect ratio distortion by cropping 3 pixels from the left instead of 2, and 41 from the bottom rather than 40, you can do it this way:

Crop(2,40,-2,-40)
Spline36Resize(960,526,1,0,0,-1)

Although if you're cropping first, then upscaling with nnedi3 and resizing, don't forget to account for the upscaling if you use the resize filter to crop. I'm a bit silly and it tends to confuse me, but if you double the size of the video after the initial cropping, then you'd need to double any resize filter cropping too. So to crop the original video by 3 pixels left, and 2 right, 40 top and 41 bottom, you'd need to do it like this if nnedi3_rpow2 (2) is in the middle.

Crop(2,40,-2,-40)
nnedi3_rpow2 (2)
Spline36Resize(960,526,2,0,0,-2)

MysteryX
10th December 2014, 21:40
I designed this cropping script that works pretty well


SrcHeight = 288
SrcWidth = 352
SrcAR = 12 / 11
# Source cropping (must divide by 4)
CropLeft = 6
CropTop = 2
CropRight = 2
CropBottom = 2
# Output cropping (pixel-precision)
Crop2Left = 2
Crop2Top = 8
Crop2Right = 6
Crop2Bottom = 4
CropHeight = ((SrcHeight - CropTop - CropBottom) * 4) - Crop2Top - Crop2Bottom
CropWidth = ((SrcWidth - CropLeft - CropRight) * 4) - Crop2Left - Crop2Right
ResizeHeight = 720
ResizeWidth = Round(Float(CropWidth) * SrcAR / CropHeight * ResizeHeight / 2) * 2

Crop(CropLeft, CropTop, -CropRight, -CropBottom)
smoothD2c(12, ncpu=4)
eedi3_rpow2 (2)
nnedi3_rpow2 (2)
Spline36Resize(ResizeWidth, ResizeHeight, Crop2Left, Crop2Top, -Crop2Right, -Crop2Bottom)

Although doing cropping at the end could do the job by itself, cropping first increases performance.

Can there be any quality impact to doing resizing in such a way?

StainlessS
10th December 2014, 21:48
Do not crop before Deblock (which I think smoothD2c is doing).

EDIT: Deblock-ing relies upon block boundaries being at known positions, cropping will change that
and negatively impact results (unless all cropping done in multiples of block size, both H & V).
Better to leave out deblocking altogether than deblock in wrong position, making things worse.

MysteryX
10th December 2014, 21:52
Do not crop before Deblock (which I think smoothD2c is doing).
Oh thanks! I thought blocking was pretty bad, hence my question about quality.