多模态视频编辑
添加 Kling 视频选区
使用 Kling Add Video Selection 端点,在多元素视频编辑中添加选区元素,通过 CometAPI 实现定向编辑和场景控制。
POST
/
kling
/
v1
/
videos
/
multi-elements
/
add-selection
cURL
curl https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"session_id": "<session_id>",
"frame_index": 1,
"points": [
{
"x": 0.5,
"y": 0.5
}
]
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"session_id": "<session_id>",
"frame_index": 1,
"points": [
{
"x": 0.5,
"y": 0.5
}
]
},
)
result = response.json()
print(result.get("code"), result.get("data"))const response = await fetch("https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"session_id": "<session_id>",
"frame_index": 1,
"points": [
{
"x": 0.5,
"y": 0.5
}
]
}),
});
const result = await response.json();
console.log(result.code, result.data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'session_id' => '<session_id>',
'frame_index' => 1,
'points' => [
[
'x' => 0.5,
'y' => 0.5
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection"
payload := strings.NewReader("{\n \"session_id\": \"<session_id>\",\n \"frame_index\": 1,\n \"points\": [\n {\n \"x\": 0.5,\n \"y\": 0.5\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"session_id\": \"<session_id>\",\n \"frame_index\": 1,\n \"points\": [\n {\n \"x\": 0.5,\n \"y\": 0.5\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"session_id\": \"<session_id>\",\n \"frame_index\": 1,\n \"points\": [\n {\n \"x\": 0.5,\n \"y\": 0.5\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"message": "<string>",
"data": {}
}使用此端点标记你希望多模态编辑器操作的视频区域。
选区如何工作
session_id来自初始化待编辑视频- 使用同一账号以及初始化返回的完全相同的
session_id frame_index用于选择你放置点位的帧points是介于0和1之间的归一化坐标- Kling 文档说明最多可标记 10 帧,每帧最多 10 个点
工作流中的作用
完整参数说明请参阅 Kling API documentation。
授权
Bearer token authentication. Use your CometAPI key.
请求体
application/json
Selection session id returned by init-selection. Follow-up calls must use the same account and exact session id.
Frame number
Supports adding up to 10 marked frames, meaning video selections can be marked based on a maximum of 10 frames. Only 1 frame can be marked at a time.
Click coordinates, represented by x and y. Value range: [0,1], expressed as a percentage; [0,1] represents the top-left corner of the frame. Supports adding multiple marked points simultaneously, with a maximum of 10 points per frame.
Show child attributes
Show child attributes
⌘I
cURL
curl https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"session_id": "<session_id>",
"frame_index": 1,
"points": [
{
"x": 0.5,
"y": 0.5
}
]
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"session_id": "<session_id>",
"frame_index": 1,
"points": [
{
"x": 0.5,
"y": 0.5
}
]
},
)
result = response.json()
print(result.get("code"), result.get("data"))const response = await fetch("https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"session_id": "<session_id>",
"frame_index": 1,
"points": [
{
"x": 0.5,
"y": 0.5
}
]
}),
});
const result = await response.json();
console.log(result.code, result.data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'session_id' => '<session_id>',
'frame_index' => 1,
'points' => [
[
'x' => 0.5,
'y' => 0.5
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection"
payload := strings.NewReader("{\n \"session_id\": \"<session_id>\",\n \"frame_index\": 1,\n \"points\": [\n {\n \"x\": 0.5,\n \"y\": 0.5\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"session_id\": \"<session_id>\",\n \"frame_index\": 1,\n \"points\": [\n {\n \"x\": 0.5,\n \"y\": 0.5\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/videos/multi-elements/add-selection")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"session_id\": \"<session_id>\",\n \"frame_index\": 1,\n \"points\": [\n {\n \"x\": 0.5,\n \"y\": 0.5\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"message": "<string>",
"data": {}
}