Skip to content

Commit d613d5e

Browse files
committed
workspace path setting for videos
1 parent 9187340 commit d613d5e

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

interactive_demo_onnx.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import signal
44
import sys
55
from argparse import ArgumentParser
6+
from hashlib import sha1
67
from pathlib import Path
78

89
if "QT_QPA_PLATFORM_PLUGIN_PATH" not in os.environ:
@@ -103,6 +104,39 @@ def resolve_runtime_path(raw_path: str) -> str:
103104
return raw_path
104105

105106

107+
def default_workspace_root() -> Path:
108+
return Path.home() / "scutie"
109+
110+
111+
def sha1_file(path: Path, chunk_size: int = 1024 * 1024) -> str:
112+
digest = sha1()
113+
with path.open("rb") as handle:
114+
while True:
115+
chunk = handle.read(chunk_size)
116+
if not chunk:
117+
break
118+
digest.update(chunk)
119+
return digest.hexdigest()
120+
121+
122+
def resolve_workspace(args) -> str | None:
123+
if args.workspace is not None:
124+
return args.workspace
125+
126+
workspace_root = default_workspace_root()
127+
workspace_root.mkdir(parents=True, exist_ok=True)
128+
129+
if args.video is not None:
130+
video_path = Path(args.video).expanduser().resolve()
131+
return str(workspace_root / sha1_file(video_path))
132+
133+
if args.images is not None:
134+
images_path = Path(args.images).expanduser().resolve()
135+
return str(workspace_root / images_path.name)
136+
137+
return None
138+
139+
106140
if __name__ in "__main__":
107141
args = get_arguments()
108142

@@ -133,6 +167,9 @@ def resolve_runtime_path(raw_path: str) -> str:
133167

134168
args.device = resolve_device(args.device)
135169
log.info(f"Using ONNX Runtime device: {args.device}")
170+
args.video = resolve_runtime_path(args.video) if args.video is not None else None
171+
args.images = resolve_runtime_path(args.images) if args.images is not None else None
172+
args.workspace = resolve_workspace(args)
136173

137174
args_dict = vars(args)
138175
for key in ("onnx_encoder", "onnx_memory_write", "onnx_read_decode", "ritm_onnx"):

0 commit comments

Comments
 (0)