letmaik / pyvirtualcam

🎥 Send frames to a virtual camera from Python
GNU General Public License v2.0
455 stars 49 forks source link

New sample: send video frames to virtual camera #9

Closed koratkar closed 3 years ago

koratkar commented 3 years ago

Thanks so much for writing this package!

letmaik commented 3 years ago

Thanks for your contribution, however I don't think it fits into the package as it can be easily done outside. I also wouldn't like introducing a new dependency (pillow) just for this feature. The package should have the minimal functionality possible to allow people to use it in different circumstances.

koratkar commented 3 years ago

That makes sense, could this code be helpful in the samples folder?

letmaik commented 3 years ago

Yeah definitely, that's a good idea.

letmaik commented 3 years ago

Are you still working on this?

koratkar commented 3 years ago

Yes, I just wrote a better one that can loop over video `import pyvirtualcam import numpy as np from numpy import asarray import cv2

path = 'PATH.mp4' video = cv2.VideoCapture(path) length = int(video.get(cv2.CAP_PROP_FRAME_COUNT)) count = 0 with pyvirtualcam.Camera(width=1280, height=720, fps=20) as cam: while True: if count == length: count = 0 video.set(1,count) s,frame = video.read() frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) array_frame = asarray(frame) frame = np.zeros((cam.height, cam.width, 4), np.uint8) frame[:,:,:3] = array_frame cam.send(frame) cam.sleep_until_next_frame() count = count + 1`

Sorry about delay

letmaik commented 3 years ago

That's a great sample, do you want to change your PR to use this then?