Convert

From Avisynth wiki
(Redirected from ConvertToYV12)
Jump to: navigation, search

Convert between any of the color formats that AviSynth supports:

Color format Image format Chroma resolution
RGB24 interleaved 4:4:4 (full chroma)
RGB32 interleaved 4:4:4 (full chroma)
YV24 planar 4:4:4 (full chroma)
YV16 planar 4:2:2 (chroma shared between 2 pixels)
YUY2 interleaved 4:2:2 (chroma shared between 2 pixels)
YV12 planar 4:2:0 (chroma shared between 2x2 pixels) 
YV411 planar 4:1:1 (chroma shared between 4 pixels)
Y8 (both) 4:0:0 (no chroma)
(♦ = not supported in AviSynth version 2.58 or below)

When the target format is the same as the source format, the original clip will be returned unchanged, except for the case of ConvertToYV12 where the ChromaInPlacement and ChromaOutPlacement parameters are different.

There is no unique way of converting YUV to RGB or vice-versa. There are different conversion matrices in use; the two most common ones are available in AviSynth, namely Rec.601 and Rec.709, plus some others. The following should be correct in most cases (see here for more)

  • Rec.601 should be used when your source is standard definition (usually defined as smaller than 720p):
ConvertToRGB(clip) (using default "Rec601")
  • Rec.709 should be used when your source is DVD or HDTV:
ConvertToRGB(clip, matrix="Rec709")
  • The special-purpose matrices PC.601 and PC.709 keep the range unchanged,
instead of converting between 0-255 RGB and 16-235 YUV, as is the normal practice.
  • The special-purpose matrix AVERAGE is used for (rarely found) sources with unweighted luma,
where Y = (R + G + B) / 3.

Note ConvertToRGB always converts to RGB32 – unless your source is RGB24, in which case no conversion is done. If you need 24-bit RGB for some reason, use ConvertToRGB24 explicitly.

Use ConvertBackToYUY2 to convert back to YUY2 with minimal color-blurring when you have previously applied a YUY2→RGB conversion.

Contents

Syntax and Parameters

ConvertToRGB(clip [, string matrix, bool interlaced, string ChromaInPlacement, string chromaresample] )
ConvertToRGB24(clip [, string matrix, bool interlaced, string ChromaInPlacement, string chromaresample] )
ConvertToRGB32(clip [, string matrix, bool interlaced, string ChromaInPlacement, string chromaresample] )

ConvertToYV24(clip [, bool interlaced, string matrix, string ChromaInPlacement, string chromaresample] )
ConvertToYV16(clip [, bool interlaced, string matrix, string ChromaInPlacement, string chromaresample] )

ConvertToYUY2(clip [, bool interlaced, string matrix, string ChromaInPlacement, string chromaresample] )
ConvertToYV12(clip [, bool interlaced, string matrix, string ChromaInPlacement, string chromaresample, string ChromaOutPlacement] )

ConvertToYV411(clip [, bool interlaced, string matrix, string ChromaInPlacement, string chromaresample] )
ConvertToY8(clip [, string matrix] )

ConvertBackToYUY2(clip [, string matrix ] )


string  matrix = "Rec601"

Controls the colour coefficients and scaling factors used in RGB↔YUV conversions.
  • "Rec601" : Uses Rec.601 coefficients; scale full range [0..255] RGB to TV range [16..235] YUV, and vice versa.
  • "Rec709" : Uses Rec.709 coefficients; scale full range [0..255] RGB to TV range [16..235] YUV, and vice versa.
  • "PC.601" : Uses Rec.601 coefficients; keep range unchanged.
  • "PC.709" : Uses Rec.709 coefficients; keep range unchanged.
  • "AVERAGE" : Uses averaged coefficients (the luma becomes the average of the RGB channels); keep range unchanged.


bool  interlaced = false

If true, it is assumed that clip is interlaced; by default, it is assumed to be progressive.
This option is needed because for example, the following (assuming clip is interlaced YV12):
SeparateFields(clip)
ConvertToYUY2
Weave
...is upsampled incorrectly. Instead it is better to use:
ConvertToYUY2(clip, interlaced=true)
Note, interlaced=true has an effect only on YV12↔YUY2 or YV12↔RGB conversions. More about that can be found here.


string  ChromaInPlacement = "MPEG2"
string  ChromaOutPlacement = "MPEG2"

ChromaInPlacement determines the chroma placement in the clip when converting from YV12.
ChromaOutPlacement determines the chroma placement in the clip when converting to YV12.
The placement can be one of these strings:
"MPEG2"  Subsampling used in MPEG-2 4:2:x and most other formats. Chroma samples are located on the left pixel column of the group (default).
"MPEG1" Subsampling used in MPEG-1 4:2:0. Chroma samples are located on the center of each group of 4 pixels.
"DV" Like MPEG-2, but U and V channels are “co-sited” vertically: V on the top row, and U on the bottom row. For 4:1:1, chroma is located on the leftmost column.


string  chromaresample = "bicubic"

Determines which chroma resampler is used in the conversion. Only used when the chroma resolutions of the source and target are different. All AviSynth resizers are allowed ("point", "bilinear", "bicubic", "lanczos", "lanczos4", "blackman", "spline16", "spline36", "spline64", "gauss" and "sinc"). Default is "bicubic".


Notes

Conversion paths

In v2.60 the following conversion paths occur:
  • YUV planar → RGB via YV24
  • YUV planar → YUY2 via YV16
(except for YV12 and chroma options listed above not explicitly set; in that case there is a direct conversion from YV12 to YUY2)
  • RGB → YUV planar via YV24
  • YUY2 → YUV planar via YV16
(except for YV12 and chroma options listed above not explicitly set; in that case there is a direct conversion from YUY2 to YV12)
The chroma options chromaresample, ChromaInPlacement and ChromaOutPlacement are only used in the 'planar conversion' part of the conversion path.
Suppose you have a YUY2 clip for example and you convert it to YV24. The YUY2 will be converted to YV16 first without applying the chroma options. Then YV16 will be converted to YV24 while applying chromaresample. Since YV12 is not involved, ChromaInPlacement and ChromaOutPlacement won't be used.

Sampling

This page covers the sampling methods and color formats in more detail.

Color conversions

This page covers the color conversions in more detail.


Changelog

v2.60 Added ConvertToY8, ConvertToYV411, ConvertToYV16, ConvertToYV24, ChromaInPlacement, ChromaOutPlacement, chromaresample, matrix="AVERAGE".
v2.50 Added ConvertToYV12.
Personal tools