Occasionally you need to use Python to implement the recording screen and export the video, write a simple code.
The idea is to take a screenshot at intervals, then turn the screenshot image into a video export.
1 #-*-coding:cp936-*-2 fromPILImportImagegrab3 ImportTime,os,cv24 ImportNumPy as NP5 defReleasevideo ():6PATH=OS.GETCWD () +'\\picture\\'7filelist=os.listdir (path)8fps=29Size= (1366,768)TenVideo=cv2. Videowriter ("1.avi", Cv2. VIDEOWRITER_FOURCC ('M','J','P','G'), FPS, size) One forIteminchfilelist: A ifItem.endswith ('. PNG'): - #locate all files in the path that are named. png and can be replaced by. jpg or other -Item = path +Item theIMG =cv2.imread (item) - video.write (IMG) - - video.release () + cv2.destroyallwindows () - if __name__=='__main__': +num=0 A while1: atNum+=1 -Time.sleep (0.5) -bbox= (0,0,1366,768)#The four parameters represent the beginning of x, Y, the end of X, Y, and the second two can see the computer -im=Imagegrab.grab (bbox) -Im.save (OS.GETCWD () +'\\picture\\'+STR (num) +'. PNG') - ifNUM>20:#This can control the end of time, this way I set to 5 seconds, change the parameters on the line in Releasevideo () - Break to
This is only a test feasibility, no optimization, in fact there is no need for two separate operation, parallel efficiency will be much higher. The use of Time.sleep () is also trickery majority. Wait a while to write a Python version of the Recording screen tool using Wxpython.
Preliminary implementation of Python automatic recording screen