Skip to content

Commit 7b90175

Browse files
committed
Add no-cache option to levels
1 parent 89f9f2c commit 7b90175

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

auto_editor/cmds/levels.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class LevelArgs:
3636
input: list[str] = field(default_factory=list)
3737
edit: str = "audio"
3838
timebase: Fraction | None = None
39+
no_cache: bool = False
3940
help: bool = False
4041

4142

@@ -53,16 +54,14 @@ def levels_options(parser: ArgumentParser) -> ArgumentParser:
5354
type=frame_rate,
5455
help="Set custom timebase",
5556
)
57+
parser.add_argument("--no-cache", flag=True)
5658
return parser
5759

5860

5961
def print_arr(arr: NDArray) -> None:
6062
print("")
6163
print("@start")
62-
if arr.dtype in {np.float64, np.float32, np.float16}:
63-
for a in arr:
64-
sys.stdout.write(f"{a:.20f}\n")
65-
elif arr.dtype == np.bool_:
64+
if arr.dtype == np.bool_:
6665
for a in arr:
6766
sys.stdout.write(f"{1 if a else 0}\n")
6867
else:
@@ -76,7 +75,7 @@ def print_arr_gen(arr: Iterator[float | np.float32]) -> None:
7675
print("")
7776
print("@start")
7877
for a in arr:
79-
print(f"{a:.20f}")
78+
print(f"{a}")
8079
print("")
8180

8281

@@ -131,7 +130,7 @@ def main(sys_args: list[str] = sys.argv[1:]) -> None:
131130
levels = initLevels(src, tb, bar, False, log)
132131
try:
133132
if method == "audio":
134-
if (arr := levels.read_cache("audio", (obj["stream"],))) is not None:
133+
if not args.no_cache and (arr := levels.read_cache("audio", (obj["stream"],))) is not None:
135134
print_arr(arr)
136135
else:
137136
container = bv.open(src.path, "r")
@@ -148,11 +147,12 @@ def value_storing_generator() -> Iterator[np.float32]:
148147
container.close()
149148

150149
cache_array = np.array(values, dtype=np.float32)
151-
levels.cache(cache_array, "audio", (obj["stream"],))
150+
if not args.no_cache:
151+
levels.cache(cache_array, "audio", (obj["stream"],))
152152

153153
elif method == "motion":
154154
mobj = (obj["stream"], obj["width"], obj["blur"])
155-
if (arr := levels.read_cache("motion", mobj)) is not None:
155+
if not args.no_cache and (arr := levels.read_cache("motion", mobj)) is not None:
156156
print_arr(arr)
157157
else:
158158
container = bv.open(src.path, "r")
@@ -171,7 +171,8 @@ def value_storing_generator() -> Iterator[np.float32]:
171171
container.close()
172172

173173
cache_array = np.array(values, dtype=np.float32)
174-
levels.cache(cache_array, "motion", mobj)
174+
if not args.no_cache:
175+
levels.cache(cache_array, "motion", mobj)
175176

176177
elif method == "subtitle":
177178
print_arr(levels.subtitle(**obj))

0 commit comments

Comments
 (0)