用途
remotion-render 用于通过 inference.sh CLI 把 React/Remotion 组件代码渲染成视频。你提供 TSX 代码,得到 MP4 输出,适合以编程方式生成动画或视频内容。
主要能力
- 渲染来自 React/Remotion 组件代码的视频。
- 支持 Remotion 的全部 API,资料列出的可用导入包括:useCurrentFrame、useVideoConfig、spring、interpolate、AbsoluteFill、Sequence、Audio、Video、Img,以及 react 的 React、useState、useEffect。
- 可设置视频宽度、高度、fps、时长、编解码器(codec)。
- 可通过 props 向组件传值,也可指定 composition_id。
- 提供 Python SDK 调用方式,并支持流式进度更新。
使用方式
首先安装 belt CLI 技能:npx skills add belt-sh/cli。需要 inference.sh CLI(belt),并执行 belt login。
渲染一个简单动画:
belt app run infsh/remotion-render --input '{
"code": "import { useCurrentFrame, AbsoluteFill } from "remotion"; export default function Main() { const frame = useCurrentFrame(); return <AbsoluteFill style={{backgroundColor: "#000", display: "flex", justifyContent: "center", alignItems: "center"}}><h1 style={{color: "white", fontSize: 100, opacity: frame / 30}}>Hello World; }",
"duration_seconds": 3,
"fps": 30,
"width": 1920,
"height": 1080
}'
输入参数说明:
- code(字符串,必填):React 组件 TSX 代码,必须默认导出一个组件。
- composition_id(字符串,可选):要渲染的 Composition ID。
- props(对象,可选):传递给组件的 props。
- width(数字,可选):视频宽度(像素)。
- height(数字,可选):视频高度(像素)。
- fps(数字,可选):每秒帧数。
- duration_seconds(数字,可选):视频时长(秒)。
- codec(字符串,可选):输出编解码器。
示例
淡入文字、动画计数器、弹簧动画、带 props、序列动画等均在资料中给出对应命令,均通过 belt app run infsh/remotion-render --input '...' 调用,传入不同的 code、props、时长、fps 和尺寸。
Python SDK
可使用 Python SDK 调用:
from inferencesh import inference
client = inference()
result = client.run({
"app": "infsh/remotion-render",
"input": {
"code": """
import { useCurrentFrame, AbsoluteFill, interpolate } from "remotion";
export default function Main() {
const frame = useCurrentFrame();
const opacity = interpolate(frame, [0, 30], [0, 1]);
return (
<AbsoluteFill style={{
backgroundColor: "#1a1a2e",
display: "flex",
justifyContent: "center",
alignItems: "center"
}}>
<h1 style={{ color: "#eee", fontSize: 80, opacity }}>
Hello from Python
</h1>
</AbsoluteFill>
);
}
""",
"duration_seconds": 3,
"fps": 30,
"width": 1920,
"height": 1080
}
})
print(result["output"]["video"])
流式进度:
for update in client.run({
"app": "infsh/remotion-render",
"input": {
"code": "...",
"duration_seconds": 10
}
}, stream=True):
if update.get("progress"):
print(f"Rendering: {update['progress']}%")
if update.get("output"):
print(f"Video: {update['output']['video']}")
适用场景
需要以代码方式生成视频的场景,例如动画文字、动画计数器、弹簧缩放动画、分阶段序列动画等。
限制
渲染依赖 inference.sh CLI(belt)以及登录状态;代码需默认导出一个 React 组件;其他收费、价格、平台或效果信息暂未提供。
相关技能
- Remotion 最佳实践(组件模式):
npx skills add remotion-dev/skills@remotion-best-practices - AI 视频生成:
npx skills add inference-sh/skills@ai-video-generation - 图像生成:
npx skills add inference-sh/skills@ai-image-generation - Python SDK 参考:
npx skills add inference-sh/skills@python-sdk - 完整平台技能:
npx skills add inference-sh/skills@infsh-cli