what can i do to improve my video quality in opencv

Viewed 2626

I am creating a python program to record my desktop screen.

But the output of this code is in very low quality and blurry.

Can anyone help me in capturing (screen capturing) in high quality.

Like the screen recorder like OBS studio and Camtasia do.

what can i do improve my quality change my extention ,codec ,etc. please mention.

import cv2
import numpy as np
import datetime
from PIL import Image, ImageTk, ImageGrab

date = datetime.datetime.now()
filename='rec_%s-%s-%s-%s%s%s.mp4' % (date.year, date.month, date.day,
                                                     date.hour, date.minute, date.second)

fourcc = cv2.VideoWriter_fourcc(*'X264')
frame_rate = 16
SCREEN_SIZE = (960,540)
out = cv2.VideoWriter(filename, fourcc,framerate, SCREEN_SIZE)

while True:
        img = ImageGrab.grab()
        frame = np.array(img)

        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        out.write(frame)
        cv2.imshow('screenshot', frame)

        if cv2.waitKey(1) == ord("q"):
            break
cv2.destroyAllWindows()
out.release()
1 Answers

frame_rate = 16

SCREEN_SIZE = (960,540)

Both of this are too low, you probably want your frame_rate to be 30, and your screen size to be 1920x1080p.

Also just has an extra info: .mp4 is a bad format for screen recording, I know OBS recommended using .flv because it doesn't corrupt the whole file if the recording end abruptly, unlike .mp4.

Related