Communitygithub.com

Cetc2211/AcTR-app

使用 z-ai-web-dev-sdk 實現 AI 驅動的影片生成功能。當使用者需要從文字提示或圖片生成影片、以程式方式建立影片內容,或構建能產生影片輸出的應用程式時,請使用此技能。支援非同步任務管理,包含狀態輪詢與結果擷取。

AcTR-app 是什麼?

此技能透過 z-ai-web-dev-sdk 套件,引導使用者實現 AI 驅動的影片生成功能。它支援從文字提示或圖片(包括單張圖片或首尾關鍵幀)創建影片,並可自訂解析度、幀率、時長與品質等參數。API 採用非同步任務模型,使用者需先建立任務並輪詢以取得最終結果。技能同時提供 CLI 與 SDK 兩種使用方式:CLI 適合快速測試與簡單自動化,SDK 則適合批次處理、客製化邏輯與複雜工作流程。特別強調 base64 編碼圖片比 URL 更可靠,並提供多種 MIME 類型(JPEG、PNG、WebP)的處理範例。此技能適用於各種軟體開發平台,並已預先安裝 z-ai-web-dev-sdk,開發者可直接使用。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Cetc2211/AcTR-app/tree/HEAD/skills/video-generation

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

影片生成技能

此技能引導使用 z-ai-web-dev-sdk 套件實作影片生成功能,讓 AI 模型能透過非同步任務處理,從文字描述或圖片創建影片。

技能路徑

技能位置:{project_path}/skills/video-generation

此技能位於專案中的上述路徑。

參考腳本:範例測試腳本可在 {Skill Location}/scripts/ 目錄中找到,供快速測試與參考。請參閱 {Skill Location}/scripts/video.ts 取得可運作的範例。

總覽

影片生成功能讓您能建立可從文字提示或圖片創建影片內容的應用程式,並可自訂解析度、幀率、時長與品質設定等參數。API 使用非同步任務模型,您需要先建立任務,再輪詢以取得結果。

重要:z-ai-web-dev-sdk 必須僅在後端程式碼中使用。切勿在客戶端程式碼中使用。

先決條件

z-ai-web-dev-sdk 套件已預先安裝。請依照下方範例所示的方式匯入。

CLI 使用方式(適用於簡單任務)

對於簡單的影片生成任務,您可以使用 z-ai CLI 而非撰寫程式碼。CLI 會自動處理任務建立與輪詢,非常適合快速測試與簡單自動化。

基本文字轉影片

# 生成影片並自動輪詢
z-ai video --prompt "A cat playing with a ball" --poll

# 使用短選項
z-ai video -p "Beautiful landscape with mountains" --poll

自訂品質與設定

# 品質模式(speed 或 quality)
z-ai video -p "Ocean waves at sunset" --quality quality --poll

# 自訂解析度與幀率
z-ai video \
  -p "City timelapse" \
  --size "1920x1080" \
  --fps 60 \
  --poll

# 自訂時長(5 或 10 秒)
z-ai video -p "Fireworks display" --duration 10 --poll

圖片轉影片

重要:對於 image_url 參數,強烈建議使用 base64 編碼的圖片資料而非 URL。這種方式更為可靠,可避免潛在的網路問題或存取限制。

注意:請將資料 URI 中的 MIME 類型與實際圖片格式(image/jpeg、image/png、image/webp 等)匹配,以避免解碼問題。

# 從單張圖片生成影片(使用 base64,建議採用)
# 將圖片轉換為 base64,並使用正確的 MIME 類型

# 對於 PNG 圖片
IMAGE_BASE64=$(base64 -i image.png)
z-ai video \
  --image-url "data:image/png;base64,${IMAGE_BASE64}" \
  --prompt "Make the scene come alive" \
  --poll

# 對於 JPEG 圖片
IMAGE_BASE64=$(base64 -i photo.jpg)
z-ai video \
  --image-url "data:image/jpeg;base64,${IMAGE_BASE64}" \
  --prompt "Make the scene come alive" \
  --poll

# 對於 WebP 圖片
IMAGE_BASE64=$(base64 -i image.webp)
z-ai video \
  --image-url "data:image/webp;base64,${IMAGE_BASE64}" \
  --prompt "Make the scene come alive" \
  --poll

# 使用 URL(較不建議,可能存在可靠性問題)
z-ai video \
  -i "https://example.com/photo.jpg" \
  -p "Add motion to this scene" \
  --poll

首尾幀模式

重要:為確保最佳可靠性,請使用 base64 編碼的圖片而非 URL。確保 MIME 類型與實際圖片格式匹配。

