Skip to content

Instantly share code, notes, and snippets.

@HughxDev
Forked from t-io/xvfb_screen_recording.py
Created December 30, 2017 19:57
Show Gist options
  • Save HughxDev/bfdabb12fde4d0358c7b74768dc1f721 to your computer and use it in GitHub Desktop.
Save HughxDev/bfdabb12fde4d0358c7b74768dc1f721 to your computer and use it in GitHub Desktop.
ScreenRecording xvfb
from selenium import webdriver
import sys, getopt, time, subprocess, shlex
from xvfbwrapper import Xvfb
def run():
print('Sreencast website animation')
xvfb = Xvfb(width=1280, height=720, colordepth=24)
xvfb.start()
#browser = webdriver.Chrome()
browser = webdriver.Firefox()
url = 'https://s3-eu-west-1.amazonaws.com/movefast-quickhost/web-animation-test/index.html'
destination = 'movie.flv'
browser.get(url)
# normal quality, lagging in the first part on the video. filesize ~7MB
# ffmpeg_stream = 'ffmpeg -f x11grab -s 1280x720 -r 24 -i :%d+nomouse -c:v libx264 -preset superfast -pix_fmt yuv420p -s 1280x720 -threads 0 -f flv "%s"' % (xvfb.new_display, destination)
# high quality, no lagging but huge file size ~50MB
ffmpeg_stream = 'ffmpeg -y -r 30 -f x11grab -s 1280x720 -i :%d+nomouse -c:v libx264rgb -crf 15 -preset:v ultrafast -c:a pcm_s16le -af aresample=async=1:first_pts=0 out.mkv' % xvfb.new_display
args = shlex.split(ffmpeg_stream)
p = subprocess.Popen(args)
print(p)
time.sleep(30) # record for 30 secs
browser.quit()
xvfb.stop()
if __name__ == "__main__":
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment