Download code/tools/prepare_clip.py from MRBSTUDIO/AGT: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/MRBSTUDIO/AGT/resolve/main/code/tools/prepare_clip.py
- Command line
-
hf download hf://MRBSTUDIO/AGT/code/tools/prepare_clip.py
-
curl -L -o prepare_clip.py https://huggingface.co/MRBSTUDIO/AGT/resolve/main/code/tools/prepare_clip.py
1.72 kB
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import sys | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from agt.prepare.video_clip import export_clips | |
| def main(argv=None): | |
| p = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter) | |
| src = p.add_mutually_exclusive_group(required=True) | |
| src.add_argument("--video", type=Path, help="video file (any format PyAV decodes)") | |
| src.add_argument("--frames", type=Path, help="directory of .jpg/.png frames, sorted by name") | |
| src.add_argument("--list", type=Path, help="JSON list of clips") | |
| p.add_argument("--fps", type=float, help="frame rate of --frames") | |
| p.add_argument("--start", type=float, default=0.0, help="window start in seconds") | |
| p.add_argument("--clip-id", default=None, help="default: <source name>_s<start in ms>") | |
| p.add_argument("--out", type=Path, required=True, help="new export directory") | |
| p.add_argument("--allow-failures", action="store_true", help="keep going when a clip cannot be cut") | |
| args = p.parse_args(argv) | |
| if args.list: | |
| entries = json.loads(args.list.read_text()) | |
| elif args.frames: | |
| if args.fps is None: | |
| p.error("--frames needs --fps") | |
| entries = [{"frames_dir": str(args.frames), "fps": args.fps, "window_start_s": args.start, "clip_id": args.clip_id}] | |
| else: | |
| entries = [{"video_path": str(args.video), "window_start_s": args.start, "clip_id": args.clip_id}] | |
| manifest = export_clips(args.out, entries, args.allow_failures) | |
| print(json.dumps({"clips": len(manifest["clips"]), "failures": len(manifest["failures"])})) | |
| if __name__ == "__main__": | |
| main() | |