Spaces:
Runtime error
Runtime error
File size: 1,334 Bytes
a22e84b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import subprocess
from pathlib import Path
class VideoClipper:
@staticmethod
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
|