@The_XXI

Как воспроизвести видео в PyGame?

Не могу воспроизвести видео в pygame, модуль pygame movie отсутствует, через moviepy видео подвисает. Есть какой-то способ воспроизводить видео в pygame?
  • Вопрос задан
  • 2352 просмотра
Пригласить эксперта
Ответы на вопрос 1
Astrohas
@Astrohas
Python/Django Developer
Есть еще pyglet
import pygame, pyglet, ctypes

#setup pyglet & the video
path = r"C:\SomeVideo.avi"

player = pyglet.media.Player()
source = pyglet.media.load(path)
player.queue(source)
player.play()

#setup pygame
pygame.init()
pygame.display.set_mode((800,800), 0)
pygame.display.set_caption("Video in Pygame!")
screen = pygame.display.get_surface()
pygame.display.flip()

#blit the video in a standard pygame event loop
while True:
    events = pygame.event.get()
    for event in events:
        if event.type == pygame.QUIT:
            sys.exit(0)
    screen.fill(0)
    
    player.dispatch_events()
    tex = player.get_texture()
    raw = tex.get_image_data().get_data('RGBA',tex.width*4)
    raw = ctypes.string_at(ctypes.addressof(raw), ctypes.sizeof(raw))
    img = pygame.image.frombuffer(raw, (tex.width, tex.height), 'RGBA')
    screen.blit(img, (0,0))
    
    pygame.display.flip()


Способ костыльный, но можно попробовать
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы