如何在python中更改vlc媒体播放器的视频宽高比

时间:2018-10-27 07:32:21

标签: python vlc aspect-ratio

我想知道如何将python中的vlc媒体播放器的视频宽高比更改为16:10。请注意,我正在使用vlc模块。我的代码如下:

import vlc
class Player():
    def __init__(self):
        self._instance = vlc.Instance(['--video-on-top'])
        self._player = self._instance.media_player_new()
        self._player.set_fullscreen(True)

    def play(self, path):
        media = self._instance.media_new(path)
        self._player.set_media(media)
        self._player.play()

    def stop(self):
        self._player.stop()
p=Player()
p.play('C:\\Users\\Keshavarz\\Desktop\\a.mp4')

1 个答案:

答案 0 :(得分:0)

使用video_set_aspect_ratio("n:n")选项,其中"n:n"是任何常见的可疑对象“ 16:9”,“ 4:3”等,但可以是任何您想要的东西,例如“ 2:5” 。

您还需要使脚本保持活动状态,为此,我在play函数中添加了一个简单的循环。

import vlc
import time
class Player():
    def __init__(self):
        self._instance = vlc.Instance(['--video-on-top'])
        self._player = self._instance.media_player_new()
        #self._player.set_fullscreen(True)
        self._player.video_set_aspect_ratio("16:9")

    def play(self, path):
        media = self._instance.media_new(path)
        self._player.set_media(media)
        self._player.play()
        playing = set([1,2,3,4])
        time.sleep(0.1)
        while True:
            state = self._player.get_state()
            if state not in playing:
                break
            time.sleep(1)

    def stop(self):
        self._player.stop()
p=Player()
p.play('C:\\Users\\Keshavarz\\Desktop\\a.mp4')