raw string from mmap.read() possible?

D

Dan Jones

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
 
D

David M. Wilson

Dan Jones said:
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?

I think you're suffering from a little confusion here:

"\0\0\0\0" results in the byte sequence:

00 00 00 00

r"\0\0\0\0" results in the byte sequence:

5c 30 5c 30 5c 30 5c 30


This of course doesn't solve your problem, I know nothing about
imaging in python. :p

HTH,


David.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top