Skip to content

Commit bee2db7

Browse files
committed
Add --no-cache option
1 parent 0841e5c commit bee2db7

File tree

7 files changed

+51
-63
lines changed

7 files changed

+51
-63
lines changed

auto_editor/__main__.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ def main_options(parser: ArgumentParser) -> ArgumentParser:
140140
)
141141
parser.add_text("Utility Options:")
142142
parser.add_argument(
143-
"--export",
144-
"-ex",
145-
metavar="EXPORT:ATTRS?",
146-
help="Choose the export mode",
143+
"--export", "-ex", metavar="EXPORT:ATTRS?", help="Choose the export mode"
147144
)
148145
parser.add_argument(
149146
"--output-file",
@@ -153,15 +150,10 @@ def main_options(parser: ArgumentParser) -> ArgumentParser:
153150
help="Set the name/path of the new output file.",
154151
)
155152
parser.add_argument(
156-
"--player",
157-
"-p",
158-
metavar="CMD",
159-
help="Set player to open output media files",
153+
"--player", "-p", metavar="CMD", help="Set player to open output media files"
160154
)
161155
parser.add_argument(
162-
"--no-open",
163-
flag=True,
164-
help="Do not open the output file after editing is done",
156+
"--no-open", flag=True, help="Do not open the output file after editing is done"
165157
)
166158
parser.add_argument(
167159
"--temp-dir",
@@ -255,7 +247,7 @@ def main_options(parser: ArgumentParser) -> ArgumentParser:
255247
parser.add_argument(
256248
"--audio-normalize",
257249
metavar="NORM-TYPE",
258-
help="Apply audio rendering to all audio tracks. Applied right before rendering the output file.",
250+
help="Apply audio rendering to all audio tracks. Applied right before rendering the output file",
259251
)
260252
parser.add_text("Miscellaneous:")
261253
parser.add_argument(
@@ -268,6 +260,9 @@ def main_options(parser: ArgumentParser) -> ArgumentParser:
268260
metavar="CMD",
269261
help="Add extra options for ffmpeg. Must be in quotes",
270262
)
263+
parser.add_argument(
264+
"--no-cache", flag=True, help="Don't look for or write a cache file"
265+
)
271266
parser.add_argument("--version", "-V", flag=True, help="Display version and halt")
272267
return parser
273268

auto_editor/analyze.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class Levels:
175175
src: FileInfo
176176
tb: Fraction
177177
bar: Bar
178+
no_cache: bool
178179
temp: str
179180
log: Log
180181

@@ -210,6 +211,9 @@ def all(self) -> NDArray[np.bool_]:
210211
return np.zeros(self.media_length, dtype=np.bool_)
211212

212213
def read_cache(self, tag: str, obj: dict[str, Any]) -> None | np.ndarray:
214+
if self.no_cache:
215+
return None
216+
213217
workfile = os.path.join(
214218
os.path.dirname(self.temp), f"ae-{__version__}", "cache.npz"
215219
)
@@ -227,7 +231,10 @@ def read_cache(self, tag: str, obj: dict[str, Any]) -> None | np.ndarray:
227231
self.log.debug("Using cache")
228232
return npzfile[key]
229233

230-
def cache(self, tag: str, obj: dict[str, Any], arr: np.ndarray) -> np.ndarray:
234+
def cache(self, arr: np.ndarray, tag: str, obj: dict[str, Any]) -> np.ndarray:
235+
if self.no_cache:
236+
return arr
237+
231238
workdur = os.path.join(os.path.dirname(self.temp), f"ae-{__version__}")
232239
if not os.path.exists(workdur):
233240
os.mkdir(workdur)
@@ -268,7 +275,7 @@ def audio(self, stream: int) -> NDArray[np.float32]:
268275
index += 1
269276

270277
bar.end()
271-
return self.cache("audio", {"stream": stream}, result[:index])
278+
return self.cache(result[:index], "audio", {"stream": stream})
272279

273280
def motion(self, stream: int, blur: int, width: int) -> NDArray[np.float32]:
274281
if stream >= len(self.src.videos):
@@ -301,7 +308,7 @@ def motion(self, stream: int, blur: int, width: int) -> NDArray[np.float32]:
301308
index += 1
302309

303310
bar.end()
304-
return self.cache("motion", mobj, result[:index])
311+
return self.cache(result[:index], "motion", mobj)
305312

306313
def subtitle(
307314
self,

auto_editor/make_layers.py

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -71,44 +71,6 @@ def make_av(src: FileInfo, all_clips: list[list[Clip]]) -> tuple[VSpace, ASpace]
7171
return vtl, atl
7272

7373

74-
def run_interpreter_for_edit_option(
75-
text: str, filesetup: FileSetup
76-
) -> NDArray[np.bool_]:
77-
src = filesetup.src
78-
tb = filesetup.tb
79-
bar = filesetup.bar
80-
temp = filesetup.temp
81-
log = filesetup.log
82-
83-
try:
84-
parser = Parser(Lexer("`--edit`", text))
85-
if log.is_debug:
86-
log.debug(f"edit: {parser}")
87-
88-
env["timebase"] = tb
89-
env["@levels"] = Levels(src, tb, bar, temp, log)
90-
env["@filesetup"] = filesetup
91-
92-
results = interpret(env, parser)
93-
94-
if len(results) == 0:
95-
raise MyError("Expression in --edit must return a bool-array, got nothing")
96-
97-
result = results[-1]
98-
if callable(result):
99-
result = result()
100-
101-
if not is_boolarr(result):
102-
raise MyError(
103-
f"Expression in --edit must return a bool-array, got {print_str(result)}"
104-
)
105-
except MyError as e:
106-
log.error(e)
107-
108-
assert isinstance(result, np.ndarray)
109-
return result
110-
111-
11274
def make_sane_timebase(fps: Fraction) -> Fraction:
11375
tb = round(fps, 2)
11476

@@ -159,20 +121,43 @@ def make_timeline(
159121
except CoerceError as e:
160122
log.error(e)
161123

162-
method = args.edit_based_on
163-
164124
has_loud = np.array([], dtype=np.bool_)
165125
src_index = np.array([], dtype=np.int32)
166126
concat = np.concatenate
167127

168128
for i, src in enumerate(sources):
169129
filesetup = FileSetup(src, len(sources) < 2, tb, bar, temp, log)
170130

171-
edit_result = run_interpreter_for_edit_option(method, filesetup)
172-
mut_margin(edit_result, start_margin, end_margin)
131+
try:
132+
parser = Parser(Lexer("`--edit`", args.edit_based_on))
133+
if log.is_debug:
134+
log.debug(f"edit: {parser}")
135+
136+
env["timebase"] = tb
137+
env["@levels"] = Levels(src, tb, bar, args.no_cache, temp, log)
138+
env["@filesetup"] = filesetup
139+
140+
results = interpret(env, parser)
141+
142+
if len(results) == 0:
143+
log.error("Expression in --edit must return a bool-array, got nothing")
144+
145+
result = results[-1]
146+
if callable(result):
147+
result = result()
148+
except MyError as e:
149+
log.error(e)
150+
151+
if not is_boolarr(result):
152+
log.error(
153+
f"Expression in --edit must return a bool-array, got {print_str(result)}"
154+
)
155+
assert isinstance(result, np.ndarray)
156+
157+
mut_margin(result, start_margin, end_margin)
173158

174-
has_loud = concat((has_loud, edit_result))
175-
src_index = concat((src_index, np.full(len(edit_result), i, dtype=np.int32)))
159+
has_loud = concat((has_loud, result))
160+
src_index = concat((src_index, np.full(len(result), i, dtype=np.int32)))
176161

177162
# Setup for handling custom speeds
178163
speed_index = has_loud.astype(np.uint)

auto_editor/preview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def preview(tl: v3, temp: str, log: Log) -> None:
6565

6666
in_len = 0
6767
for src in all_sources:
68-
in_len += Levels(src, tb, Bar("none"), temp, log).media_length
68+
in_len += Levels(src, tb, Bar("none"), False, temp, log).media_length
6969

7070
out_len = tl.out_len()
7171

auto_editor/subcommands/levels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def main(sys_args: list[str] = sys.argv[1:]) -> None:
129129
except ParserError as e:
130130
log.error(e)
131131

132-
levels = Levels(src, tb, bar, temp, log)
132+
levels = Levels(src, tb, bar, False, temp, log)
133133
try:
134134
if method == "audio":
135135
print_arr_gen(iter_audio(src, tb, **obj))

auto_editor/subcommands/repl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def main(sys_args: list[str] = sys.argv[1:]) -> None:
6767
tb = src.get_fps() if args.timebase is None else args.timebase
6868
bar = Bar("modern")
6969
env["timebase"] = tb
70-
env["@levels"] = Levels(src, tb, bar, temp, log)
70+
env["@levels"] = Levels(src, tb, bar, False, temp, log)
7171
env["@filesetup"] = FileSetup(src, strict, tb, bar, temp, log)
7272

7373
print(f"Auto-Editor {auto_editor.__version__}")

auto_editor/utils/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def resolution(val: str | None) -> tuple[int, int] | None:
217217
return natural(vals[0]), natural(vals[1])
218218

219219

220-
@dataclass
220+
@dataclass(slots=True)
221221
class Args:
222222
yt_dlp_location: str = "yt-dlp"
223223
download_format: str | None = None
@@ -255,6 +255,7 @@ class Args:
255255
show_ffmpeg_output: bool = False
256256
quiet: bool = False
257257
preview: bool = False
258+
no_cache: bool = False
258259
margin: tuple[str, str] = ("0.2s", "0.2s")
259260
silent_speed: float = 99999.0
260261
video_speed: float = 1.0

0 commit comments

Comments
 (0)