Communitygithub.com

Kling AI 图像转视频

使用 Kling AI 将静态图像转换为视频。适用于图像转视频、为静止图像添加运动效果或构建 I2V 流水线。可通过“klingai 图像转视频”、“kling ai 动画图像”、“klingai img2vid”、“animate picture klingai”等短语触发。

Kling AI 图像转视频 是什么?

该技能利用 Kling AI 的 `/v1/videos/image2video` 端点,将静态图像动态转化为视频。它支持多种高级功能,包括运动提示、相机控制、动态遮罩(运动笔刷)、静态遮罩以及用于起始到结束过渡的尾部图像。开发者可以通过设置 `model_name`、`duration`、`mode` 等参数来精细控制输出效果。技能支持的功能之间存在互斥规则(例如 `image_tail` 不能与 `dynamic_masks` 同时使用),并且有严格的图像格式、分辨率和大小要求。用户需要先获取 Kling API 凭据、通过模型和时长白名单审核,并确保所有源图像和遮罩均已获得必要的使用许可。该技能适用于 Python 环境,可以通过轮询或 Webhook 获取任务结果。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/jeremylongshore/tons-of-skills-marketplace/tree/HEAD/plugins/saas-packs/klingai-pack/skills/klingai-image-to-video

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Kling AI 图像转视频 是做什么的?

概述

使用 /v1/videos/image2video 端点将静态图像动画化。支持运动提示、相机控制、动态遮罩(运动笔刷)、静态遮罩以及用于起始到结束过渡的尾部图像。

端点: POST https://api.klingai.com/v1/videos/image2video

请求参数

参数类型必需描述
model_namestring是kling-v1-5, kling-v2-1, kling-v2-master 等
imagestring是源图像的 URL(JPG、PNG、WebP)
promptstring否动画的运动描述
negative_promptstring否要排除的内容
durationstring是"5" 或 "10" 秒
aspect_ratiostring否默认 "16:9"
modestring否"standard" 或 "professional"
cfg_scalefloat否提示词遵循度(0.0-1.0)
image_tailstring否结束帧图像 URL(与遮罩/相机互斥)
camera_controlobject否相机移动(与遮罩/image_tail 互斥)
static_maskstring否固定区域的遮罩图像 URL
dynamic_masksarray否运动笔刷轨迹
callback_urlstring否完成通知的 Webhook

基本图像转视频

import jwt, time, os, requests

BASE = "https://api.klingai.com/v1"

def get_headers():
    ak, sk = os.environ["KLING_ACCESS_KEY"], os.environ["KLING_SECRET_KEY"]
    token = jwt.encode(
        {"iss": ak, "exp": int(time.time()) + 1800, "nbf": int(time.time()) - 5},
        sk, algorithm="HS256", headers={"alg": "HS256", "typ": "JWT"}
    )
    return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}

# 将风景照片动画化
response = requests.post(f"{BASE}/videos/image2video", headers=get_headers(), json={
    "model_name": "kling-v2-1",
    "image": "https://example.com/landscape.jpg",
    "prompt": "Clouds slowly drifting across the sky, gentle wind rustling through trees",
    "negative_prompt": "static, frozen, blurry",
    "duration": "5",
    "mode": "standard",
})

task_id = response.json()["data"]["task_id"]

# 轮询获取结果
while True:
    time.sleep(15)
    result = requests.get(
        f"{BASE}/videos/image2video/{task_id}", headers=get_headers()
    ).json()
    if result["data"]["task_status"] == "succeed":
        print(f"Video: {result['data']['task_result']['videos'][0]['url']}")
        break
    elif result["data"]["task_status"] == "failed":
        raise RuntimeError(result["data"]["task_status_msg"])

起始到结束过渡(image_tail)

使用 image_tail 指定第一帧和最后一帧。Kling 会在它们之间插值运动。

response = requests.post(f"{BASE}/videos/image2video", headers=get_headers(), json={
    "model_name": "kling-v2-master",
    "image": "https://example.com/sunrise.jpg",        # 第一帧
    "image_tail": "https://example.com/sunset.jpg",    # 最后一帧
    "prompt": "Time lapse of sun moving across the sky",
    "duration": "5",
    "mode": "professional",
})

