1

I am trying to take a screenshot of every frame of a movie for other processing. However, when I run this, all I get is newlines printed out. After I kill the program in any way, I get a Segmentation fault (core dumped)

Why is the segmentation fault happening? My code or pygame or somthing else?

Why do I not get some text out of the program?

Using Python 2.7, Ubuntu

import sys
import os
if sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5:
    os.environ['SDL_VIDEODRIVER'] = 'windib'
import pygame

pygame.init()
pygame.mixer.quit()
movie = pygame.movie.Movie(sys.argv[1])
screen = pygame.display.set_mode(movie.get_size())
movie.set_display(screen)

movie.play()
while movie.get_busy():
    print pygame.image.tostring(screen, 'RGB', False)
    if pygame.event.peek(pygame.QUIT):
        pygame.quit()
        exit()
    pygame.event.clear()
movie.stop()
pygame.quit()

This is my first question so please say if I have missed anything :)

muddyfish
  • 3,530
  • 30
  • 37
  • I don't know about the screenshot bit (I'll look at that later) but I can see a few issues: 1) I'm not sure your QUIT event actually breaks your loop. It quits pygame but then, as you're still in the loop it's going to give you an error when you try to run pygame methods. 2) You've got `pygame.quit()` twice. 3) Is `exit()` meant to be `sys.exit()`? – elParaguayo Mar 10 '14 at 12:42
  • I believe exit() and sys.exit() are interchangeable aren´t they? – muddyfish Mar 10 '14 at 17:46
  • That's not my understanding - but then I only saw this post: http://stackoverflow.com/questions/6501121/the-difference-between-exit-and-sys-exit-in-python – elParaguayo Mar 10 '14 at 19:39

1 Answers1

0

I believe, reading from docs, that it actually 'blits' the movie to your surface. So in pygame you can save surfaces. Assuming this it should be possible to use pygame.image.save(screen, "screenshot.bmp")

This is because a display takes attributes of a surface. So in the pygame docs under image you can find the function save as I used above. And as long as you pause the movie first (to get accurate image) you should have a screenshot of the movie.

Cheers!

KodyVanRy
  • 1,110
  • 1
  • 14
  • 25