Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Expected __Structure instance instead of __Structure
-
Hello forum members. Will you tell me how to set activeVideoMinFrameDuration?
I tried the following code:
from objc_util import * AVCaptureDevice = ObjCClass('AVCaptureDevice') _device = AVCaptureDevice.defaultDeviceWithDeviceType_mediaType_position_( 'AVCaptureDeviceTypeBuiltInWideAngleCamera', 'vide', 1) dur = _device.activeVideoMinFrameDuration() dur.a *= 3 _device.setActiveVideoMinFrameDuration(dur)
I got error:
Traceback (most recent call last): File "/var/mobile/Containers/Shared/AppGroup/94D43082-190D-4454-9A0E-256D7C4B8046/Pythonista3/Documents/test.py", line 10, in <module> _device.setActiveVideoMinFrameDuration(dur) File "/var/containers/Bundle/Application/F1D3A05F-66E7-4AD5-8569-D61994DF7737/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 803, in __call__ return method(*ordered_args, **kw) File "/var/containers/Bundle/Application/F1D3A05F-66E7-4AD5-8569-D61994DF7737/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 897, in __call__ res = objc_msgSend(obj.ptr, sel(self.sel_name), *args) ctypes.ArgumentError: argument 3: <class 'TypeError'>: expected __Structure instance instead of __Structure
I have read the following topic: https://forum.omz-software.com/topic/2031/videos, but I have had no success so far.
-
@yukia10 I'm not able to help you but you could find a similar problem here
I suppose that @jonb or @dgelessus could help you -
-
Iirc, you may need to manually set the argtype/restype. The auto type encoding stuff often has problems with structures -- ctypes doesn't know that two different structure types created with the same fields are identical. Objc_util ought to be catching structure types and comparing field types...
Anyway, one approach is to define your own CMTime structure, so that it has actual names, etc. See for example
Then, when you call methods that use a CMTime as an argument, you need to pass in the extra kwargs restype, and argtypes. In the above example,
cgimage_obj=generator.copyCGImageAtTime_actualTime_error_(t,byref(tactual),None,restype=c_void_p,argtypes=[CMTime,POINTER(CMTime),POINTER(c_void_p)])
This overrides the built in type checker, so you need to make sure you have it correct.
-
Thank you very much for all of your advices. I still have no luck.
I ran the following code:
from ctypes import * from objc_util import * class CMTime(Structure): _fields_ = [('value', c_int64), ('timescale', c_int32), ('flags', c_uint32), ('epoch', c_int64)] AVCaptureDevice = ObjCClass('AVCaptureDevice') _device = AVCaptureDevice.defaultDeviceWithDeviceType_mediaType_position_( 'AVCaptureDeviceTypeBuiltInWideAngleCamera', 'vide', 1) dur = _device.activeVideoMinFrameDuration(restype=CMTime, argtypes=[]) dur.value *= 3 _device.lockForConfiguration_(None) _device.setActiveVideoMinFrameDuration_(dur, restype=None, argtypes=[CMTime]) _device.unlockForConfiguration()
And I got error:
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/94D43082-190D-4454-9A0E-256D7C4B8046/Pythonista3/Documents/test.py", line 15, in <module> _device.setActiveVideoMinFrameDuration_(dur, restype=None, argtypes=[CMTime]) File "/var/containers/Bundle/Application/F1D3A05F-66E7-4AD5-8569-D61994DF7737/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 897, in __call__ res = objc_msgSend(obj.ptr, sel(self.sel_name), *args) ctypes.ArgumentError: argument 3: <class 'TypeError'>: expected __Structure instance instead of CMTime
activeVideoMinFrameDuration
is a property. Is there any way to specify argument types of a setter? -
hmm, your code worked for me.
what version of pythonista are you running?
-
On my iPad mini 4 with beta version, it get the same error.
Apple doc says that framerate must be in videoSupportedFrameRateRanges.
If I print value and timescale, they are 30 and 1. Is it possible that x3 gives 90 FPS, unsupported on my iDevice ? -
That shouldn't give you the ctypes error. The ctypes error is because it is still trying to create a custom structure rather than using the argtypes you provided.
Can you print out .encoding for the method in question?
-
Thank you very much for checking my code.
@JonB Pythonista 3.2 on iPad mini 5. This code says:
Pythonista version 3.2 (320000) running Python 3.6.1 on iOS 12.3.1 on a 64-bit iPad11,1 with a screen size of (1024 x 768) * 2
.encoding is:
>>> _device.setActiveVideoMinFrameDuration_.encoding b'v40@0:8{?=qiIq}16'
@cvp I assume 3/30 = 10 FPS. It gave the same error without the line
dur.value *= 3
.This error may be specific on iPad mini. -
I restarted Pythonista and now your code runs ok.
The print value,timescale gives 1,30 and then 3,30 😀('pythonista_ver_str', '3.3') ('pythonista_ver_num', '330013') ('ios_ver_str', '12.3.1') ('screen_resolution', Size(768.00, 1024.00)) ('screen_scale', 2.0) ('machine_architecture', '64bit') ('machine_model', 'iPad5,1')
-
I restarted my iPad mini and it runs OK now.
Thank you very much for all of your help.