moviepy

使用 MoviePy(2.x)通过 Python 编辑与合成视频。适用于以编程方式编辑视频、创建蒙太奇、添加文字叠加、构建自动化视频流水线、合成多个片段、应用特效、从模板生成社交媒体视频、拼接片段、提取音频、创建 GIF、制作幻灯片、添加转场、调整大小和裁剪或将视频编辑功能集成到 Python 应用程序中的场景,涵盖 MoviePy 2.x 的合成、特效、文字处理和渲染功能。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
7

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "moviepy":https://skillpi.com/zh/skills/deepskill-c034adcde843c442677c56cbdaabbc1f53c1a7812335bb4c6c8a4b7487dfd4d7。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

使用 MoviePy(2.x)通过 Python 编辑与合成视频。适用于以编程方式编辑视频、创建蒙太奇、添加文字叠加、构建自动化视频流水线、合成多个片段、应用特效、从模板生成社交媒体视频、拼接片段、提取音频、创建 GIF、制作幻灯片、添加转场、调整大小和裁剪或将视频编辑功能集成到 Python 应用程序中的场景,涵盖 MoviePy 2.x 的合成、特效、文字处理和渲染功能。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: moviepy
description: >-
  Edit and compose video with Python using MoviePy. Use when a user asks to
  programmatically edit videos, create video montages, add text overlays, build
  automated video pipelines, composite multiple clips, apply video effects,
  generate social media videos from templates, concatenate clips, extract audio,
  create GIFs, build slideshows, add transitions, resize and crop videos, or
  integrate video editing into Python applications. Covers MoviePy 2.x for
  compositing, effects, text, and rendering.
license: Apache-2.0
compatibility: 'Python 3.8+, ffmpeg required'
metadata:
  author: terminal-skills
  version: 1.0.0
  category: content
  tags:
    - moviepy
    - python
    - video-editing
    - compositing
    - automation

MoviePy

Overview

Edit video programmatically with MoviePy — the Python library for video compositing, cutting, effects, and rendering. Ideal for automated video pipelines: social media content generation, bulk video processing, slideshow builders, subtitle embedding, template-based video creation, and any workflow where you need code-driven video editing without a GUI. Built on ffmpeg.

Instructions

Step 1: Installation

pip install moviepy
apt install -y ffmpeg         # Ubuntu/Debian
# Optional for text: apt install -y imagemagick
# Or: pip install Pillow (MoviePy v2.x uses PIL for text)

Step 2: Basic Operations

from moviepy import VideoFileClip, AudioFileClip

clip = VideoFileClip("input.mp4")
print(f"Duration: {clip.duration}s, Size: {clip.size}, FPS: {clip.fps}")

trimmed = clip.subclipped(10, 60)            # 10s to 60s
resized = clip.resized(height=720)            # Maintain aspect ratio
resized = clip.resized((1080, 1920))          # Force size
cropped = clip.cropped(x1=100, y1=50, x2=1820, y2=1030)
fast = clip.with_speed_scaled(2.0)            # 2x speed
silent = clip.without_audio()

trimmed.write_videofile("output.mp4", fps=24, codec="libx264",
    audio_codec="aac", bitrate="5000k", preset="medium", threads=4)
clip.subclipped(5, 10).write_gif("output.gif", fps=15)
clip.close()

Step 3: Concatenation & Composition

from moviepy import VideoFileClip, concatenate_videoclips, CompositeVideoClip, ColorClip

# Concatenate clips sequentially
final = concatenate_videoclips([
    VideoFileClip("scene1.mp4"),
    VideoFileClip("scene2.mp4"),
    VideoFileClip("scene3.mp4"),
])

# Composite (overlay layers)
bg = ColorClip(size=(1920, 1080), color=(15, 23, 42), duration=10)
main = VideoFileClip("main.mp4").resized(height=800).with_position("center")
logo = (VideoFileClip("logo.png", duration=10)
        .resized(height=60).with_position((1820, 30)))

composite = CompositeVideoClip([bg, main, logo], size=(1920, 1080))
composite.write_videofile("composite.mp4", fps=30)

Step 4: Text Overlays

from moviepy import TextClip, CompositeVideoClip, VideoFileClip

video = VideoFileClip("input.mp4")
title = (TextClip(text="Episode 1: Getting Started",
                  font_size=60, color="white", font="Arial-Bold",
                  stroke_color="black", stroke_width=2)
         .with_duration(5).with_position("center").with_start(1))

subtitle = (TextClip(text="Welcome to the show",
                     font_size=36, color="white", bg_color="rgba(0,0,0,128)")
            .with_duration(4).with_position(("center", 900))
            .with_start(3).crossfadein(0.5).crossfadeout(0.5))

final = CompositeVideoClip([video, title, subtitle])
final.write_videofile("titled.mp4")

Step 5: Audio Operations

from moviepy import VideoFileClip, AudioFileClip, CompositeAudioClip

video = VideoFileClip("input.mp4")
video.audio.write_audiofile("extracted.mp3")

# Mix audio tracks
original = video.audio.with_volume_scaled(0.3)
music = AudioFileClip("bg_music.mp3").with_volume_scaled(0.15)
voiceover = AudioFileClip("narration.mp3")
mixed = CompositeAudioClip([original, music, voiceover])
final = video.with_audio(mixed)
final.write_videofile("mixed.mp4")

