pygame.movie
pygame module for playback of mpeg video
pygame.movie.Movie load an mpeg movie file

NOTE: On NT derived Windows versions (e.g. XT) the default SDL directx video driver is problematic. For pygame.moviepygame module for playback of mpeg video, use the windib driver instead. To enable windib set the SDL_VIDEODRIVER environment variable to ‘windib’ before importing pygame (see the pygame.examples.movieplayer.main()play an MPEG movie example).

Pygame can playback video and audio from basic encoded MPEG-1 video files. Movie playback happens in background threads, which makes playback easy to manage.

The audio for Movies must have full control over the sound system. This means the pygame.mixerpygame module for loading and playing sounds module must be uninitialized if the movie’s sound is to be played. The common solution is to call pygame.mixer.quit() before the movie begins. The mixer can be reinitialized after the movie is finished.

The video overlay planes are drawn on top of everything in the display window. To draw the movie as normal graphics into the display window, create an offscreen Surface and set that as the movie target. Then once per frame blit that surface to the screen.

Videos can be converted to the .mpg file format (MPEG-1 video, MPEG-1 Audio Layer III (MP3) sound) using ffmpeg video conversion program (http://ffmpeg.org/):

ffmpeg -i <infile> -vcodec mpeg1video -acodec libmp3lame -intra <outfile.mpg>
class pygame.movie.Movie
load an mpeg movie file
Movie(filename) -> Movie
Movie(object) -> Movie
pygame.movie.Movie.play start playback of a movie
pygame.movie.Movie.stop stop movie playback
pygame.movie.Movie.pause temporarily stop and resume playback
pygame.movie.Movie.skip advance the movie playback position
pygame.movie.Movie.rewind restart the movie playback
pygame.movie.Movie.render_frame set the current video frame
pygame.movie.Movie.get_frame get the current video frame
pygame.movie.Movie.get_time get the current vide playback time
pygame.movie.Movie.get_busy check if the movie is currently playing
pygame.movie.Movie.get_length the total length of the movie in seconds
pygame.movie.Movie.get_size get the resolution of the video
pygame.movie.Movie.has_video check if the movie file contains video
pygame.movie.Movie.has_audio check if the movie file contains audio
pygame.movie.Movie.set_volume set the audio playback volume
pygame.movie.Movie.set_display set the video target Surface

Load a new MPEG movie stream from a file or a python file object. The Movie object operates similar to the Sound objects from pygame.mixerpygame module for loading and playing sounds.

Movie objects have a target display Surface. The movie is rendered into this Surface in a background thread. If the target Surface is the display Surface, the movie will try to use the hardware accelerated video overlay. The default target is the display Surface.

play()
start playback of a movie
play(loops=0) -> None

Starts playback of the movie. Sound and video will begin playing if they are not disabled. The optional loops argument controls how many times the movie will be repeated. A loop value of -1 means the movie will repeat forever.

stop()
stop movie playback
stop() -> None

Stops the playback of a movie. The video and audio playback will be stopped at their current position.

pause()
temporarily stop and resume playback
pause() -> None

This will temporarily stop or restart movie playback.

skip()
advance the movie playback position
skip(seconds) -> None

Advance the movie playback time in seconds. This can be called before the movie is played to set the starting playback time. This can only skip the movie forward, not backwards. The argument is a floating point number.

rewind()
restart the movie playback
rewind() -> None

Sets the movie playback position to the start of the movie. The movie will automatically begin playing even if it stopped.

The can raise a ValueError if the movie cannot be rewound. If the rewind fails the movie object is considered invalid.

render_frame()
set the current video frame
render_frame(frame_number) -> frame_number

This takes an integer frame number to render. It attempts to render the given frame from the movie to the target Surface. It returns the real frame number that got rendered.

get_frame()
get the current video frame
get_frame() -> frame_number

Returns the integer frame number of the current video frame.

get_time()
get the current vide playback time
get_time() -> seconds

Return the current playback time as a floating point value in seconds. This method currently seems broken and always returns 0.0.

get_busy()
check if the movie is currently playing
get_busy() -> bool

Returns true if the movie is currently being played.

get_length()
the total length of the movie in seconds
get_length() -> seconds

Returns the length of the movie in seconds as a floating point value.

get_size()
get the resolution of the video
get_size() -> (width, height)

Gets the resolution of the movie video. The movie will be stretched to the size of any Surface, but this will report the natural video size.

has_video()
check if the movie file contains video
has_video() -> bool

True when the opened movie file contains a video stream.

has_audio()
check if the movie file contains audio
has_audio() -> bool

True when the opened movie file contains an audio stream.

set_volume()
set the audio playback volume
set_volume(value) -> None

Set the playback volume for this movie. The argument is a value between 0.0 and 1.0. If the volume is set to 0 the movie audio will not be decoded.

set_display()
set the video target Surface
set_display(Surface, rect=None) -> None

Set the output target Surface for the movie video. You may also pass a rectangle argument for the position, which will move and stretch the video into the given area.

If None is passed as the target Surface, the video decoding will be disabled.