EdgeTAM / trimm_examples.py
chongzhou's picture
rollback sam2_base and sam2_video_predictor
3ccde9c
raw
history blame contribute delete
925 Bytes
import os
from moviepy.editor import VideoFileClip
# Define the folder and duration
input_folder = "examples"
output_folder = "examples/trimmed"
trim_duration = 3 # seconds
# Create output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
# Process each .mp4 file
for filename in os.listdir(input_folder):
if filename.lower().endswith(".mp4"):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, filename)
print(f"Trimming: {input_path} -> {output_path}")
try:
clip = VideoFileClip(input_path).subclip(0, trim_duration)
clip.write_videofile(
output_path,
codec="libx264",
audio_codec="aac",
verbose=False,
logger=None,
)
except Exception as e:
print(f"Failed to process {filename}: {e}")