SDL_Overlay YUV data

hi all

i try to use SDL_Overlay to show webcam data
that’s my code####################################################
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = 640;
fmt.fmt.pix.height = 480;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;

if (-1 == ioctl (fd, VIDIOC_S_FMT, &fmt))

{
printf(“set v4ls format error: %d\n”, errno);
goto finish;
}

buffer = malloc(fmt.fmt.pix.sizeimage);

if(SDL_Init(SDL_INIT_VIDEO) < 0){
printf(“SDL init error\n”);
return 0;
}
screen = SDL_SetVideoMode(640, 480, 24, SDL_HWSURFACE | SDL_RESIZABLE);
v_frame=SDL_CreateYUVOverlay(640, 480, SDL_YV12_OVERLAY, screen);

rect.x=0;
rect.y=0;
rect.w=640;
rect.h=480;

v_frame->pixels[0] = buffer;
v_frame->pixels[2] = buffer + 640480;
v_frame->pixels[1] = buffer + 640
480/4;

v_frame->pitches[0] = 640;
v_frame->pitches[1] = 160;
v_frame->pitches[2] = 160;

for (i=0; i<300; i++)
{
SDL_LockYUVOverlay(v_frame);
if (read(fd, buffer, fmt.fmt.pix.sizeimage)==-1)
{
printf(“read frame error: %d\n”, errno);
return 0;
}
SDL_UnlockYUVOverlay(v_frame);
SDL_DisplayYUVOverlay(v_frame, &rect);
}

############################################################################

it can display but there is a ghost shadow on the image
I think the problem is color information(U&V)
it works fine when i convert YUV to RGB and display on a SDL_Surface
but i don’t know how to solve it when i use SDL_Overlay
how should i do to make it display fine
thanks

Sam