With what to record video from the desktop? MoviePy creates animation, opencv records video from the camera, PIL takes screenshots. More for Windows did not find anything ...
2 answers
I would like to recommend you to use FFmpeg for this purpose here can be read in more detail: https://www.ffmpeg.org There are a lot of features and settings. Here is a sample code for how I use it in my Windows:
import subprocess as subp from os.path import join log_dir = '' # путь куда положить файл с записью CORE_DIR = '' # путь где лежит ffmpeg.exe video_file = join(log_dir, 'video_' + id_test + '.flv') FFMPEG_BIN = join(CORE_DIR, 'ffmpeg\\bin\\ffmpeg.exe') command = [ FFMPEG_BIN, '-y', '-loglevel', 'error', '-f', 'gdigrab', '-framerate', '12', '-i', 'desktop', '-s', '960x540', '-pix_fmt', 'yuv420p', '-c:v', 'libx264', '-profile:v', 'main', '-fs', '50M', video_file ] ffmpeg = subp.Popen(command, stdin=subp.PIPE, stdout=subp.PIPE, stderr=subp.PIPE) You start a very cool thing in a separate process and while the script is running or something else is being written. Just do not forget to stop the process later.
Here is the code to stop:
ffmpeg.stdin.write("q") ffmpeg.stdin.close() - +1 for using ffmpeg to get a screen video. Aside: do not use
std*=PIPEif you do not consume the appropriate stream, otherwise the process may hang (when the corresponding system buffer is full). If you just want to hide the output, you should useDEVNULL. - jfs - I agree with the comment: But the fact is that I need to stop this corresponding stream correctly or the video file will not be recorded correctly, for this you have to use std * = PIPE. Otherwise, something I did not work. But stdout = subp.PIPE, stderr = subp.PIPE can of course be sent to DEVNULL. - Chp
- one"hide output" hints that
std*in my comments isstdout,stderr(standard output stream and error stream). - jfs
|
You can take screenshots and record them in a video file. I found this code here.
import numpy as np import Image, ImageGrab, ImageOps import cv2 while(True): printscreen_pil = ImageGrab.grab() printscreen_numpy = np.array(printscreen_pil.getdata(),dtype=uint8)\ .reshape((printscreen_pil.size[1],printscreen_pil.size[0],3)) cv2.imshow('window',printscreen_numpy) if cv2.waitKey(25) & 0xFF == ord('q'): cv2.destroyAllWindows() break cap = cv2.VideoCapture(0) # Define the codec and create VideoWriter object #fourcc = cv2.VideoWriter_fourcc(*'MJPG') fourcc = cv2.cv.CV_FOURCC(*'XVID') out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480)) while(cap.isOpened()): ret, frame = cap.read() if ret==True: # frame = cv2.flip(frame,0) # write the flipped frame out.write(frame) cv2.imshow('frame',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break else: break # Release everything if job is finished cap.release() out.release() cv2.destroyAllWindows() |
screencast- jfs