运动笔刷(dynamic_masks)

为图像中的特定元素绘制运动路径。在 v2.6 中,每张图像最多支持 6 个运动路径。

response = requests.post(f"{BASE}/videos/image2video", headers=get_headers(), json={
    "model_name": "kling-v2-6",
    "image": "https://example.com/person-standing.jpg",
    "prompt": "Person walking forward naturally",
    "duration": "5",
    "dynamic_masks": [
        {
            "mask": "https://example.com/person-mask.png",  # 白色 = 选中的区域
            "trajectories": [
                {"x": 0.5, "y": 0.7, "t": 0.0},   # 起始位置(归一化 0-1)
                {"x": 0.5, "y": 0.5, "t": 0.5},   # 中间点
                {"x": 0.5, "y": 0.3, "t": 1.0},   # 结束位置
            ]
        }
    ],
})

静态遮罩(冻结区域)

在动画化其余部分时,保持图像的特定区域静止。

response = requests.post(f"{BASE}/videos/image2video", headers=get_headers(), json={
    "model_name": "kling-v2-master",
    "image": "https://example.com/scene.jpg",
    "prompt": "Water flowing in the river, birds flying",
    "duration": "5",
    "static_mask": "https://example.com/buildings-mask.png",  # 白色 = 冻结
})

互斥规则

以下功能不能在单个请求中组合使用:

特性集 A特性集 B
image_taildynamic_masks, static_mask, camera_control
dynamic_masks / static_maskimage_tail, camera_control
camera_controlimage_tail, dynamic_masks, static_mask

图像要求

约束值
格式JPG, PNG, WebP
最大大小10 MB
最小分辨率300x300 px
最大分辨率4096x4096 px
遮罩格式PNG(白色为选中区域,黑色为排除区域)

错误处理

错误原因修复
400 无效图像URL 无法访问或格式错误验证图像 URL 可公开访问
400 互斥组合了不兼容的特性每个请求仅使用一个特性集
task_status: failed图像过于复杂或质量低使用更高分辨率、更清晰的源图像
遮罩不匹配遮罩尺寸与源图像不同确保遮罩与源图像尺寸匹配

前提条件

  • Kling API 凭据存储在运行时密钥管理器中,已批准的模型和时长白名单,以及每个作业的信用额度预算。
  • 合成或版权清晰的源图像以及任何遮罩或尾部图像,对于可识别的人物需记录同意,并获得转换资产的许可。
  • 私有暂存存储桶和审查负责人。新生成的图像在记录政策、质量和出版批准之前,必须保持草稿状态并带有水印。

说明

  1. 从已批准的白名单中解析源图像和遮罩引用;拒绝来自不可信 URL、缺少来源证明或包含未记录同意的可识别人物的资产。
  2. 在花费信用额度之前,验证格式、尺寸、功能互斥性、提示词长度和请求的时长。使用合成固定装置进行自动化检查。
  3. 使用稳定的作业密钥对请求进行去重,仅在内容策略检查通过后提交,并将任务和源图像保存在私有暂存存储中。
  4. 运行一个简短的、带水印的沙箱示例。检查运动、策略结果、源图像保真度和信用额度预算,然后再请求负责人批准更大规模或公开的渲染。
  5. 批准后,按摘要推广确切的任务结果。若失败或撤回,则停止下游发布,删除暂存媒体和临时 URL,并恢复先前批准的资产或作业状态。
  6. 记录一份隐私处理过的收据,仅包含不透明的作业和资产摘要、策略和批准结果、预算结果、保留期限以及回滚引用。

输出

返回包含不透明任务标识符、模型和时长、状态、输出摘要或私有暂存 URL、示例/批准状态以及清理或回滚引用的结果。不要将源图像、遮罩 URL、提示词、面部数据、凭据或未编辑的提供商响应放入日志或收据中。

示例

对于安全的自动化检查,使用合成的风景固定装置和私有示例:

source=fixture:synthetic-landscape-v3; rights=cleared; mode=standard;
duration=5; canary=watermarked-sandbox; policy=pass; approval=pending;
publish=false; contacts_exported=0; receipt=asset-sha256:opaque

