Log in

View Full Version : Appropriate YV12 to YUY2 conversion and back


Cary Knoop
10th August 2020, 07:41
What are the Vapoursynth equivalent YV12 to YUY2 conversions and back?

TheFluff
10th August 2020, 11:27
Do you mean actual interleaved YUY2 like in Avisynth, or just any old 4:2:2? I don't think VS (or zimg, rather) actually supports converting to the former. It has a format constant but it's one of the COMPAT ones that's only used for Avisynth interoperability. VS doesn't really support working with interleaved color formats in general, everything is planar internally and packing is only done for input or output.

feisty2
10th August 2020, 12:44
there's no appropriate way to convert between 4:2:0 and 4:2:2 because you have to resample Cb, Cr and that leads to quality loss, however, if your goal is to simply "get the shit done":


#to 422
clp = core.fmtc.resample(clp, css="422", kernel="point")

#to 420
clp = core.fmtc.resample(clp, css="420", kernel="point")

#"point" (nearest neighbor) is a true lossless resampling kernel, but it's pretty much useless if you want to apply literally any filtering on the resampled clip.

Cary Knoop
10th August 2020, 16:08
Do you mean actual interleaved YUY2 like in Avisynth
That's the one I mean.

What do you do if your source is already packed that way and you want to deinterlace?

_Al_
10th August 2020, 16:23
if you do:
#clip is some YUV420P8
clip2 = core.resize.Point(clip, format=vs.COMPATYUY2)
clip3 = core.resize.Point(clip2, format=vs.YUV420P8)
then all three clips are the same

COMPATYUY2 stores bytes as two byte packs interleaved as YU,YV,YU,YV, etc., you can check here (https://github.com/UniversalAl/view/blob/master/view.py#L1203)
What is the reason to use interleaved YUY2?

TheFluff
10th August 2020, 16:50
That's the one I mean.

What do you do if your source is already packed that way and you want to deinterlace?

Unpacking YUY2 to planar YUV422P8 is lossless. If you can't find a deinterlacer that supports YUV422P8 you could always upscale the chroma so you get YUV444P8 - that probably has at least slightly wider support.

I believe you can also re-pack YUV422P8 to YUY2 for output, or if that doesn't work you could as a last resort use v210, which is a wacky 10-bit interleaved YUV 4:2:2 thing mostly used by QuickTime and some other professional software. The VFW output does support that, although you need to do some mysterious incantation to enable it (can't remember off the top of my head).