📜  Python VLC MediaPlayer – 设置比例(1)

📅  最后修改于: 2023-12-03 15:34:05.907000             🧑  作者: Mango

Python VLC MediaPlayer - Setting Aspect Ratio

VLC is a free and open-source media player that can handle almost all types of multimedia files. python-vlc is a Python library that provides bindings for the VLC media player.

This tutorial is focused on setting the aspect ratio of media playback in the Python VLC MediaPlayer module.

Setting Aspect Ratio

The aspect ratio of a video can be set using the set_video_aspect_ratio() method of the MediaPlayer class. The method takes a string parameter in the format of width:height, e.g. "16:9".

import vlc

# create vlc instance and media player
instance = vlc.Instance("--no-xlib")
player = instance.media_player_new()

# load media
media = instance.media_new("example.mp4")
player.set_media(media)

# set aspect ratio
player.video_set_aspect_ratio("16:9")

# start playback
player.play()

In the above example, we create a VLC instance and a media player. We load media from a file and set the aspect ratio to "16:9". Finally, we start the playback.

Conclusion

Setting the aspect ratio of media playback in the Python VLC MediaPlayer module is straightforward. The set_video_aspect_ratio() method of the MediaPlayer class is used to set the aspect ratio.

However, keep in mind that the aspect ratio of the video source cannot be changed, and some videos may not have a valid aspect ratio.