2020-12-27 04:56:43 +00:00
|
|
|
from multiprocessing.managers import BaseManager
|
2021-04-12 23:23:48 +00:00
|
|
|
|
2021-01-09 20:37:01 +00:00
|
|
|
try:
|
|
|
|
from tqdm import tqdm
|
|
|
|
except ImportError:
|
2021-01-10 04:11:34 +00:00
|
|
|
tqdm = None
|
2021-01-09 20:37:01 +00:00
|
|
|
|
2020-12-27 04:56:43 +00:00
|
|
|
|
|
|
|
def Manager():
|
|
|
|
"""
|
|
|
|
Thread save manager for frame counter
|
|
|
|
"""
|
|
|
|
m = BaseManager()
|
|
|
|
m.start()
|
|
|
|
return m
|
|
|
|
|
|
|
|
|
|
|
|
class Counter:
|
|
|
|
"""
|
2020-12-27 05:49:31 +00:00
|
|
|
Frame Counter
|
2020-12-27 04:56:43 +00:00
|
|
|
"""
|
2021-04-12 23:23:48 +00:00
|
|
|
|
2020-12-27 05:49:31 +00:00
|
|
|
def __init__(self, total, initial, use_tqdm=True):
|
2020-12-27 04:56:43 +00:00
|
|
|
self.first_update = True
|
|
|
|
self.initial = initial
|
|
|
|
self.left = total - initial
|
2020-12-27 05:49:31 +00:00
|
|
|
self.current = 0
|
2021-04-12 23:23:48 +00:00
|
|
|
self.use_tqdm = use_tqdm and (tqdm is not None)
|
2020-12-27 05:49:31 +00:00
|
|
|
if use_tqdm:
|
2021-04-12 23:23:48 +00:00
|
|
|
self.tqdm_bar = tqdm(
|
|
|
|
total=self.left,
|
|
|
|
initial=0,
|
|
|
|
dynamic_ncols=True,
|
|
|
|
unit="fr",
|
|
|
|
leave=True,
|
|
|
|
smoothing=0.01,
|
|
|
|
)
|
2020-12-27 04:56:43 +00:00
|
|
|
|
|
|
|
def update(self, value):
|
2020-12-27 05:49:31 +00:00
|
|
|
if self.use_tqdm:
|
|
|
|
if self.first_update:
|
|
|
|
self.tqdm_bar.reset(self.left)
|
|
|
|
self.first_update = False
|
|
|
|
self.tqdm_bar.update(value)
|
|
|
|
else:
|
|
|
|
self.current += value
|
2020-12-27 04:56:43 +00:00
|
|
|
|
|
|
|
def close(self):
|
2021-01-09 20:37:01 +00:00
|
|
|
if self.use_tqdm:
|
|
|
|
self.tqdm_bar.close()
|
2020-12-27 04:56:43 +00:00
|
|
|
|
2020-12-27 05:49:31 +00:00
|
|
|
def get_frames(self):
|
|
|
|
return self.current
|