Spaces:
Runtime error
Runtime error
import subprocess | |
from pathlib import Path | |
class VideoClipper: | |
def create_clip(video_path: Path, start: float, end: float, output_path: Path): | |
# Try to find ffmpeg in common locations | |
ffmpeg_cmd = None | |
for cmd in ["ffmpeg", "/usr/local/bin/ffmpeg", "/usr/bin/ffmpeg", "/opt/homebrew/bin/ffmpeg"]: | |
try: | |
# Check if the command exists | |
subprocess.run([cmd, "-version"], capture_output=True, check=True) | |
ffmpeg_cmd = cmd | |
break | |
except (subprocess.SubprocessError, FileNotFoundError): | |
continue | |
if not ffmpeg_cmd: | |
raise FileNotFoundError("ffmpeg not found in PATH. Please install ffmpeg to create video clips.") | |
cmd = [ | |
ffmpeg_cmd, | |
"-ss", str(start), | |
"-to", str(end), | |
"-i", str(video_path), | |
"-c", "copy", | |
str(output_path) | |
] | |
try: | |
subprocess.run(cmd, check=True, capture_output=True) | |
except subprocess.CalledProcessError as e: | |
print("Error creating clip: {}".format(e)) | |
if hasattr(e, 'stderr') and e.stderr: | |
print("FFmpeg error: {}".format(e.stderr)) | |
raise | |