solo-salamander

screen_record_snippet

Jul 30th, 2021 (edited)
3,043
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pyautogui
  2. import cv2
  3. import numpy as np
  4. import sys
  5. import time
  6. # import click
  7. import os
  8. import datetime
  9.  
  10.  
  11. today = datetime.datetime.now()
  12. date_str = today.strftime('%Y-%m-%d  %H:%M:%S')
  13. date_str = date_str.replace(':','-')
  14. cur_dir = '/'.join(os.path.dirname(os.path.abspath(__file__)).split('/'))
  15. filename = date_str + '.avi'
  16. # @click.command()
  17. # @click.option('--rec',type=str,default='class_rec',required=False,help="class you will be recording for")
  18. # @click.option('--filename',type=str,default=date_str + '.avi',required=False,help="you can specify filename/ default is script start datetime")
  19. # @click.option('--path',type=str,default=cur_dir,required=False,help="path to save folder / default is script location")
  20. # @click.option('--duration',type=int,default=1,help="duration for screen record / default is 60s")
  21. # def cli(rec,filename,path,duration):
  22. def cli():
  23.     resolution = (1920, 1080)
  24.     codec = cv2.VideoWriter_fourcc(*"XVID")
  25.     # filename = f"{path}/{filename}"
  26.     fps = 10.0
  27.     out = cv2.VideoWriter(filename, codec, fps, resolution)
  28.     cv2.namedWindow("Live", cv2.WINDOW_NORMAL)
  29.     cv2.resizeWindow("Live", 480, 270)
  30.     start_time = time.time()
  31.     # duration_in_seconds = duration * 60
  32.     while True:
  33.         current_time = time.time()
  34.         img = pyautogui.screenshot()
  35.         frame = np.array(img)
  36.         frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  37.         out.write(frame)
  38.         cv2.imshow('Live', frame)
  39.  
  40.         if cv2.waitKey(1) == ord('q'):
  41.             break
  42.         # if current_time - start_time >  duration_in_seconds:
  43.         #     break
  44.  
  45.     out.release()
  46.     cv2.destroyAllWindows()
  47.  
  48.  
  49. if __name__ == '__main__':
  50.     cli()
  51.  
RAW Paste Data