I just need help understanding how to provide the right variable types, by referring to the Python API for LibVLC.
I'm using the
vlc.py Python wrapper, and I can't work out what format the parameters need to be in when calling "libvlc_video_set_aspect_ratio".
vlc.libvlc_video_set_aspect_ratio(player,
"16:9")
Gives the error;
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type
vlc.libvlc_video_set_aspect_ratio(player,
c_char_p('16:9'))
Gives the error;
"builtins.TypeError: bytes or integer address expected instead of str instance"
Here is the
documentation for libvlc_video_set_aspect_ratio:
def libvlc_video_set_aspect_ratio(p_mi, psz_aspect):
'''Set new video aspect ratio.
@param p_mi: the media player.
@param psz_aspect: new video aspect-ratio or None to reset to default @note Invalid aspect ratios are ignored.
'''
f = _Cfunctions.get('libvlc_video_set_aspect_ratio', None) or \
_Cfunction('libvlc_video_set_aspect_ratio', ((1,), (1,),), None,
None, MediaPlayer, ctypes.c_char_p)
return f(p_mi, psz_aspect)
Try vlc.libvlc_video_set_aspect_ratio(player, (16,9))
(Apr-28-2019, 08:00 PM)Yoriz Wrote: [ -> ]Try vlc.libvlc_video_set_aspect_ratio(player, (16,9))
Thank you. Well, I tried it, I got the first error again; "ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type"
I've made the minimum code available at
this pastebin; It needs
vlc.py in the same folder and libvlc and SDL2 installed. And then just change the hardcoded "your_video.mp4" to whatever you want. Then you press 1 or 2 to force the aspect ratio.
(Apr-28-2019, 08:02 PM)buran Wrote: [ -> ]cross-posted https://forum.videolan.org/viewtopic.php?f=32&t=149188
please, don't cross-post or let us know if you asked the same question elsewhere
No worries, I will do so moving forward. I always thought cross-posting referred to different boards within the same forum. I gave it a day there before I posted somewhere else. I've posted there before and I get the feeling they maybe don't like Python questions, and I figure this is more of a pure Python question anyway. I think this is just a matter of understanding how to convey certain variable types in Python.
(Apr-28-2019, 09:55 PM)Yoriz Wrote: [ -> ]What does libvlc_video_get_aspect_ratio return, maybe it will give an indication of what a psz_aspect is.
I printed the output of libvlc_video_get_aspect_ratio, and it just prints "None"... so nothing useful there :(
I would have thought API documentation contains the info on the variable types, and that I just couldn't work out how to interpret that from those docs. So it doesn't look like it contains that information?
I found this in the main LibVLC documentation (rather than going through the Python version)
https://www.videolan.org/developers/vlc/...b4a6968e5e
And if I click "psz_string" it's defined as "char* vlc_value_t::psz_string".
When I was last trying to solve this problem, I was looking into a Python fuction called "str_to_bytes" so that may have something to do with it, but I can't remember why.
Stab in the dark here but try player.video_set_aspect_ratio('16:9')
(Apr-28-2019, 10:34 PM)Yoriz Wrote: [ -> ]Stab in the dark here but try player.video_set_aspect_ratio('16:9')
Geez, that worked! Thank you!
I had already moved to the player.method(parameters) style, as opposed to method.(player, parameters), but I only gleaned that from an example I found, nothing in the documentation led me to think that was possible.
So, in the interests of teaching a man to fish, how did you think to try '16:9'? I had tried that I swear, but maybe not with the player.method() style. I find it strange that we had to "stab in the dark" instead of the documentation giving us the info...
And also where did you get the inclination that the player.method() syntax was possible?
Man I tried vlc.libvlc_video_set_aspect_ratio(player, '16:9') and like I thought - that still gives the error! But for some reason, player.video_set_aspect_ratio('16:9') works...
In the VLC thread, someone told me that using a byte string, eg. b"16:9" is what was needed to make the long version work, eg;
vlc.libvlc_video_set_aspect_ratio(player, b"16:9")
video_set_aspect_ratio
calls
libvlc_video_set_aspect_ratio
by using
str_to_bytes(psz_aspect)
def video_set_aspect_ratio(self, psz_aspect):
3755 '''Set new video aspect ratio.
3756 @param psz_aspect: new video aspect-ratio or None to reset to default @note Invalid aspect ratios are ignored.
3757 '''
3758 return libvlc_video_set_aspect_ratio(self, str_to_bytes(psz_aspect))