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
2
2
3
3
4
4
class ToolBar :
Original file line number Diff line number Diff line change 3
3
from multiprocessing import Queue , Process
4
4
from time import time
5
5
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
12
17
13
18
14
19
class VideoWriterAV (Process ):
@@ -28,6 +33,7 @@ def __init__(
28
33
super ().__init__ ()
29
34
self .queue = queue
30
35
36
+ av = _get_av ()
31
37
self .container = av .open (path , mode = "w" )
32
38
33
39
self .stream = self .container .add_stream (codec , rate = fps , options = options )
@@ -45,6 +51,7 @@ def __init__(
45
51
self .stream .pix_fmt = pixel_format
46
52
47
53
def run (self ):
54
+ av = _get_av ()
48
55
while True :
49
56
if self .queue .empty (): # no frame to write
50
57
continue
@@ -177,12 +184,6 @@ def record_start(
177
184
178
185
"""
179
186
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
-
186
187
if Path (path ).exists ():
187
188
raise FileExistsError (f"File already exists at given path: { path } " )
188
189
You can’t perform that action at this time.
0 commit comments