YV12 - RGB conversion
September 20, 2010
As mentioned two posts earlier, in version 1.9.4 of
Video Enhancer we added YV12 mode of super
resolution engine. Most video codecs can decode video to several different
uncompressed formats: RGB24, RGB32, YV12, UYVY, YUY2 etc. They differ in
colorspace (red-green-blue or luminosity-color tone1-color tone2)
and data layout. Versions up to 1.9.3 just asked the decoder to provide data
in RGB32 and relied on DirectShow (part of DirectX) and system components to
convert video to RGB32 in case the decoder cannot do it itself. When version
1.9.4 came out it behave differently. It asked the decoder to provide one of
YV12, YUY2, RGB24 and RGB32 formats. If YV12 was given and super resolution
feature was used (either alone or in the beginning of filters sequence)
then YV12 mode of SR was used and then if some VirtualDub filters were
present in the queue, VE relied again on system converters to transform video
from YV12 to RGB32 (in which VD filters work). The same happened when
"Always use RGB32" option was turned on: decoder provided video in one of
abovementioned formats and then a system converter was used.
However it turns out there were
two problems:
- By default there is no system filter for YV12-RGB conversion, so DirectShow
searches for a codec for this conversion. Usually it finds one of old
Video-for-Windows codecs and inserts it in AVI Decompressor wrapper but
some users didn't have a matching codec and VE failed to process a file.
I still don't know which codec exactly was used,
but it had problem number two:
- Conversion from YV12 to RGB was weird, introducing a checkerboard pattern
which was very bad for super resolution. When looking at result of such
conversion one may not notice the problem:
But if we upsize the video it's easy to see the pattern:
So we had to change how VE works with YV12 video and version 1.9.5 was born.
Now it asks the decoder for any of YV12, YUY2, UYVY, RGB24 and RGB32 formats
and if it's YV12 then SR works in fast YV12 mode but if it's anything else
then our own filter converts video to RGB32. The same filter is used for
conversion if after YV12 SR there is some VD filter. No more checkerboard
and no more problems with lack of YV12 codec!
Video quality was the
primary objective for this conversion filter, so it uses proper interpolation
for color tone components (remember that in YV12 color tone resolution is
twice lower in both width and height than in RGB, and in YUY2 and UYVY it's
twice lower in width than RGB but same in height). Bad converter with no
interpolcaion can easily create little blocking artifacts. Here's an example:
Old converter (some codec wrapped in AVI Decompressor):
New built-in converter in Video Enhancer 1.9.5:
(both pictures magnified 3 times).
tags: video_enhancer
|