# 在兩個幀之間生成影片(使用 base64,建議採用)
# 確保每張圖片都使用正確的 MIME 類型

# 使用 PNG 圖片的範例
START_BASE64=$(base64 -i start.png)
END_BASE64=$(base64 -i end.png)
z-ai video \
  --image-url "data:image/png;base64,${START_BASE64},data:image/png;base64,${END_BASE64}" \
  --prompt "Smooth transition between frames" \
  --poll

# 使用 JPEG 圖片的範例
START_BASE64=$(base64 -i start.jpg)
END_BASE64=$(base64 -i end.jpg)
z-ai video \
  --image-url "data:image/jpeg;base64,${START_BASE64},data:image/jpeg;base64,${END_BASE64}" \
  --prompt "Smooth transition between frames" \
  --poll

# 使用 URL(較不建議)
z-ai video \
  --image-url "https://example.com/start.png,https://example.com/end.png" \
  --prompt "Smooth transition between frames" \
  --poll

搭配音訊生成

# 生成影片並附帶 AI 生成音效
z-ai video \
  -p "Thunder storm approaching" \
  --with-audio \
  --poll

儲存輸出

# 將任務結果儲存為 JSON 檔案
z-ai video \
  -p "Sunrise over mountains" \
  --poll \
  -o video_result.json

自訂輪詢參數

# 自訂輪詢行為
z-ai video \
  -p "Dancing robot" \
  --poll \
  --poll-interval 10 \
  --max-polls 30

# 建立任務但不輪詢(取得任務 ID)
z-ai video -p "Abstract art animation" -o task.json

CLI 參數

  • --prompt, -p <text>:選用 - 影片的文字描述
  • --image-url, -i <data>:選用 - 建議使用 base64 編碼的圖片資料(例如 "data:image/png;base64,iVBORw...")。URL 也可支援但較不建議。如需使用兩張圖片,請以逗號分隔。
  • --quality, -q <mode>:選用 - 輸出模式:speed 或 quality(預設:speed)
  • --with-audio:選用 - 生成 AI 音效(預設:false)
  • --size, -s <resolution>:選用 - 影片解析度(例如 "1920x1080")
  • --fps <rate>:選用 - 幀率:30 或 60(預設:30)
  • --duration, -d <seconds>:選用 - 時長:5 或 10 秒(預設:5)
  • --model, -m <model>:選用 - 使用的模型名稱
  • --poll:選用 - 自動輪詢直到任務完成
  • --poll-interval <seconds>:選用 - 輪詢間隔(預設:5)
  • --max-polls <count>:選用 - 最大輪詢次數(預設:60)
  • --output, -o <path>:選用 - 輸出檔案路徑(JSON 格式)

支援的解析度

  • 1024x1024
  • 768x1344
  • 864x1152
  • 1344x768
  • 1152x864
  • 1440x720
  • 720x1440
  • 1920x1080(以及其他標準解析度)

稍後檢查任務狀態

如果您在建立任務時未使用 --poll,可以稍後檢查其狀態:

# 從初始回應取得任務 ID
z-ai async-result --id "task-id-here" --poll

何時使用 CLI 與 SDK

使用 CLI 的時機:

  • 快速影片生成測試
  • 簡單的一次性影片創建
  • 命令列自動化腳本
  • 測試不同的提示詞與設定

使用 SDK 的時機:

  • 需要自訂邏輯的批次影片生成
  • 與 Web 應用程式整合
  • 自訂任務佇列管理
  • 具有複雜工作流程的生產應用程式

影片生成工作流程

影片生成遵循兩個步驟的非同步模式:

  1. 建立任務:提交影片生成請求並接收任務 ID
  2. 輪詢結果:查詢任務狀態直到完成,並擷取影片 URL

基本影片生成實作

簡單的文字轉影片生成

import ZAI from 'z-ai-web-dev-sdk';

async function generateVideo(prompt) {
  try {
    const zai = await ZAI.create();

    // 建立影片生成任務
    const task = await zai.video.generations.create({
      prompt: prompt,
      quality: 'speed', // 'speed' 或 'quality'
      with_audio: false,
      size: '1920x1080',
      fps: 30,
      duration: 5
    });

    console.log('Task ID:', task.id);
    console.log('Task Status:', task.task_status);

    // 輪詢結果
    let result = await zai.async.result.query(task.id);
    let pollCount = 0;
    const maxPolls = 60;
    const pollInterval = 5000; // 5 秒

    while (result.task_status === 'PROCESSING' && pollCount < maxPolls) {
      pollCount++;
      console.log(`Polling ${pollCount}/${maxPolls}: Status is ${result.task_status}`);
      await new Promise(resolve => setTimeout(resolve, pollInterval));
      result = await zai.async.result.query(task.id);
    }

    if (result.task_status === 'SUCCESS') {
      // 從多個可能欄位取得影片 URL
      const videoUrl = result.video_result?.[0]?.url ||
                      result.video_url ||
                      result.url ||
                      result.video;
      console.log('Video URL:', videoUrl);
      return videoUrl;
    } else {
      console.log('Task failed or still processing');
      return null;
    }
  } catch (error) {
    console.error('Video generation failed:', error.message);
    throw error;
  }
}

