Page 1 of 1

Calculating Crop/Pad Values for the Video Resize Editor

Posted: Tue Jun 02, 2009 10:51 pm
by ckhouston
Introduction

There have been a few forum requests for ways to accurately determine values for the number of pixels to pad or crop videos to obtain specific results without causing distortion. Equations are presented below for several different objectives. They can be used for ConvertXtoDVD, ConvertXtoHD, and ConvertXtoVideo.

Some have complained that the equations are too difficult to use. They are algebraic equations that simply need the appropriate values substituted in them. Using these equations is much simpler and less prone to errors than the standard multi-step, reasoned but sometimes intuitive, procedure that is often used.

Equation variables are:

CHP (Cropped Horizontal Pixels) ~ the number of horizontal pixels cropped from the sides
CVP (Cropped Vertical Pixels) ~ the number of vertical pixels cropped from top and bottom
PHP (Padded Horizontal Pixels) ~ the number of horizontal pixels padded on the sides
PVP (Padded Vertical Pixels) ~ the number of vertical pixels padded on top and bottom
THP (Target Horizontal Pixels) ~ the number of horizontal pixels to be converted to (720 for FullD1 resolution for example) - See Note 1
TVP (Target Vertical Pixels) ~ the number of vertical pixels to be converted to (480 NTSC or 576 PAL for FullD1 for example) - See Note 1
SHP (Source Horizontal Pixels) ~ the number of horizontal pixels in the source (the file being converted) - see Note 1
SVP (Source Vertical Pixels) ~ the number of vertical pixels in the source (the file being converted) - see Note 1
TAR (Target Aspect Ratio) ~ the aspect ratio to be converted to, either 4:3 = 1.333 or 16:9 = 1.778, chosen at top of editor
SAR (Source Aspect Ratio) ~ the aspect ratio of the source, the file you are converting in other words - see Note 1


Note 1: The simplest way to determine values of those last six variables is illustrated in the attached image below. Start the conversion, pause it after a few seconds, open the conversion log, find lines similar to those shown in the image, determine values as illustrated, then either resume conversion if no changes are needed or cancel if you want to make changes before final conversion.

Note 2: The aspect ratio used herein is the physical width divided by the physical height. The aspect ratio is equal to the ratio of horizontal to vertical pixels only if square pixels are used in a video. Some source files do have square pixels while others do not, the DVD target always uses non-square pixels.

Note 3: The equations presume symmetric padding and cropping with values given for a single edge -- check the Symmetric Pad/Crop box in the editor. Asymmetric pad/crops can also be done by unchecking that box and making sure the average of the unequal values on opposite edges is equal to the value given by the equations.

Note 4: The equations also presume that any pad/crop value not used in the equation is zero, be sure to check -- see red part of Note 6. For example, only PVP and CHP are used in equation 3] so values for PHP and CVP must be set to zero in the edit window in order to get valid results. Then set the pad/crop value (CHP, CVP, PHP, or PVP) on the right side of the equation, substitute values for other variables, and calculate the value on the left.

Note 5: Cropping/padding should always be done to even number values (end with a 0, 2, 4, 6, or 8 ). Calculated values should therefore be rounded to the nearest even number.

Note 6: The Stretch option sets all crop and pad values to zero, it stretches the picture to fit the screen in other words. It is useful in rare cases where the source file actually has an aspect ratio of either 4:3 or 16:9 but the file header specifies some other incorrect aspect which confuses the conversion program -- see the Standard Stretch Option section below. It can also be used to quickly set pad and crop values to zero as a starting point for custom resizing. Get into the habit of doing that because pad/crop values are not automatically reset to zero when switching from another option to User Defined.


Several options are presented below including the standard ones that can be selected in the resize editor. The appropriate equation to use for each option is determined by whether SAR is less than or greater than TAR (either variation of the equations can be used if SAR is equal to TAR). Note that there is an additional restriction on how much one can choose to crop or pad in equations 3] through 6].

The pad and crop values shown on the right side of equations 1] through 8] must be chosen by the user before the calculation can be made. In some cases where it is more convenient to choose values on the left side first, the equation can be solved for the variable on the right in terms of the one on the left. For example, suppose equation 7] is to be used but you want to choose CHP first and then solve for the appropriate value of CVP to use. Solving that equation for CVP gives

CVP = {CHP - (SHP/2) x [1- (TAR/SAR)]} / [(TAR/SAR) x (SHP/SVP)]

All other variables on the right side of the equations are determined as explained above. An example is given in the Using the Equations section at the end of this post.


