How to capture a pygame screen?

How can I capture and save a sequence of images or videos on a pygame screen?

Basically, I want to share my video on YouTube. In addition, you want to make a tutorial.

The game is displayed mainly in the loop:

def main(): while True: GetInput() Move() Shift() Draw() 

Using the Draw() function that does all blit() and stuff before doing pygame.display.flip()

+8
python video-capture pygame
source share
1 answer

Use pygame.image.save on the surface of the screen:

 window = pygame.display.set_mode(...) ... pygame.image.save(window, "screenshot.jpeg") 

Please note that this will significantly slow down your program. If it depends on the time, you can fake the frame rate while capturing.

+21
source share

All Articles