-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_decode.py
52 lines (35 loc) · 1.33 KB
/
run_decode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import sys
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from typing import List
from simple_parsing import choice, field, ArgumentParser
from tqdm import tqdm
from utils import read_frames_with_time, cal_fps_from_tqdm
@dataclass
class Args:
run_mode: str = choice("sync", "multi", alias=["-rm"], default="sync")
n_stream: int = field(alias=["-n"], default=os.cpu_count())
duration: int = field(alias=["-t"], default=60)
def sync_decode(args: Args) -> None:
with tqdm(unit="frame") as pbar:
for frame in read_frames_with_time(args.duration):
pbar.update(1)
cal_fps_from_tqdm(pbar)
def multi_decode(args: Args) -> None:
with tqdm(unit="frame") as pbar:
def decode_stream(thread_id: int):
for frame in read_frames_with_time(args.duration):
pbar.update(1)
with ThreadPoolExecutor(args.n_stream) as pool:
for i in range(args.n_stream):
pool.submit(decode_stream, i)
cal_fps_from_tqdm(pbar)
def main(args: Args) -> None:
globals()[f"{args.run_mode}_decode"](args)
def parse_args(args: List[str]):
parser = ArgumentParser()
parser.add_arguments(Args, dest="arguments")
return parser.parse_args(args).arguments
if __name__ == '__main__':
main(parse_args(sys.argv[1:]))