Step 6: Effects & Custom Filters

from moviepy import VideoFileClip, vfx

clip = VideoFileClip("input.mp4")
clip.with_effects([vfx.MirrorX()])           # Mirror horizontally
clip.with_effects([vfx.BlackAndWhite()])      # Grayscale
clip.with_effects([vfx.FadeIn(1), vfx.FadeOut(2)])

# Custom frame-by-frame effect
def add_vignette(frame):
    import numpy as np
    rows, cols = frame.shape[:2]
    X, Y = np.meshgrid(np.arange(cols) - cols/2, np.arange(rows) - rows/2)
    mask = 1 - np.clip(np.sqrt(X**2 + Y**2) / (max(rows, cols) * 0.5), 0, 1)
    return (frame * mask[:, :, np.newaxis] ** 1.5).astype("uint8")

vignetted = clip.image_transform(add_vignette)

Step 7: Batch Processing

import os
from moviepy import VideoFileClip, TextClip, CompositeVideoClip

def process_video(input_path, output_path, watermark_text="@mychannel"):
    clip = VideoFileClip(input_path).resized(height=1080)
    watermark = (TextClip(text=watermark_text, font_size=24, color="white")
                 .with_opacity(0.5).with_duration(clip.duration).with_position((20, 20)))
    final = CompositeVideoClip([clip, watermark])
    final.write_videofile(output_path, fps=clip.fps, codec="libx264",
                          audio_codec="aac", preset="fast", threads=4)
    clip.close()

input_dir, output_dir = "raw_videos", "processed"
os.makedirs(output_dir, exist_ok=True)
for f in os.listdir(input_dir):
    if f.endswith((".mp4", ".mov", ".avi")):
        process_video(os.path.join(input_dir, f),
                      os.path.join(output_dir, f.rsplit(".", 1)[0] + ".mp4"))

Examples

Example 1: Generate 30 Instagram story videos from a JSON config

User prompt: "I have a products.json file with 30 entries, each containing name, price, tagline, and image_path. Write a Python script that generates a 1080x1920 Instagram story for each product with the product image as background, name in bold white at the top, price in green, and tagline at the bottom with a fade-in."

The agent will write a script that loads products.json, iterates over each entry, creates a ColorClip background at 1080x1920, loads the product image and resizes it to fill the frame, creates TextClip layers for the name (72px, bold, top), price (56px, green #22c55e, center), and tagline (36px, bottom with crossfadein(0.5)), composites them with CompositeVideoClip, renders each to stories/{name}.mp4 at 30fps, and closes all clips.

Example 2: Concatenate interview clips with title cards and background music

User prompt: "I have 5 interview clips in /footage/ named q1.mp4 through q5.mp4. Create a script that puts a 3-second dark title card with white text before each clip showing 'Question 1' through 'Question 5', concatenates everything, adds background music from ambient.mp3 at 20% volume, and exports as interview_final.mp4."

The agent will write a script that builds title cards using ColorClip with dark background and TextClip for each question number, loads each interview clip with VideoFileClip, interleaves title cards and clips into a list, concatenates with concatenate_videoclips, loads ambient.mp3 as an AudioFileClip trimmed to the total duration at 20% volume, mixes it with the original audio using CompositeAudioClip, and writes the final video.

Guidelines

  • Always call clip.close() after writing output to free ffmpeg processes and file handles, especially in batch loops
  • MoviePy 2.x changed many method names from 1.x; use subclipped() not subclip(), resized() not resize(), with_position() not set_position()
  • Set threads=4 or higher in write_videofile() for multi-core encoding, and use preset="fast" for batch jobs where speed matters more than file size
  • For text rendering, MoviePy 2.x uses Pillow by default; install ImageMagick only if you need the method="caption" word-wrapping feature
  • Large batch jobs can exhaust RAM since each clip keeps decoded frames in memory; process one clip at a time and close it before starting the next

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值95/100

亮点

  • 提供完整的自动化视频编辑流水线能力,覆盖批量处理、特效合成、模板生成等高价值场景
  • 适用于社交媒体内容生成、访谈剪辑、产品展示等多种实际业务需求
触发精准95/100

亮点

  • 触发词覆盖全面,包含 programmatically edit, montages, overlays, automation, compositing, effects, templates, GIFs, slideshows, transitions, resize/crop, integration 等关键场景
  • 边界清晰,无与其他视频工具混淆风险
结构规范95/100

待提升项

  • 缺少显式 When to Use 章节 原报告严重程度:轻微

    文档未设置独立 'When to Use' 章节标题,虽 description 已覆盖相关内容

    改进建议:建议增加显式 'When to Use' 章节以提升可读性

亮点

  • 结构清晰,分 7 个逻辑步骤从安装到高级批量处理
  • 每个步骤均含完整可运行代码示例
  • 提供两个端到端用户场景示例(Instagram stories, interview concatenation)
  • frontmatter 完整,包含兼容性、许可证、元数据等信息
执行可靠95/100

亮点

  • 明确依赖管理(pip + ffmpeg + Pillow/ImageMagick 可选)
  • 关键资源释放指导(clip.close() 防止内存泄漏)
  • 批量处理内存优化建议(逐 clip 处理)
  • 编码参数完整(threads, preset, codec, bitrate)
证据可验 (前四项均值)95/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。