在记录同意、策略、质量和所有者批准之前,请勿替换真实客户的照片或发布示例。

资源

Individual skills in this repo

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

jeremylongshore/tons-of-skills-marketplace

Use when asked to structure a landing page for positioning, plan a conversion-optimized page layout, or design a launch page. Examples: "landing page for product launch", "conversion-optimized layout for SaaS

jeremylongshore/tons-of-skills-marketplace

Use when asked to design growth-optimized landing pages, activation funnel layouts, or experiment-friendly page structures. Examples: "growth-optimized landing", "activation funnel layout", "A/B testable page

jeremylongshore/tons-of-skills-marketplace

Use when asked to structure a landing page, design page layout for conversion, or plan landing page information architecture. Examples: "landing page structure for SaaS", "conversion-optimized layout

jeremylongshore/tons-of-skills-marketplace

Generate polished demo videos from a single prompt. Use when the user asks to create a demo video, product walkthrough, feature showcase, or animated presentation. Trigger with "make a demo video", "create a product video", "demo walkthrough", or "feature showcase video".

jeremylongshore/tons-of-skills-marketplace

Track cryptocurrency portfolio with real-time valuations, allocation analysis, and P&L tracking. Use when checking portfolio value, viewing holdings breakdown, analyzing allocations, or exporting portfolio data. Trigger with phrases like "show my portfolio", "check crypto holdings", "portfolio allocation", "track my crypto", or "export portfolio".

jeremylongshore/tons-of-skills-marketplace

Runs the full release workflow for the current project. Commits any uncommitted changes, pushes to remote, creates and merges a PR if on a feature branch, determines the next semver version from conventional commits, creates an annotated git tag and GitHub release with generated notes, cleans up merged branches, and returns to a clean main. Use when the user says promote, ship, release, commit and push, tag and release, or get back to main.

jeremylongshore/tons-of-skills-marketplace

Agent skill at plugins/productivity/content-multiplier/skills/channel-formats/SKILL.md

jeremylongshore/tons-of-skills-marketplace

Operate an evidence-backed editorial queue, balance topic and format coverage, schedule approved drafts, and reconcile backlog state with the publishing system. Use when choosing or scheduling the next blog work. Trigger with "show the editorial calendar" or "pick the next topic".

jeremylongshore/tons-of-skills-marketplace

Configure CI/CD pipeline for AppFolio property management integrations. Trigger: "appfolio CI".

jeremylongshore/tons-of-skills-marketplace

Diagnose and fix common AppFolio API integration errors. Trigger: "appfolio error".

jeremylongshore/tons-of-skills-marketplace

Build property management dashboard with AppFolio API data. Trigger: "appfolio property dashboard".

jeremylongshore/tons-of-skills-marketplace

Automate tenant management and lease operations with AppFolio. Trigger: "appfolio tenant management".

jeremylongshore/tons-of-skills-marketplace

Collect AppFolio API debug evidence for support tickets. Trigger: "appfolio debug".

jeremylongshore/tons-of-skills-marketplace

Deploy AppFolio integration service to cloud infrastructure. Trigger: "deploy appfolio".

jeremylongshore/tons-of-skills-marketplace

Query AppFolio properties, units, and tenants via REST API. Trigger: "appfolio hello world".

jeremylongshore/tons-of-skills-marketplace

Configure AppFolio Stack API authentication with OAuth 2.0. Use when setting up property management API access, registering as an AppFolio Stack partner, or configuring client credentials for API calls. Trigger: "install appfolio", "setup appfolio", "appfolio auth", "appfolio API key".

jeremylongshore/tons-of-skills-marketplace

Set up local development for AppFolio property management API integration. Trigger: "appfolio local dev".

jeremylongshore/tons-of-skills-marketplace

Production readiness checklist for AppFolio integrations. Trigger: "appfolio production checklist".

jeremylongshore/tons-of-skills-marketplace

Handle AppFolio API rate limits with throttling and backoff. Trigger: "appfolio rate limit".

jeremylongshore/tons-of-skills-marketplace

Reference architecture for AppFolio property management integration. Trigger: "appfolio architecture".

相关技能