On Sat, 05 Apr 2008 06:32:12 -0500, Vicente Soriano  
<[EMAIL PROTECTED]> wrote:
> Hi!
> I'm trying to make a program that changes the color of
> some pixels by another pixels (pixels from another video
> file, aka BlueScreening). I have started to use the
> libavcodec functions, but i cannot access to the color
> of the pixels. I guess it is in the "data" var of the "AVFrame"
> struct, but, i don't know how to change the value.

AVFrame->data *does* contain the pixel data, but reading this data depends  
on the Format of the stream.  You probably want RGB colors, but most  
codecs use YCbCr, instead.  In YCbCr, frame->data[0] points to Y values  
(one byte per pixel), ->data[1] points to Cb values (4 bits per pixel) and  
->data[2] points to Cr values (also 4 bits per pixel).

To illustrate: (for column X and row Y)
   int Y= frame->data[0] + frame->linesize[0] * Y + X
   int Cb= frame->data[1] + frame->linesize[1] * Y + (X/2);
   // I forget if the first pixel is in the low 4 bits or high 4 bits
   if ((X&1) == /* 0 or 1 */) Cb>>= 4;
   Cb&= 0xF;
   int Cr= frame->data[2] + frame->linesize[2] * Y + (X/2);
   if ((X&1) == /* 0 or 1 */) Cr>>= 4;
   Cr&= 0xF;

You can of course come up with much more efficient code than that.

Converting YCbCr values to RGB values is a topic on its own.  Check google  
for all the details.  If you want to take the easy way out, use swscale to  
convert the entire frame to RGB and then do your color-key.  But, keep in  
mind that you can also color-key directly on YCbCr values without ever  
converting to RGB (just convert your RGB key-color to YCbCr first).


________
Michael Conrad
IntelliTree Solutions llc.
513-552-6362
[EMAIL PROTECTED]
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to