Skip to content

854 * 480 resolution causes "pixel buffer size mismatch" on macOS #110

@agilebean

Description

@agilebean
  • Operating system: MacOS Venture 13.5
  • Python version: 3.8
  • pyvirtualcam version: 0.10.2
  • Virtual camera (OBS, v4l2loopback, UnityCapture): OBS
  • Virtual camera version: 29.1.3

Describe the bug
...
Running a python script sending frames from a video which has worked perfectly one year ago. The same script keeps on throwing the error

pixel buffer size mismatch

Notes:

  1. This happened no matter which color conversion was done (*any combination).
  2. cv2.imshow() works perfectly.
  3. OBS Studio works perfectly, i.e. sends the same video to a virtual cam which can be seen in Google Meet or Zoom.

To Reproduce
Trying to run from this repository the example script webcam_filter.py

import logging
import argparse
import pyvirtualcam
from pyvirtualcam import PixelFormat
import cv2

parser = argparse.ArgumentParser()
parser.add_argument("--video_path", help="path to input video file", default="video/dicaprio1-silent_rgb.mp4")
parser.add_argument("--fps", action="store_true", help="output fps every second")
parser.add_argument("--device", help="virtual camera device, e.g. /dev/video0 (optional)")
args = parser.parse_args()

print(args.video_path)

video = cv2.VideoCapture(args.video_path)
if not video.isOpened():
    raise ValueError("error opening video")
length = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = video.get(cv2.CAP_PROP_FPS)

print(f"width {width} height{height}")

with pyvirtualcam.Camera(width=width, height=height, fps=fps, fmt=PixelFormat.BGR,
                         device=args.device) as cam:

    print(f'Virtual cam started: {cam.device} ({cam.width}x{cam.height} @ {cam.fps}fps)')
    # Set the resolution of the virtual camera


    count = 0
    while True:
        # Restart video on last frame.
        if count == length:
            count = 0
            video.set(cv2.CAP_PROP_POS_FRAMES, 0)

        # Read video frame.
        ret, frame = video.read()
        if not ret:
            raise RuntimeError('Error fetching frame')

        cv2.imshow('frame: ', frame)
        # frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        # frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) # UVYV

        # Send to virtual cam.
        cam.send(frame)

        # Wait until it's time for the next frame
        cam.sleep_until_next_frame()

        count += 1
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededmacOSThis issue appears on macOS

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions