Skip to content

videofilt_aspectratio

shekh edited this page Apr 15, 2018 · 1 revision

VirtualDub Plugin SDK 1.2

Handling aspect ratio

V13 or earlier: Aspect ratio support is only available starting with API V14.

Starting with API V14, source and output streams are tagged with a fraction indicating the pixel aspect ratio of video frames. This indicates whenever the pixels are non-square.

In general, most video processing algorithms aren't affected by aspect ratios, but in some cases it can be useful. For instance, aspect ratio information can be used to ensure that text is not rendered squished or stretched.

Reading and controlling the pixel aspect ratio

The pixel aspect ratio (PAR) is indicated by the mAspectRatioHi and mAspectRatioLo fields of the VDXFBitmap structure. The ratio of these two is the PAR, with ratios above one indicating a pixel that is wider than it is tall. If the fraction is 0/0, it means that the pixel aspect ratio is unknown. In that case, your filter should assume square pixels (1:1).

To change the PAR, the filter should modify the aspect ratio fields on the fa->dst bitmap in its paramProc method. Note that changing the aspect ratio does not actually change any of the video data, so this should only be used to indicate a true change in aspect. It should not, for example, be used to cheaply stretch video horizontally.

Pixel aspect ratios for YCbCr video

In cases where the video images are composed of multiple size pixels, such as the luma and chroma planes of YCbCr-encoded video, the PAR is described for the luma plane. A conversion between formats with different color spaces or chroma subsampling ratios does not alter the PAR.

Frame aspect ratio vs. pixel aspect ratio

Sometimes aspect ratios are described in terms of the frame rather than each pixel. Widescreen, for example, is described as 16:9 regardless of the resolution of the image. The video filter API does not encode the frame aspect ratio directly and it is implicit based on the frame resolution and the PAR:

frame_aspect_ratio = pixel_aspect_ratio * width / height

For instance, a video stream with a PAR of 8/9 and a resolution of 720x480 has a frame aspect ratio of 4/3 (4:3).

How aspect ratio is used (VirtualDub specific)

In VirtualDub, the aspect ratio indicated at the end of the filter chain is used to correct the display width. The user can override this, but one of the options on the aspect ratio menu of the display panes is to use the reported aspect ratio.

Note that AVI does not generally support specifying aspect ratios. Some video decoders report aspect ratio based on information in the encoded video stream, but there is no general mechanism for doing so or for controlling this through the encoding API. Therefore, video that emerges with a pixel aspect ratio (PAR) other than 1:1 will have its aspect ratio reset when written to AVI unless another filter is used to correct the PAR by resampling the image and changing the resolution to compensate.


Copyright (C) 2007-2012 Avery Lee.

Clone this wiki locally