What do you need to play pygame to play video files?

I have a video file called intro.mpg that plays a 2 minute introduction. Its properties are as follows:

Length: 02:23
Frame Width: 800
Frame Height: 600
Data Rate: 18500 kbps
Total Bitrate: 18884 kbps
Frame Rate: 50 fps

Bit Rate: 384 kbps
Channels 2 (stereo)
Audio Sample Rate: 44 kHz

Is pygame required for a specific type of video file with certain properties, or is this my code:

import sys
import pygame

pygame.init()
pygame.mixer.init()

mov_name = "resources\\video\\intro.mpg"

screen = pygame.display.set_mode((800, 600))
video = pygame.movie.Movie(mov_name)
screen = pygame.display.set_mode(video.get_size())
video.play()

while video.get_busy():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

'Because that’s all I get: enter image description here

+4
source share
1 answer

A series of events do not sleep for a while. So the computer runs as fast as it can. Your code uses too much CPU. And the time to play the movie is not enough.

Solution: Try this code:

import sys
import pygame

pygame.init()
pygame.mixer.init()
mov_name = "path_to_file"

clock=pygame.time.Clock()

####screen = pygame.display.set_mode((800, 600))
video = pygame.movie.Movie(mov_name)
w,h=video.get_size()
screen = pygame.display.set_mode((w,h))
video.set_display(screen,(0,0,w,h))
video.play()

while True:
    event=pygame.event.wait()
    if event.type==pygame.QUIT:
            pygame.quit()
            sys.exit()
0
source

All Articles