View Full Version : how to color correctly convert RGB > YV12
pancserzso
24th December 2006, 04:07
I would like to encode a sequence of RGB images (tiff, tga, png) using megui/xvid.
I'm using that script now, which annoyingly changes the colors when I add the ConvertToYV12() line.
ImageSource("s2bc%04d.tga", 0000, 0104, 25)
FlipVertical
ConvertToYV12()
How could I convert the colorspace to YV12 while preserving the original RGB colors?
foxyshadis
24th December 2006, 04:37
Try one of the other matrices. They're listed in the avisynth manual. (bt.601, pc.601, bt.709, pc.709, I think.)
To find out if it's just the unavoidable YV12 color averaging, immediately follow converttoyv12 with converttorgb and compare. That's the best conversion quality you can get with YV12.
sh0dan
24th December 2006, 16:11
You shouldn't observe a color difference, unless you use an overlay based player. Open the script or xvid in vdub and the colors should be exactly as your images.
It is probably your player or graphic driver settings that changes the look of the images.
Trixter
26th December 2006, 04:10
How could I convert the colorspace to YV12 while preserving the original RGB colors?
I ran into this trying to convert RGB sources to MPEG-2. If you don't want any colorspace range conversion (ie. keep 0-255 RGB --> 0-255 YUV as much as precision allows), use the PC.601 matrix, like this:
ConvertToYUY2(matrix="PC.601")
Note that, due to the loss of precision with an 8-bit-per-channel workspace, the colors will change anyway, but at least they won't be sqeezed into a different range.
However, be sure that's what you want. Due to the larger precision in my MPEG-2 encoder (when using a 10-bit DCT), I opted to keep things in the larger range because I knew I could count on my MPEG-2 encoder to do the final range conversion properly. For example, here's a PAL->NTSC transcoding script I used for my last project (note the use of the PC.601 matrix during colorspace conversions):
import("d:\program files\avisynth 2.5\plugins\mvbob\mvbob.avs")
AVISource("\assets\mc2\pal\mentalhangover.avi")
ConvertToYUY2(matrix="PC.601",interlaced=true)
AssumeTFF
mvbob
ConvertMCfps
Lanczos4Resize(720, 480)
ConvertToRGB(matrix="PC.601",interlaced=true)
AssumeFrameBased
SeparateFields() # Turn 60p into 30i (this line and next)
SelectEvery(4, 0, 3) # 4,1,2 is for odd field first; 4,0,3 is for even field first
weave
AddBorders(0,2,0,4) # we have to pad to 486 lines by adding 2 at top and 4 at bottom
bananacreamandpeca
28th December 2006, 04:31
Isn't there a FAQ that stresses/talk about these color-space changes?
I don't understand any of it.
So what trixter says is, you can keep colors as acurate as possible with this matrix (same matrice usable for x264?)
cuz changing of colors is inevitable.
But he doesnt bother with this, cuz he knows the player will do another conversion the right way upon playback.
wich changes the RGB-YV12 back to ->RGB again.
But he has this script that allows you to keep colors without much overly change???
Why I even bother coming beck here at doom9
Trixter
28th December 2006, 07:07
No, that's not what I wrote.
The accepted valid range for YUV in the digital domain is luminance levels from 16 to 235. For RGB, we all know it's 0-255. So when you convert RGB to YUV, the default matrix in avisynth will squeeze the values to the 16-235 range.
Since I was going from RGB to YUV for processing, then back to RGB again, the range conversion was affecting things visibly. So I chose the other matrix, where the range is not affected. You still need to convert to the 16-235 range for DVD (my output target for that project), but I knew that my mpeg-2 encoder could do this with more precision than avisynth. So by choosing the PC.601 matrix, no range adjustment was done.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.