開始使用

Chillin Render API 允許您通過定義如下的 JSON 結構來指定要渲染的視頻內容和參數。

  • 前往 Render Console 獲取 Render API 積分並生成您的 Render API 密鑰

  • 向 Render API 端點發送帶有您的 API 密鑰的 POST 請求:

curl-example.sh
1curl -X POST https://render-api.chillin.online/render/v1 \ 2-H "Accept: application/json" \ 3-H "Content-Type: application/json" \ 4-H "Authorization: Bearer YOUR_API_KEY" \ 5-d @request.json
request.json
1{ 2"compositeWidth": 1920, 3"compositeHeight": 1080, 4"fps": 30, 5"projectData": { 6 "type": "", 7 "width": 1920, 8 "height": 1080, 9 "fill": "#000000", 10 "view": [ 11 { 12 "id": "bba95c7f-652b-4380-b166-6bece989f527", 13 "type": "Image", 14 "start": 0, 15 "duration": 5, 16 "trackIndex": 0, 17 "x": 0, 18 "y": 0, 19 "width": 3629, 20 "height": 5444, 21 "blendMode": "normal", 22 "anchorX": 1814.5, 23 "anchorY": 2722, 24 "rotation": 0, 25 "scaleX": 0.19838354151359294, 26 "scaleY": 0.19838354151359294, 27 "alpha": 1, 28 "skewX": 0, 29 "skewY": 0, 30 "hidden": false, 31 "locked": false, 32 "keyframes": [], 33 "externalUrl": "https://images.pexels.com/photos/33189512/pexels-photo-33189512.jpeg", 34 "ext": "jpeg" 35 } 36 ], 37 "audio": [], 38 "effect": [], 39 "transition": [], 40 "version": 0, 41 "duration": 5 42} 43}; 44

該 API 在異步模式下運行,並返回如下響應:

async_response.json
1{ 2"code": 0, 3"data": { 4 "message": "Async render request submitted successfully", 5 "render_id": 100000, 6 "status": "processing" 7}, 8"msg": "success" 9} 10

核心概念

所有 JSON 對象都包括一個視頻項目對象,指定視頻的合成寬度、合成高度和解析度。

項目對象包含渲染視頻的基本參數,例如寬度、高度、持續時間、背景顏色等。

該項目還包括一個或多個元素,每個元素表示一個視頻組件,例如視頻、圖像、文本、形狀、音頻或效果。

每個元素都包含該組件的特定參數,例如位置、大小、顏色、內容等。

project.json
1{ 2"compositeWidth": 1920, 3"compositeHeight": 1080, 4"fps": 30, 5"projectData": { 6 "type": "", 7 "width": 1920, 8 "height": 1080, 9 "fill": "#000000", 10 "view": [ 11 { 12 "id": "8ecf7475-2c6c-47f9-827b-a09c7913f4c0", 13 "type": "Image", 14 "start": 0, 15 "duration": 5, 16 "trackIndex": 0, 17 "x": -570.0335392757963, 18 "y": -170.90659033307685, 19 "blendMode": "normal", 20 "anchorX": 1302, 21 "anchorY": 2312, 22 "rotation": 0, 23 "scaleX": 0.23356401384083045, 24 "scaleY": 0.23356401384083045, 25 "alpha": 1, 26 "skewX": 0, 27 "skewY": 0, 28 "keyframes": [], 29 "externalUrl": "https://images.pexels.com/photos/30465303/pexels-photo-30465303.jpeg", 30 "ext": "jpeg" 31 } 32 ], 33 "audio": [], 34 "effect": [], 35 "transition": [], 36 "version": 0, 37 "duration": 5 38} 39}; 40

3D 空間與相機

渲染引擎支持 2D 和 3D 元素。雖然畫布的寬度和高度以像素為單位定義,但引擎使用透視相機進行 3D 渲染:

  • 坐標系統:x 和 y 坐標表示 2D 畫布平面上的位置。z 坐標控制 3D 空間中的深度。
  • 像素完美投影:在 z=0 時,一個世界單位等於一個像素,保持與 2D 工作流程的兼容性。
  • 3D 旋轉:元素可以使用 rotationXrotationYrotation(Z 軸)屬性繞 X、Y 和 Z 軸旋轉。

此設計允許在同一項目中無縫混合 2D 和 3D 元素。傳統的 2D 元素(z=0)與之前一樣渲染,而 3D 元素可以在三維空間中進行定位和旋轉。

3D 元素示例

這是一個簡單的 3D 立方體元素示例:

3d-cube-example.json
1{ 2"id": "3d-cube-001", 3"type": "3D", 4"start": 0, 5"duration": 5, 6"trackIndex": 0, 7"x": 960, 8"y": 540, 9"z": 0, 10"width": 200, 11"height": 200, 12"anchorX": 100, 13"anchorY": 100, 14"rotation": 0, 15"rotationX": 30, 16"rotationY": 45, 17"scaleX": 1, 18"scaleY": 1, 19"scaleZ": 1, 20"alpha": 1, 21"ext": "geometry", 22"geometryType": "cube", 23"nodeCategory": "basic", 24"geometryColor": "#4A90E2" 25} 26

與 2D 元素的主要區別:

  • type: "3D" 將其標識為 3D 元素
  • zrotationXrotationYscaleZ 使 3D 變換成為可能
  • geometryType 指定 3D 形狀(立方體、球體、圓柱體等)
  • geometryColor 設置 3D 幾何圖形的基本顏色

有關 3D 元素的更多詳細信息,請參見 3D Element 文檔。

JSON 架構

您的請求 JSON 必須嚴格遵循本文件中定義的 JSON 架構。您可以在 Chillin Video Editor 中測試並生成相應的請求 JSON。