// 使用方式
const videoUrl = await generateVideo('A cat is playing with a ball.');
console.log('Generated video:', videoUrl);

圖片轉影片生成

重要:image_url 參數可接受 base64 編碼的圖片資料與 URL,但強烈建議使用 base64 編碼,以獲得更好的可靠性並避免網路相關問題。

關鍵:始終將 base64 資料 URI 中的 MIME 類型與實際圖片格式匹配,以防止解碼錯誤。

import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';

// 輔助函式:從副檔名偵測 MIME 類型
function getMimeType(filePath) {
  const ext = path.extname(filePath).toLowerCase();
  const mimeTypes = {
    '.jpg': 'image/jpeg',
    '.jpeg': 'image/jpeg',
    '.png': 'image/png',
    '.gif': 'image/gif',
    '.webp': 'image/webp',
    '.bmp': 'image/bmp'
  };
  return mimeTypes[ext] || 'image/jpeg'; // 若未知則預設為 JPEG
}

async function generateVideoFromImage(imagePath, prompt) {
  const zai = await ZAI.create();

  // 方法 1:使用 base64 編碼圖片(建議採用)
  // 自動從副檔名偵測 MIME 類型
  const imageBuffer = fs.readFileSync(imagePath);
  const mimeType = getMimeType(imagePath);
  const base64Image = `data:${mimeType};base64,${imageBuffer.toString('base64')}`;

  const task = await zai.video.generations.create({
    image_url: base64Image,  // 帶有正確 MIME 類型的 Base64 資料字串
    prompt: prompt,
    quality: 'quality',
    duration: 5,
    fps: 30
  });

  return task;
}

// 方法 2:使用 URL(較不建議)
async function generateVideoFromImageUrl(imageUrl, prompt) {
  const zai = await ZAI.create();

  const task = await zai.video.generations.create({
    image_url: imageUrl,  // URL 字串
    prompt: prompt,
    quality: 'quality',
    duration: 5,
    fps: 30
  });

  return task;
}

// 使用範例
const task1 = await generateVideoFromImage(
  './images/photo.jpg',  // 支援 JPEG
  'Animate this scene with gentle motion'
);

const task2 = await generateVideoFromImage(
  './images/graphic.png',  // 支援 PNG
  'Add dynamic movement'
);

const task3 = await generateVideoFromImage(
  './images/animation.webp',  // 支援 WebP
  'Bring this to life'
);

使用首尾幀的圖片轉影片

重要:對於關鍵幀模式,強烈建議使用 base64 編碼圖片而非 URL,以確保一致且可靠的影片生成。務必為每張圖片使用正確的 MIME 類型。

import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';

// 輔助函式:從副檔名偵測 MIME 類型
function getMimeType(filePath) {
  const ext = path.extname(filePath).toLowerCase();
  const mimeTypes = {
    '.jpg': 'image/jpeg',
    '.jpeg': 'image/jpeg',
    '.png': 'image/png',
    '.gif': 'image/gif',
    '.webp': 'image/webp',
    '.bmp': 'image/bmp'
  };
  return mimeTypes[ext] || 'image/jpeg';
}

async function generateVideoWithKeyframes(startImagePath, endImagePath, prompt) {
  const zai = await ZAI.create();

  // 方法 1:使用 base64 編碼圖片(建議採用)
  // 自動為每張圖片偵測 MIME 類型
  const startBuffer = fs.readFileSync(startImagePath);
  const endBuffer = fs.readFileSync(endImagePath);
  
  const startMimeType = getMimeType(startImagePath);
  const endMimeType = getMimeType(endImagePath);
  
  const startBase64 = `data:${startMimeType};base64,${startBuffer.toString('base64')}`;
  const endBase64 = `data:${endMimeType};base64,${endBuffer.toString('base64')}`;

  const task = await zai.video.generations.create({
    image_url: [startBase64, endBase64],  // 具有正確 MIME 類型的 Base64 字串陣列
    prompt: prompt,
    quality: 'quality',
    duration: 10,
    fps: 30
  });

  console.log('Task created with keyframes:', task.id);
  return task;
}

