Hello,
I grab frames from a webcam and show them on a window through a
overlay (SDL_YUY2_OVERLAY); then I draw on them while I see the video.
The problem is that the video is always flashing (e.g. I see flashing
also the area which is supposed to be covered by the drawings). More
specificly, what I draw is a color histogram.
I’ve seen some discussions on this list about similar problems, but no
one had a definitive solution. What I do in my app now is more or less
this:
// Init
pscreen = SDL_SetVideoMode(w, h, 24, SDL_HWSURFACE|SDL_DOUBLEBUF);
// …
overlay = SDL_CreateYUVOverlay(w, h, SDL_YUY2_OVERLAY, pscreen);
pbuff = (unsigned char *) overlay->pixels[0];
while (…) {
// …
// Grab a frame
// …
SDL_LockYUVOverlay(overlay);
memcpy(pbuff, frame, wh2);
SDL_UnlockYUVOverlay(overlay);
SDL_DisplayYUVOverlay(overlay, &drect);
SDL_LockSurface(pscreen);
// Then draw lines with putpixel on pscreen surface
// …
SDL_UnlockSurface(pscreen);
SDL_UpdateRect(pscreen, x,y,etc.);
}
Other info:
- I tried with and without locking pscreenm and/or using SDL_flip()
instead of updaterect - It happens with both HWSURFACE (with double buffering or not) and SWSURFACE
- I’m on Linux, SDL 1.2.12
- I can’t draw on the frame before painting it, because it’s in YUYV
and it means that U and V are shared between close pixels (so I can’t
draw on single pixels)
I partially solved by reducing the overlay size, but what if the area
I want to draw on is not rectangular?
Any suggestion?
Thanks…–
Eugenio
http://binaryunit.blogspot.com