'Unexpected resizing when viewing video inside a rectangle with pygame/moviepy

I'm trying to create a rectangle and display a video in a square inside the rectangle. The problem is that when the preview is executed, the rectangle disappears (or is resizing). Can someone help me?

import moviepy.video.fx.all
from moviepy.editor import *
import pygame

class VideoSprite(pygame.sprite.Sprite):
    def __init__(self, rect, filename):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((rect.width, rect.height), pygame.HWSURFACE)
        self.rect = self.image.get_rect()
        self.rect.x = rect.x
        self.rect.y = rect.y
        self.video = moviepy.editor.VideoFileClip(filename).resize((self.rect.width, self.rect.height))        
        self.video_stop = False

    def update(self, time=pygame.time.get_ticks()):
        if not self.video_stop:
            try:
                raw_image = self.video.get_frame(time / 1000)
                self.image = pygame.image.frombuffer(raw_image,(self.rect.width, self.rect.height), 'RGB')
            except:
                self.video_stop = True

WINDOW_WIDTH    = 300
WINDOW_HEIGHT   = 600
WINDOW_SURFACE  = pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE

DARK_BLUE = (   3,   5,  54)
pygame.init()
pygame.mixer.init()
pygame.display.set_caption('Natália')
window = pygame.display.set_mode( ( WINDOW_WIDTH, WINDOW_HEIGHT ), WINDOW_SURFACE )

vds = VideoSprite(pygame.Rect( 50, 50, 100, 100 ),'theVideo.mp4')
sprite_group = pygame.sprite.GroupSingle()
sprite_group.add(vds)
sprite_group.update()
window.fill( DARK_BLUE )
sprite_group.draw( window )
pygame.display.flip()
vds.video.preview()

input()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source