Complete Screen Recorder in Python
import cv2
import sys
from PIL import ImageGrab
import numpy as np
resolution = ImageGrab.grab()
width,height=resolution.size
forcc = cv2.VideoWriter_fourcc("m","p","4","v")
capture_video =cv2.VideoWriter("output.mp4",forcc,5.5,(width,height))
try:
while True:
img = ImageGrab.grab(bbox=(0,0,width,height))
img_np = np.array(img)
img_final =cv2.cvtColor(img_np,cv2.COLOR_BGR2RGB)
#cv2.imshow("screen recorder",img_final)q
capture_video.write(img_final)
print("recording....")
except KeyboardInterrupt:
print("stoped recording!")
sys.exit()
# Break second method
import cv2
import sys
from PIL import ImageGrab
import keyboard
import numpy as np
resolution = ImageGrab.grab()
width,height=resolution.size
forcc = cv2.VideoWriter_fourcc(*"mp4v")
capture_video =cv2.VideoWriter("output.mp4",forcc,5.5,(width,height))
while True:
img = ImageGrab.grab(bbox=(0,0,width,height))
img_np = np.array(img)
img_final =cv2.cvtColor(img_np,cv2.COLOR_BGR2RGB)
#cv2.imshow("screen recorder",img_final)
capture_video.write(img_final)
print("recording....")
if keyboard.is_pressed("q"):
break
cv2.destroyAllWindows()
capture_video.release()
Comments
Post a Comment