Play Video in Python Using Pygame

In this module, we are going to discuss how to play a video file in Python using pygame. Here, we play a video file in pygame using in Python to play video

Here we use module for playing a video. The syntax is as follows"file name")

The file must be in mpg format else it will not support the playing of file.

The following code gives a complete description of playing a video file

import pygame
import sys
while True:
    for eve in pygame.event.get():
        if eve==pygame.QUIT:


We get the screen of size as video and the video starts playing and it continues until it is completed or we close the window."movie_sample.mpg")

It is used for loading mpg files and we assign it with an object called movie which will be used in a further piece of code.


We are making the screen set to the size of the video file. To get it possible we used movie.get_size() function which returns the (width,height) of video file.


pygame.Surface is used for representing images. Here, we are using it to set up a video screen convert() changes the pixel format of the video.

play() is used to start the playing of the video files. By default, it takes input as zero(0) and stops playing when the video is completed but if we specify -1 then the video self-loops it will not end.


It is a function used to stop playing video files.

Also read:

Change Collision HitBox size with Pygame

5 responses to “Play Video in Python Using Pygame”

  1. Anonymous says:

    NotImplementedError: movie module not available (ModuleNotFoundError: No module named ‘’)

    I got this error!

    • Sergio Mendoza says:

      Hey, im not sure but it seems that the “movie” library from pygame has been deprecated since 20016

      • Éberte Valter da Silva Freitas says:

        I have the same error. If the library was discontinued, which one are you using now to put a video?

    • Creepermin says:

      Hey I’m having the same error, but I’m also getting a traceback

      Traceback (most recent call last):
      File “”, line 5, in“ricky.mpg”)
      File “/usr/lib/python3/dist-packages/pygame/”, line 100, in __getattr__
      raise NotImplementedError(missing_msg)
      NotImplementedError: movie module not available (ModuleNotFoundError: No module named ‘’)

      • albator105 says:

        at the end of your traceback it say
        NotImplementedError: movie module not available (ModuleNotFoundError: No module named ‘’)
        you can transform your video in image with vlc, get framerate and make a dict (dict={})
        and load image in after make the blit it:
        import pygame,
        screen = pygame.display.set_mode((680,470))
        clock =pygame.time.Clock()
        while True:
        img[1] = pygame.image.load(“img/1 (“+str(a)+”).png”)
        #get all image and rename “1” in one times for my example it give “1 (1).png,1 #(2).png”

Leave a Reply

Your email address will not be published. Required fields are marked *