Python Forum
Can't work out parameter format for LibVLC functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't work out parameter format for LibVLC functions
#1
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) 
Reply
#2
Try vlc.libvlc_video_set_aspect_ratio(player, (16,9))
Reply
#3
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(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.
Reply
#5
What does libvlc_video_get_aspect_ratio return, maybe it will give an indication of what a psz_aspect is.
Reply
#6
(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.
Reply
#7
Stab in the dark here but try player.video_set_aspect_ratio('16:9')
Reply
#8
(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...
Reply
#9
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")
Reply
#10
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)) 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 10,661 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  main libvlc error: stale plugins cache: schascheck 2 7,596 Dec-27-2020, 05:24 PM
Last Post: schascheck
  User functions don't work: Baldev10 7 3,083 Aug-18-2020, 08:34 PM
Last Post: deanhystad
  I writte 5 functions (def) but on 6 don't work. Someone can help me? perrud 2 2,755 Feb-03-2018, 10:20 AM
Last Post: perrud

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020