can i record screen realtime?

for example i grab screen as a Pixmap or image and add to created avi file it.

create avi file "x"?

while()
{
grabWindow
add avi file
}

like this