Skip to content

Lazy import av #432

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

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion fastplotlib/layouts/_frame/_toolbar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastplotlib.layouts._subplot import Subplot
from .._subplot import Subplot


class ToolBar:
Expand Down
25 changes: 13 additions & 12 deletions fastplotlib/layouts/_record_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
from multiprocessing import Queue, Process
from time import time

try:
import av
except ImportError:
HAS_AV = False
else:
HAS_AV = True

def _get_av():
try:
import av
except ImportError:
raise ModuleNotFoundError(
"Recording to video file requires `av`:\n"
"https://github.com/PyAV-Org/PyAV"
) from None
else:
return av


class VideoWriterAV(Process):
Expand All @@ -28,6 +33,7 @@ def __init__(
super().__init__()
self.queue = queue

av = _get_av()
self.container = av.open(path, mode="w")

self.stream = self.container.add_stream(codec, rate=fps, options=options)
Expand All @@ -45,6 +51,7 @@ def __init__(
self.stream.pix_fmt = pixel_format

def run(self):
av = _get_av()
while True:
if self.queue.empty(): # no frame to write
continue
Expand Down Expand Up @@ -177,12 +184,6 @@ def record_start(

"""

if not HAS_AV:
raise ModuleNotFoundError(
"Recording to video file requires `av`:\n"
"https://github.com/PyAV-Org/PyAV"
)

if Path(path).exists():
raise FileExistsError(f"File already exists at given path: {path}")

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy