Python Forum

Full Version: saving output to a video file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everybody. I've just created a simple moving object and now I need to save it as a video file. Can anybody tell me how can I save the output and which format I should choose? Also if you also introduce a source to learn it, it would be great. I also put my code here to make a sense of what it's like.
import pygame 
pygame.init()
screen=pygame.display.set_mode((1000,1000)) 

pygame.display.set_caption('visual rhythm')
icon=pygame.image.load("song.png")
pygame.display.set_icon(icon)

playerImg=pygame.image.load('spaceship.png')
playerX=370
playerY=400
def player(x,y):
    screen.blit(playerImg,(int(x),int(y)))

speed=[4000, -2000 , 2000 , -1000 , 1333 , -4000]
count=0
count2=0
clock=pygame.time.Clock()
while count2<len(speed):
    screen.fill((0,255,0))
    milli=clock.tick()
    seconds=milli/1000.0
    dm=seconds*speed[count]
    playerY+=dm
    player(playerX,playerY)
    pygame.display.update()
    if playerY>=946 or playerY<1:
        count+=1
        count2+=1
You mean you want to screencast your game? I always use ffmpeg to screencast.

like this would screencast the entire screen based on various settings
ffmpeg -f alsa -ac 2 -i plughw:0,0 -f x11grab -r 100 -s 1920x1080 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -threads 5 myvideo.mkv
or cut it in a section of the game window
ffmpeg -f alsa -ac 2 -ab 128k -i pulse -f x11grab -s 800x600 -r 30 -i :0.0+10,20 -acodec libmp3lame -vcodec mpeg4 -vtag xvid game_video.avi