mcpField
M
media-composition

media-composition

github.com/athola创意与媒体343100 次安装1 天前更新
代码仓库

关于 media-composition

用于将分别生成的 GIF、视频和图像合成为教程或文档素材的 Skill。它通过 YAML 清单校验输入,并使用 FFmpeg 按堆叠、网格、叠加或画中画等布局合成。

主要功能

  1. 01解析 YAML 清单
  2. 02校验组件文件是否存在
  3. 03使用 FFmpeg 合成媒体
  4. 04支持堆叠、网格与叠加布局
  5. 05验证输出并记录指标

适用场景

  1. 01合并终端与浏览器录屏
  2. 02制作并排媒体对比
  3. 03构建画中画演示
  4. 04为教程和文档组合媒体素材

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/athola/claude-night-market --skill media-composition

安装后在 Claude Code 中输入/media-composition确认已加载。

详细介绍

媒体合成技能

将多个媒体资源(GIF、视频、图像)合并为复合输出,用于制作详尽的教程和文档。

适用场景

  • 将多个媒体输出合并为复合内容
  • 从终端和浏览器录制内容制作复合演示

不适用场景

  • 无需合成的单格式输出
  • 简单的终端录制——直接使用 scry:vhs-recording

概述

此技能负责将分别生成的媒体资源合成为统一输出。它会读取定义组件及其合成规则的清单文件,验证所有输入均存在,并执行 FFmpeg 命令以生成最终的复合媒体。

前置条件

使用此技能前,以下工具必须在 PATH 中可用:

  • ffmpeg:用于媒体合成和编码
  • yq:用于解析 YAML 清单

运行 ffmpeg -version 和 yq --version,以确认工具可用。

必需的进度项

- Parse composition manifest file
- Validate all component outputs exist
- Determine composition layout and parameters
- Execute FFmpeg composition command
- Verify combined output file created
- Report composition metrics (file size, dimensions)

清单格式

清单用于定义要合并的组件及其排列方式:

# Example manifest: tutorials/mcp.manifest.yaml
name: mcp
title: "MCP Server Integration"
components:
  - type: tape
    source: mcp.tape
    output: assets/gifs/mcp-terminal.gif
  - type: playwright
    source: browser/mcp-browser.spec.ts
    output: assets/gifs/mcp-browser.gif
    requires:
      - "skrills serve"
combine:
  output: assets/gifs/mcp-combined.gif
  layout: vertical
  options:
    padding: 10
    background: "#1a1a2e"
清单架构
字段类型必需描述
namestring是合成内容的标识符
titlestring否便于阅读的标题
componentsarray是要合并的媒体组件列表
components[].typestring是源类型:tape、playwright、static
components[].sourcestring是源文件路径
components[].outputstring是生成的输出路径
components[].requiresarray否生成前要运行的命令
combine.outputstring是合并后输出的路径
combine.layoutstring是布局模式(见下表)
combine.optionsobject否布局专属选项

分步流程

1. 解析清单文件
# Read and validate manifest structure
yq eval '.' manifest.yaml

# Extract component outputs
yq eval '.components[].output' manifest.yaml
2. 验证组件输出
# Check all required files exist
for output in $(yq eval '.components[].output' manifest.yaml); do
  if [[ ! -f "$output" ]]; then
    echo "ERROR: Missing component: $output"
    exit 1
  fi
done
3. 执行 FFmpeg 合成

根据清单中指定的布局,执行相应的 FFmpeg 命令。

4. 验证合并后的输出
# Verify output exists and has content
if [[ -f "$output" && -s "$output" ]]; then
  echo "Composition successful: $output"
  ls -lh "$output"
else
  echo "ERROR: Composition failed"
  exit 1
fi

FFmpeg 合成命令

垂直堆叠

将 GIF/视频从上到下堆叠:

ffmpeg -i top.gif -i bottom.gif \
  -filter_complex "[0:v][1:v]vstack=inputs=2" \
  -y output.gif

添加间距:

ffmpeg -i top.gif -i bottom.gif \
  -filter_complex "[0:v]pad=iw:ih+10:0:0:color=black[top];[top][1:v]vstack=inputs=2" \
  -y output.gif
水平堆叠

将 GIF/视频并排堆叠:

ffmpeg -i left.gif -i right.gif \
  -filter_complex "[0:v][1:v]hstack=inputs=2" \
  -y output.gif
顺序拼接

依次播放 GIF/视频:

# Create concat list file
cat > concat_list.txt << EOF
file 'first.gif'
file 'second.gif'
file 'third.gif'
EOF

# Concatenate
ffmpeg -f concat -safe 0 -i concat_list.txt \
  -y output.gif
网格布局(2x2)
ffmpeg -i tl.gif -i tr.gif -i bl.gif -i br.gif \
  -filter_complex "[0:v][1:v]hstack=inputs=2[top];[2:v][3:v]hstack=inputs=2[bottom];[top][bottom]vstack=inputs=2" \
  -y output.gif
添加背景颜色
ffmpeg -i top.gif -i bottom.gif \
  -filter_complex "color=c=#1a1a2e:s=800x600[bg];[bg][0:v]overlay=0:0[tmp];[tmp][1:v]overlay=0:300" \
  -y output.gif

布局选项

布局描述选项
vertical从上到下堆叠padding、background、align
horizontal从左到右堆叠padding、background、align
sequential按顺序播放transition、duration
gridN x M 网格排列rows、cols、padding
overlay相互叠加position、opacity
pip画中画corner、scale、margin
布局选项详情
选项类型默认值描述
paddingint0组件之间的像素间距
backgroundstring"black"背景颜色(十六进制值或名称)
alignstring"center"对齐方式:left、center、right
transitionstring"none"转场类型:fade、wipe、none
scalefloat0.25PiP 缩放比例
cornerstring"br"PiP 角落位置:tl、tr、bl、br

合成示例

终端和浏览器教程
name: plugin-demo
components:
  - type: tape
    source: demo.tape
    output: terminal.gif
  - type: playwright
    source: browser.spec.ts
    output: browser.gif
combine:
  output: demo-combined.gif
  layout: vertical
  options:
    padding: 5
    background: "#0d1117"
并排对比
name: before-after
components:
  - type: static
    source: before.gif
    output: before.gif
  - type: static
    source: after.gif
    output: after.gif
combine:
  output: comparison.gif
  layout: horizontal
  options:
    padding: 10
画中画
name: pip-demo
components:
  - type: tape
    source: main.tape
    output: main.gif
  - type: playwright
    source: overlay.spec.ts
    output: overlay.gif
combine:
  output: pip-demo.gif
  layout: pip
  options:
    corner: br
    scale: 0.3
    margin: 20

完成标准

  • 成功解析清单文件
  • 验证所有组件输出均已存在
  • FFmpeg 合成命令执行成功,未发生错误
  • 合并后的输出文件存在且大小不为零
  • 已记录输出尺寸和时长
  • 已清理临时文件

评论

支持 Markdown