raw string from mmap.read() possible?

Dan Jones djones at shcorp.com
Sun Nov 9 13:27:41 EST 2003


Hello all,

I'm writing a webcam app to display video from a video4linux device. I'm
having trouble with the function to convert the video from yuv420p
format to rgb. Its a C function that I wrapped for use in python. Here's
whats happening:

WIDTH=320
HEIGHT=240

yuvframe = mmap.read(WIDTH*HEIGHT*3)
rgbframe = yuv.yuv2rgb(WIDTH, HEIGHT, yuvframe)

At this point it gives a typeerror: argument 3 must be string without
null bytes, not str.

I did some testing to see whats going on. This call also generates the
typeerror:

rgbframe = yuv.yuv2rgb(WIDTH, HEIGHT, "\0\0\0\0")

but if I send it a raw string it doesn't complain:

rgbframe = yuv.yuv2rgb(WIDTH, HEIGHT, r"\0\0\0\0")

I'm assuming this is happening because C interprets NULL as the end of
the string. Is there a way to get a raw string directly from the
mmap.read() call or do I have to do a conversion after the read? If I
have to convert it, what would be the fastest way to do it? I need to
get at least 5-10fps. Any help much appreciated.

Thanks,
Dan






More information about the Python-list mailing list