townkat
Posts: 5
Joined: Thu Mar 08, 2018 5:35 am

mmal tutorial SyntaxError

Thu Mar 08, 2018 5:58 am

hi all,
i have a pi 3 and a camera v2.1 working fine with standard camera = picamera.PiCamera() object.

I am experimenting now with mmal but i get "SyntaxError: invalid syntax"
when i try:
encoder.inputs[0].enable(lamdba port, buf: True)
which is first line from example from:
https://picamera.readthedocs.io/en/rele ... -mmal-tour
16.1.8. File Input (JPEG encoding)

i can get the output.tell() 921600 result , from 16.1.6. File Output (RGB capture) as a checkpoint

i also did apt update/upgrade rpi-update

1. please help as i am really interested into seeing this hardware jpg encoding working :)

(2. also why isn't jpg encoding available with standard picamera object? i think it deserve its place in standard library as it should be really useful..)


3. and not to open another topic just for this i'l also add a slightly unrelated question: are there any chances to get full 8mp resolution h264 encoding even if it is low fps in the future ?
(even 1fps would be better than nothing, even if extrapolating would estimate a 7.5fps maybe?:))
i think it would be really cool don't you think? ..not to talk about h265.. :)

thank you all

townkat
Posts: 5
Joined: Thu Mar 08, 2018 5:35 am

Re: mmal tutorial SyntaxError

Fri Mar 09, 2018 5:30 am

1. I answered myself, typo in documentation: lamdba=lambda .

I now have other questions, i'll just add another one..:

When capturing with mmal if i do not do a time.sleep(x) before connecting the callback function and capturing, the camera object become corrupted and cannot be used untill reboot. How does the picamera object do this without useless waitings ? i am thinking at the threading events like in callback function, but how? as here there is no calling ..

Also how to connect mmal splitter(or decoder)? if i try i get: 'property' object not suscriptable...If this would be solved i think the complexity of capturing directly with mmalcamera is not much bigger with higher posibilities..

Here is my code if anyone needs a sample of capturing with mmalcamera object. I also have it working with jpg encoder, and maybe also with resizer (not sure, working on it..), if anyone need them just let me know.

Code: Select all

from io import BytesIO
from picamera import mmal, mmalobj as mo

camera = mo.MMALCamera()

camera.outputs[2].format = mmal.MMAL_ENCODING_RGB24
camera.outputs[2].framesize = (640, 480)
camera.outputs[2].commit()

from io import BytesIO
rgbfile = BytesIO()

from threading import Event
finished = Event()
finished.clear()

def savetorgb(port, buf):
    rgbfile.write(buf.data)
    if (buf.flags & mmal.MMAL_BUFFER_HEADER_FLAG_FRAME_END):
        finished.set()
        return True
    return False

camera.outputs[2].enable(savetorgb)
time.sleep(1) #without this the picamera object become unusable untill reboot
camera.outputs[2].params[mmal.MMAL_PARAMETER_CAPTURE] = True
if (not finished.wait(10)):
    print('nope')
camera.outputs[2].params[mmal.MMAL_PARAMETER_CAPTURE] = False
camera.outputs[2].disable()
print('rgbfile size is ' + str(rgbfile.tell()))

townkat
Posts: 5
Joined: Thu Mar 08, 2018 5:35 am

Re: mmal tutorial SyntaxError

Sun Mar 11, 2018 3:27 am

Just a small update, i managed to get all the objects i was interested in (camera, encoder, splitter, resizer etc.) connected and working.
The fix to the delay needing was simply to change the port number to "1" ex.: camera.outputs[1].params[picamera.mmal.MMAL_PARAMETER_CAPTURE] = True
, then it works without the time.sleep(1) line,

A new problem appeared thought, it only works up to 1920x1080 resolution, if i try to set higher, even in the simple example in the above post then there will be no output, output file object 0 bytes.
Now i am studying picamera.picamera object source as it manage to work at higher than 1920x1080 resolution..but i am not very optimistic unfortunately.. (already almost 2 days into this problem..)
..i just wish the documentation would help me more..

If anyone wonders, my purpose which picamera object was not able to satisfy is to capture exactly the same picture at multiple resolution (1 full sensor resolution, and another smaller thumb, but may be bigger than exif limits), from video port (so not post processing). Also the thumb should be a separate file.

Also as i am sure others will get into this python error and i found nothing on google about it, the error: 'property' object not subscriptable , was caused by forgetting to use ( ) parenthesis.
for ex: encoder = picamera.mmalobj.MMALImageEncoder
instead of
encoder = picamera.mmalobj.MMALImageEncoder()
then encoder.inputs[0] = ... would return 'property' object not subscriptable..
i am sure there will be others.. :)

DJG66
Posts: 1
Joined: Thu Jan 02, 2020 9:24 am

Re: mmal tutorial SyntaxError

Thu Jan 02, 2020 9:26 am

Bro, can you pst your code for image capture with encoding?
I am unable to connect the encoder

User avatar
DougieLawson
Posts: 37073
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: mmal tutorial SyntaxError

Fri Jan 03, 2020 1:27 am

Don't hold your breath waiting. The OP hasn't logged on to the forum since Sun 15 Apr 2018 @ 18:08.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Camera board”