// 方法 2:使用 URL(較不建議)
async function generateVideoWithKeyframesUrl(startImageUrl, endImageUrl, prompt) {
  const zai = await ZAI.create();

  const task = await zai.video.generations.create({
    image_url: [startImageUrl, endImageUrl],  // URL 字串陣列
    prompt: prompt,
    quality: 'quality',
    duration: 10,
    fps: 30
  });

  console.log('Task created with keyframes:', task.id);
  return task;
}

// 使用不同格式的範例
const task1 = await generateVideoWithKeyframes(
  './frames/start.jpg',  // JPEG 起始幀
  './frames/end.jpg',    // JPEG 結束幀
  'Smooth transition between these scenes'
);

const task2 = await generateVideoWithKeyframes(
  './frames/start.png',  // PNG 起始幀
  './frames/end.webp',   // WebP 結束幀 - 不同格式也沒問題!
  'Morphing effect between images'
);

非同步結果管理

查詢任務狀態

import ZAI from 'z-ai-web-dev-sdk';

async function checkTaskStatus(taskId) {
  try {
    const zai = await ZAI.create();
    const result = await zai.async.result.query(taskId);

    console.log('Task Status:', result.task_status);

    if (result.task_status === 'SUCCESS') {
      // 從結果中提取影片 URL
      const videoUrl = result.video_result?.[0]?.url ||
                      result.video_url ||
                      result.url ||
                      result.video;
      if (videoUrl) {
        console.log('Video URL:', videoUrl);
        return { success: true, url: videoUrl };
      }
    } else if (result.task_status === 'PROCESSING') {
      console.log('Task is still processing');
      return { success: false, status: 'processing' };
    } else if (result.task_status === 'FAIL') {
      console.log('Task failed');
      return { success: false, status: 'failed' };
    }
  } catch (error) {
    c

…

[因翻譯長度而被截斷]

Individual skills in this repo

This repo contains 7 individual skills — each has its own dedicated page.

Cetc2211/AcTR-app

Generate a single-file Chinese atelier-style portfolio website (horizontal-row list + hover-reveal thumb interaction, art lishu typography "Alimama DaoLiTi" via CDN, light/dark theme, hash-routed detail pages). Takes a natural-language description of the studio (name, director, discipline, works) and outputs ONE working .html file. Runs in BOTH Claude Code (writes to ~/Desktop) and GLM / online chat (outputs HTML inline). Trigger phrases include "做个中式工作室作品集", "做个隶书作品集", "lishu-portfolio-gen ...", "做个白屋风格的作品集", or when user drags this skill folder into chat asking for an atelier-style site.

Cetc2211/AcTR-app

Premium calm-tech SaaS landing template — bilingual (CN/EN) literary voice over a dark forest-night palette with warm gold accent, Cormorant + Noto Serif SC, Three.js procedural forest hero, station-based scrolling narrative, custom cursor. Built for ambient-AI / creative-tool / philosophical SaaS, not loud commercial launch.

Cetc2211/AcTR-app

Pro-camera HUD mockup template — full-viewport black canvas wrapping a real video with monospace overlays (corner brackets, top status bar, side AF/exposure columns, bottom timecode + aperture/shutter/ISO row, vertical 8-filter wheel, animated reticle). For cinematographer portfolios, camera-app demos, LUT pack previews, filter-look auditions. NOT a TikTok/Reels mockup, NOT a storyboard, NOT a shot list, NOT a script document. The chrome wraps real footage — never a div placeholder.

Cetc2211/AcTR-app

Premium pre-launch waitlist page template — dark charcoal canvas with subtle vignette, drifting portrait video-thumbnail cards, fade-up cascades, glass nav, live-updating join counter, single email form with success/error states. Built for creative-tool / AI / niche-SaaS invite-only launches with hushed exclusive tone, not loud growth-marketing.

Cetc2211/AcTR-app

Route design-related HTML artifact tasks to the right artifact skill, reference, design system generation, or export skill.

Cetc2211/AcTR-app

Implement text-to-speech (TTS) capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to convert text into natural-sounding speech, create audio content, build voice-enabled applications, or generate spoken audio files. Supports multiple voices, adjustable speed, and various audio formats.

Cetc2211/AcTR-app

Implement specialized video understanding capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to analyze video content, understand motion and temporal sequences, extract information from video frames, describe video scenes, or perform video-based AI analysis. Optimized for MP4, AVI, MOV, and other common video formats.

相關技能