Communitygithub.com

Kling AI 视频扩展

使用 Kling AI 延续功能延长视频时长。适用于从短片段创建更长视频或构建序列。可通过诸如“klingai 延长视频”、“kling ai 视频延续”、“klingai 更长视频”、“延长 klingai 片段”等短语触发。

Kling AI 视频扩展 是什么?

该技能使开发者能够通过 Kling AI 的 API 实现视频扩展,从而无缝延长视频时长。它允许用户将现有视频(通过其 `task_id` 标识)的时长按 5 秒的增量延长,并可自定义提示词和模式(标准或专业)。该技能支持连续多次扩展,可用于构建总时长达 20 秒或更长的视频。它主要适用于 Claude Code、Cursor 或 Codex 等 AI 编码代理,提供了可直接运行的 Python 代码示例,以便与 Kling API 集成,处理身份验证、任务提交和结果轮询。该技能还包含了成本计算(每次扩展消耗 10 或 35 个积分)、错误处理指导,以及操作指令(如版权验证、审查和预算控制),以确保生成内容的安全和合规。

兼容平台✓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-video-extension

在你喜欢的 AI 中提问

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

文档

Kling AI 视频扩展 是做什么的?

概述

通过追加额外的秒数来扩展现有视频。扩展接口接收已完成视频的 task_id,并生成无缝的延续内容。

端点: POST https://api.klingai.com/v1/videos/video-extend

请求参数

参数类型必填描述
task_id字符串是已完成源视频的任务 ID
prompt字符串否扩展部分的运动/场景描述
duration字符串否扩展长度:"5"(默认值)
mode字符串否"standard" 或 "professional"
model_name字符串否默认值:"kling-v2-master"
callback_url字符串否完成回调的 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"}

# 第1步:生成初始的5秒视频
initial = requests.post(f"{BASE}/videos/text2video", headers=get_headers(), json={
    "model_name": "kling-v2-master",
    "prompt": "A rocket launching from a desert landscape, cinematic",
    "duration": "5",
    "mode": "standard",
}).json()
initial_task_id = initial["data"]["task_id"]

# 等待完成...
# (轮询直到 task_status == "succeed")

# 第2步:延长 5 秒
extension = requests.post(f"{BASE}/videos/video-extend", headers=get_headers(), json={
    "task_id": initial_task_id,
    "prompt": "The rocket ascends through clouds into the stratosphere",
    "duration": "5",
    "mode": "standard",
}).json()
ext_task_id = extension["data"]["task_id"]

# 第3步:轮询扩展任务
while True:
    time.sleep(15)
    result = requests.get(
        f"{BASE}/videos/video-extend/{ext_task_id}", headers=get_headers()
    ).json()
    if result["data"]["task_status"] == "succeed":
        extended_url = result["data"]["task_result"]["videos"][0]["url"]
        print(f"Extended video: {extended_url}")
        break
    elif result["data"]["task_status"] == "failed":
        print(f"Failed: {result['data']['task_status_msg']}")
        break

链式多次扩展

def chain_extensions(initial_task_id: str, prompts: list[str],
                     duration: str = "5", mode: str = "standard") -> list[str]:
    """链式多次扩展以构建更长的视频。"""
    current_task_id = initial_task_id
    video_urls = []

    for i, prompt in enumerate(prompts):
        print(f"扩展 {i + 1}/{len(prompts)}:提交中...")

        # 提交扩展
        r = requests.post(f"{BASE}/videos/video-extend", headers=get_headers(), json={
            "task_id": current_task_id,
            "prompt": prompt,
            "duration": duration,
            "mode": mode,
        }).json()
        ext_task_id = r["data"]["task_id"]

        # 轮询直至完成
        while True:
            time.sleep(15)
            result = requests.get(
                f"{BASE}/videos/video-extend/{ext_task_id}", headers=get_headers()
            ).json()
            status = result["data"]["task_status"]

            if status == "succeed":
                url = result["data"]["task_result"]["videos"][0]["url"]
                video_urls.append(url)
                current_task_id = ext_task_id  # 下一次扩展从此链式衔接
                print(f"扩展 {i + 1} 完成:{url}")
                break
            elif status == "failed":
                raise RuntimeError(f"扩展 {i + 1} 失败:{result['data']['task_status_msg']}")

    return video_urls

用法:构建一个 20 秒的视频

# 生成初始的 5 秒视频
initial_r = requests.post(f"{BASE}/videos/text2video", headers=get_headers(), json={
    "model_name": "kling-v2-master",
    "prompt": "Morning sunrise over a mountain lake, mist rising",
    "duration": "5",
    "mode": "standard",
}).json()
initial_id = initial_r["data"]["task_id"]
# ... 轮询直至完成 ...

# 再链式扩展 3 次 = 5 + 5 + 5 + 5 = 总共 20 秒
extensions = chain_extensions(initial_id, [
    "Sun rises higher, birds begin flying across the lake",
    "A deer approaches the water's edge to drink",
    "Wide shot pulling back to reveal the full mountain range",
])

费用

每次扩展的费用与一次新的生成相同:

扩展时长标准专业
5 秒10 积分35 积分

一个 20 秒的视频(初始 + 3 次扩展)在标准模式下消耗 40 积分。

错误处理

错误原因修复
无效的 task_id源任务不存在验证 task_id 是否来自一个已完成的生成任务
源未完成正在扩展一个仍在处理中的任务等待源任务达到 succeed 状态
扩展失败提示词与源冲突使扩展提示词与原始场景保持一致

前提条件

  • 一个已完成、版权已清除或合成的源草稿、经批准的扩展简报、已授权的 workspace 和积分预算、政策审查、仅限草稿的目标,以及一个回滚/移除负责人。

操作说明

  1. 在创建扩展之前,确认源视频的所有权、完成状态和批准的连续性简报;不要使用私有、未经许可或受政策限制的材料。
  2. 在批准的时长和积分上限内提交一个带水印的草稿代表任务,然后验证政策、权利、质量和目标控制。
  3. 如果出现连续性、政策、权利或预算偏离,立即停止并删除扩展任务,而不是发布它。
  4. 仅在获得所有者批准后才进行推广;保留一份脱敏收据,并在约定的保留期限后删除临时资产。

输出

生成一份扩展收据,其中包含源任务参考、权利分类、模式/时长、积分估算、政策审查、草稿目标、审批人、保留/删除参考以及任务 ID。排除提示词、身份信息和资产 URL。

示例

source=synthetic-task-42; rights=cleared; duration=5s; mode=standard; policy=pass; destination=draft-only; cleanup=24h 可安全用于审查。

资源

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".

相关技能