Pad All Edges

This might be done to provide small black borders so no part of the picture will be cut by TV overscan, or to reduce the picture size for special effect as is sometimes done in commercial DVDs. The appropriate equations are

1] PVP = (TVP/2) x [1 - (TAR/SAR) x (1 - 2 x PHP/THP)] for SAR > TAR

or

2] PHP = (THP/2) x [1 - (SAR/TAR) x (1 - 2 x PVP/TVP)] for SAR < TAR


Crop Opposite Edges then Pad the Other Two Edges

This is similar to what the Automatic resize option does but can be used with more general values. The equations are

3] PVP = (TVP/2) x [1 - (TAR/SAR) / (1 - 2 x CHP/THP)] for SAR > TAR and CHP < (THP/2) x (1 - TAR/SAR)

or

4] PHP = (THP/2) x [1 - (SAR/TAR) / (1 - 2 x CVP/TVP)] for SAR < TAR and CVP < (TVP/2) x (1 - SAR/TAR)


Pad Opposite Edges then Crop Other Two Edges

This is a variation of the option above. The equations are

5] CHP = (THP/2) x [1 - (TAR/SAR) / (1 - 2 x PVP/TVP)] for SAR > TAR and PVP < (TVP/2) x (1 - TAR/SAR)

or

6] CVP = (TVP/2) x [1 - (SAR/TAR) / (1 - 2 x PHP/THP)] for SAR < TAR and PHP < (THP/2) x (1 - SAR/TAR)


Crop All Edges

This might be done to zoom the video image or to eliminate part of the outer edges for some reason.

7] CHP = (SHP/2) x [1 - (TAR/SAR)] + (TAR/SAR) x (SHP/SVP) x CVP for SAR > TAR and vertical cropping done first

or CVP = {CHP - (SHP/2) x [1- (TAR/SAR)]} / [(TAR/SAR) x (SHP/SVP)] for SAR > TAR and horizontal cropping done first


or

8] CVP = (SVP/2) x [1 - (SAR/TAR)] + (SAR/TAR) x (SVP/SHP) x CHP for SAR < TAR and horizontal cropping done first

or CHP = {CVP - (SVP/2) x [1 - (SAR/TAR)]} / [(SAR/TAR) x (SVP/SHP)] for SAR < TAR and vertical cropping done first


Standard Letterbox Option

This is the recommended option for most projects. It adds padding (black bars) to part of the image in order to change the aspect of the source to the chosen DVD aspect.

Equations obtained by setting pad values on right side of equations 1] and 2] to zero

9] PVP = (TVP/2) x [1 - (TAR/SAR)] for SAR > TAR

or

10] PHP = (THP/2) x [1 - (SAR/TAR)] for SAR < TAR


Standard Pan-Scan Option

This option crops part of the image in order to change the aspect of the source to the chosen DVD aspect.

Equations obtained by setting pad values on right side of equations 5] and 6] to zero

11] CHP = (THP/2) x [1 - (TAR/SAR)] for SAR > TAR

or

12] CVP = (TVP/2) x [1 - (SAR/TAR)] for SAR < TAR


Standard Automatic Resize Option

This is a compromise between the Letterbox and Pan-Scan options. It crops part of the image and also adds padding in order to change the aspect of the source to the chosen DVD aspect.

Calculate Pan-Scan crop values from equation 11] or 12], divide by 2 and round to nearest even number, then use that crop value to calculate the amount to pad from equations 3] or 4].


Standard Stretch Option

This option is intended to correct badly encoded source files that were erroneously encoded to a 16:9 aspect when it should have been 4:3 or encoded to 4:3 when it should have been 16:9. It does not crop or pad, it merely changes the aspect, distorting the image in the process. Converting a 16:9 source to 4:3 will stretch the image vertically (make objects slimmer) when using this option. Converting a 4:3 source to 16:9 will stretch the image sideways (make objects fatter) if this option is used.


Using the Equations

As an example, suppose your SAR > TAR and you want to pad all edges, you would use equation 1]. Since PHP (meaning pad the sides) is on the right side of the equation, you will set its value first by padding the sides as much as you want in the editor. You might want to pad the sides by say 6% to account for TV overscan. If you are converting to typical FullD1 resolution, you would then pad the sides by PHP = 0.06 x 720 = 43.2 or 44 when rounded to the nearest even number. Then substitute that value into equation 1] to calculate PVP, the amount to pad top and bottom. Remember to use 480 for TVP in the equation if you convert to NTSC or 576 for PAL and FullD1 resolution.