私は実際にあなたのビデオのスタッドを気づいた。
これは、draw()
+ window.flip()
の代わりにblit()
を使用しているためです。これは、グラフィカルバッファを更新する方がはるかに効率的です。
player
のテクスチャをpyglet.sprite.Sprite()
オブジェクトに入れることもできます。テクスチャ自体はすべてのフレームで高いレートで更新されます。
import pyglet
from pyglet.gl import *
from threading import *
# REQUIRES: AVBin
#pyglet.options['audio'] = ('alsa', 'openal', 'silent')
key = pyglet.window.key
class main(pyglet.window.Window):
def __init__ (self):
super(main, self).__init__(800, 800, fullscreen = False)
self.x, self.y = 0, 0
self.player = pyglet.media.Player()
self.player.queue(pyglet.media.load("video.mp4"))
self.sprites = {'video' : None}
self.alive = 1
def on_draw(self):
self.render()
def on_close(self):
self.alive = 0
def on_mouse_motion(self, x, y, dx, dy):
pass
def on_mouse_release(self, x, y, button, modifiers):
pass
def on_mouse_press(self, x, y, button, modifiers):
pass
def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
pass
def on_key_release(self, symbol, modifiers):
pass
def on_key_press(self, symbol, modifiers):
if symbol == 65307: # [ESC]
self.alive = 0
elif symbol == key.LCTRL:
self.player.play()
def render(self):
self.clear()
if self.player.playing:
if self.sprites['video'] is None:
texture = self.player.get_texture()
if texture:
self.sprites['video'] = pyglet.sprite.Sprite(texture)
else:
self.sprites['video'].draw()
self.flip()
def run(self):
while self.alive == 1:
self.render()
# -----------> This is key <----------
# This is what replaces pyglet.app.run()
# but is required for the GUI to not freeze
#
event = self.dispatch_events()
x = main()
x.run()
しかし、これは私が私のWindowsマシン上で他のいくつかの私の.mp4
ビデオとグリッチなどのドライバの問題を抱えているが、それはあなたが見つけたコード例よりも優れて働いて、私のためにフレームレートを倍増しました。
これをテストするには若干の問題があります。私が抱いているビデオのほとんどは黒くなり、何も表示されません(ビデオファイルはちょっとした暗いものにエンコードされ、ffmpegを通してそれらを渡そうとするとエラーが発生します)。私たちが自分でダウンロードできるビデオでテストしましたか? – Torxed