Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macos webcam #738

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions imageio/plugins/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,6 @@ def _open(
regex_match = re.match(r"<video(\d+)>", self.request.filename)
if regex_match:
self.request._video = self.request.filename
# Specify input framerate? (only on macOS)
if self.request._video and platform.system().lower() == "darwin":
if "-framerate" not in str(self._arg_input_params):
self._arg_input_params.extend(["-framerate", str(float(fps or 15))])
# Get local filename
if self.request._video:
index = int(regex_match.group(1))
Expand Down Expand Up @@ -334,8 +330,29 @@ def _open(
self._nframes = self.count_frames()
self._meta["nframes"] = self._nframes

# Specify input framerate? (only on macOS)
# Ideally we'd get the supported framerate from the metadata, but we get the
# metadata when we boot ffmpeg ... maybe we could refactor this so we can
# get the metadata beforehand, but for now we'll just give it 2 tries on MacOS,
# one with fps 30 and one with fps 15.
need_fps = (
self.request._video
and platform.system().lower() == "darwin"
and "-framerate" not in str(self._arg_input_params)
)
if need_fps:
self._arg_input_params.extend(["-framerate", str(float(30))])

# Start ffmpeg subprocess and get meta information
self._initialize()
try:
self._initialize()
except IndexError:
# Specify input framerate again, this time different.
if need_fps:
self._arg_input_params[-1] = str(float(15))
self._initialize()
else:
raise

# For cameras, create thread that keeps reading the images
if self.request._video:
Expand Down