Spaces:
Sleeping
Sleeping
File size: 1,055 Bytes
bd65e34 |
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 |
from pathlib import Path
from typing import Dict, List
from moviepy.editor import VideoFileClip, concatenate_videoclips
def get_vid_path(
orig_vid: str | Path, timestamps: List[Dict[str, str]], out: Path
) -> Path:
out.mkdir(parents=True, exist_ok=True)
vid_name = Path(orig_vid).name
out_path = out / (vid_name + f"_{hash(str(timestamps))}.mp4")
return out_path
def build_video(orig_vid: str | Path, timestamps: List[Dict[str, str]], out_path: Path):
# timestamps = [{"start": "00:01:23", "end": "00:02:45"}]
if out_path.exists():
return out_path
video_clips = []
video = VideoFileClip(orig_vid)
# Extract video clips for each timestamp event
for timestamp in timestamps:
clip = video.subclip(timestamp["start"], timestamp["end"])
video_clips.append(clip)
# Concatenate the video clips with transitions
final_clip = concatenate_videoclips(video_clips)
# Write the final concatenated movie to a file
final_clip.write_videofile(str(out_path))
return out_path
|