File tree Expand file tree Collapse file tree 2 files changed +14
-13
lines changed
Expand file tree Collapse file tree 2 files changed +14
-13
lines changed Original file line number Diff line number Diff line change 1- from fastplotlib . layouts ._subplot import Subplot
1+ from . ._subplot import Subplot
22
33
44class ToolBar :
Original file line number Diff line number Diff line change 33from multiprocessing import Queue , Process
44from time import time
55
6- try :
7- import av
8- except ImportError :
9- HAS_AV = False
10- else :
11- HAS_AV = True
6+
7+ def _get_av ():
8+ try :
9+ import av
10+ except ImportError :
11+ raise ModuleNotFoundError (
12+ "Recording to video file requires `av`:\n "
13+ "https://github.com/PyAV-Org/PyAV"
14+ ) from None
15+ else :
16+ return av
1217
1318
1419class VideoWriterAV (Process ):
@@ -28,6 +33,7 @@ def __init__(
2833 super ().__init__ ()
2934 self .queue = queue
3035
36+ av = _get_av ()
3137 self .container = av .open (path , mode = "w" )
3238
3339 self .stream = self .container .add_stream (codec , rate = fps , options = options )
@@ -45,6 +51,7 @@ def __init__(
4551 self .stream .pix_fmt = pixel_format
4652
4753 def run (self ):
54+ av = _get_av ()
4855 while True :
4956 if self .queue .empty (): # no frame to write
5057 continue
@@ -177,12 +184,6 @@ def record_start(
177184
178185 """
179186
180- if not HAS_AV :
181- raise ModuleNotFoundError (
182- "Recording to video file requires `av`:\n "
183- "https://github.com/PyAV-Org/PyAV"
184- )
185-
186187 if Path (path ).exists ():
187188 raise FileExistsError (f"File already exists at given path: { path } " )
188189
You can’t perform that action at this time.
0 commit comments