Log in

View Full Version : Color format conversion, Audio process


vcmohan
12th March 2004, 03:42
While trying to Author some effects and transitions I ran into some doubts/problems
1. In a transition I do not attempt to process Audio at all. However I return back the child frame,or a second clip frame or a work area frame. In each of these cases which Audio is retained? I was under the impression that in the first case the child audio , in second case the second clip audio and in the third case a blank audio will be present. Is this correct?
2. For converting RGB color value to YUY2 format what is the conversion algorthm? I am sure that somewhere on the web this info may be present but pl bear with me.

Mug Funky
12th March 2004, 05:47
i believe there's a table of "multi-clip" functions in the avisynth docs that explains what properties of which clips are inherited.

as for colour interpolations, i think it's done with linear interpolation, except in the case of overlay() which converts everything to yuv 4:4:4 with nearest-neighboring. i could be wrong...

vcmohan
15th March 2004, 04:10
Originally posted by Mug Funky
i believe there's a table of "multi-clip" functions in the avisynth docs that explains what properties of which clips are inherited.
I tried quite some time with the documentation but failed to get to a place where such a table is available. Can you possibly help me with the exact link?

as for colour interpolations, i think it's done with linear interpolation, except in the case of overlay() which converts everything to yuv 4:4:4 with nearest-neighboring. i could be wrong...

I just want to know if R,G,B values are known for a pixel what are its Y, U, V values?

stickboy
15th March 2004, 05:04
Originally posted by vcmohan:
I tried quite some time with the documentation but failed to get to a place where such a table is available. Can you possibly help me with the exact link?I think Mug Funky was referring to the documentation bundled with the AviSynth binaries, under Getting Started > Multi-Clip Functions.

But I don't think that really helps you; it only explains what other multi-clip functions choose to do.
I just want to know if R,G,B values are known for a pixel what are its Y, U, V values?http://www.google.com/search?q=rgb+yuv+conversion

The first link gives some formulas. (Note that it doesn't account for CCIR-601 limits, though.) It would be nice if some inline conversion functions were added to avisynth.h so that if plug-in authors need to perform such conversions that they're consistent...

BTW, you should ask in the AviSynth Development forum, not AviSynth Usage.

trevlac
15th March 2004, 14:10
On color conversions.....

Be aware that there are many variations in how this is done (in various software). Poynton is a good source for well accepted formulas (http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC30). However, to know exactly what a specific Avisynth ConvertToX does, you should read the source.

vcmohan
16th March 2004, 03:14
Thanks to stickboy and trevlac for the information. I have now posted my querry regarding inheritance of audio in the development section

Richard Berg
16th March 2004, 12:48
/*****************************************************
******* Colorspace Single-Byte Conversions ******
****************************************************/


inline void YUV2RGB(int y, int u, int v, BYTE* out)
{
const int crv = int(1.596*65536+0.5);
const int cgv = int(0.813*65536+0.5);
const int cgu = int(0.391*65536+0.5);
const int cbu = int(2.018*65536+0.5);

int scaled_y = (y - 16) * int((255.0/219.0)*65536+0.5);

_PixelClip PixelClip;

out[0] = ScaledPixelClip(scaled_y + (u-128) * cbu); // blue
out[1] = ScaledPixelClip(scaled_y - (u-128) * cgu - (v-128) * cgv); // green
out[2] = ScaledPixelClip(scaled_y + (v-128) * crv); // red
}


// not used here, but useful to other filters
inline int RGB2YUV(int rgb)
{
const int cyb = int(0.114*219/255*65536+0.5);
const int cyg = int(0.587*219/255*65536+0.5);
const int cyr = int(0.299*219/255*65536+0.5);

_PixelClip PixelClip;

// y can't overflow
int y = (cyb*(rgb&255) + cyg*((rgb>>8)&255) + cyr*((rgb>>16)&255) + 0x108000) >> 16;
int scaled_y = (y - 16) * int(255.0/219.0*65536+0.5);
int b_y = ((rgb&255) << 16) - scaled_y;
int u = ScaledPixelClip((b_y >> 10) * int(1/2.018*1024+0.5) + 0x800000);
int r_y = (rgb & 0xFF0000) - scaled_y;
int v = ScaledPixelClip((r_y >> 10) * int(1/1.596*1024+0.5) + 0x800000);
return (y*256+u)*256+v;
}

When converting entire frames there are much faster algorithms in the code (mostly MMX) but these should give the correct formulas.

I think sh0dan already answered your audio question.

stickboy
16th March 2004, 20:43
Those functions currently are in convert.h and use ScaledPixelClip from internal.h, neither of which is covered by the special-exception-to-the-GPL clause in the AviSynth license.

I assume those functions were originally written by BRG? Any idea if he'd be willing to grant exception to those functions too?

scmccarthy
18th March 2004, 01:13
The above values for crv, cgv, cgu, and cbu would be more accurately computed by: const int crv = int(1.59603*65536+0.5);
const int cgv = int(0.81297*65536+0.5);
const int cgu = int(0.39177*65536+0.5);
const int cbu = int(2.01723*65536+0.5);
Based on: const int crv = int(0.701*255/112*65536+0.5);
const int cgv = int(0.701*.299/.587*255/112*65536+0.5);
const int cgu = int(0.886*.114/.587*255/112*65536+0.5);
const int cbu = int(0.886*255/112*65536+0.5);
Stephen

Richard Berg
19th March 2004, 10:36
I don't think we have any moral obstacles to putting RGB2YUV declarations in avisynth.h. (I doubt it's even copyrightable, actually, being just a formula from a book.)

What other helper functions should we provide? ApplyMessage from text-overlay.h is rather nice, for instance.

sh0dan
19th March 2004, 10:52
... but they would require either the actual code or avisynth.lib to compile.

In general no. The code was written under GPL, and should remain as such. The exception allows you to write non-GPL plugins, and use AviSynth dll interfaces from closed source software. It does not cover using code from various places.

You are allowed to use the AlignPlanar, FillBorder and ConvertAudio classes. They are defined in avisynth.h, but the actual code is somewhere else (for some silly reason - I'm moving it to a separate file soon).

Richard Berg
19th March 2004, 11:17
I think stickboy's point was convenience, since GPL authors can just copy the code if they really wanted. (Don't you already have to link against avisynth.lib if you use ConvertAudio?)

sh0dan
19th March 2004, 11:43
Originally posted by Richard Berg
(Don't you already have to link against avisynth.lib if you use ConvertAudio?)
Yes - and that's why I'd like to simply supply the needed classes in a .cpp file that could simply be included in the project.

stickboy
23rd May 2004, 00:32
I asked BenRG what his opinion was about moving some of the color conversion functions (RGB2YUV, YUV2RGB) into avisynth.h (or into a file that's given a similar exception to the GPL) for convenience and consistency to plug-in authors.

He said that if that's what the AviSynth community wants, he's perfectly fine with it.

vcmohan
23rd May 2004, 04:44
Is there some problem with message alert system? After 16th March only today I got the alert.

It will be a very good Idea to keep the color convert functions in the Avisynth.h.

I also found some unsatisfactory results. If all white RGB of ffffff
converted to YUV , becomes 255, 0, 0 when displayed in YUY2 format gives a color on my screen.

Wilbert
23rd May 2004, 13:15
I also found some unsatisfactory results. If all white RGB of ffffff
converted to YUV, becomes 255, 0, 0 when displayed in YUY2 format gives a color on my screen.
White RGB should become (235,128,128) when converting to YUV. So, I'm not sure what you mean here?

vcmohan
24th May 2004, 03:42
sorry my mistake. I used some formula but probably missed out on some plus values and used. Thanks for correcting me