Spaces:
Runtime error
Runtime error
Download app.py from shin0624/Cutting_Video_Function_All_Frame: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/shin0624/Cutting_Video_Function_All_Frame/resolve/main/app.py
- Command line
-
hf download hf://spaces/shin0624/Cutting_Video_Function_All_Frame/app.py
-
curl -L -o app.py https://huggingface.co/spaces/shin0624/Cutting_Video_Function_All_Frame/resolve/main/app.py
1.21 kB
| # -*- coding: utf-8 -*- | |
| # SPDX-License-Identifier: MIT | |
| # Copyright (c) 2024 [shin0624] | |
| import gradio as gr | |
| import cv2 | |
| import tempfile | |
| import zipfile | |
| from pathlib import Path | |
| def extract_frames(video_file): | |
| temp_dir = tempfile.mkdtemp() | |
| frames_dir = Path(temp_dir) / "frames" | |
| frames_dir.mkdir(exist_ok=True) | |
| cap = cv2.VideoCapture(video_file) | |
| frame_count = 0 | |
| while cap.isOpened(): | |
| ret, frame = cap.read() | |
| if not ret: | |
| break | |
| frame_path = frames_dir / f"frame_{frame_count:05d}.png" | |
| cv2.imwrite(str(frame_path), frame) | |
| frame_count += 1 | |
| cap.release() | |
| zip_path = Path(temp_dir) / "frames.zip" | |
| with zipfile.ZipFile(zip_path, 'w') as zipf: | |
| for frame_file in frames_dir.glob("*.png"): | |
| zipf.write(frame_file, arcname=frame_file.name) | |
| return str(zip_path) | |
| demo = gr.Interface( | |
| fn=extract_frames, | |
| inputs=gr.Video(label="λμμ μ λ‘λ"), | |
| outputs=gr.File(label="νλ μ ZIP νμΌ"), | |
| title="νλ μ μΆμΆκΈ° (ZIP)", | |
| description="λμμμ μ λ‘λνλ©΄ λͺ¨λ νλ μμ PNGλ‘ μ μ₯νμ¬ ZIP νμΌλ‘ μ 곡ν©λλ€." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |