เอกสารอ้างอิง API ฉบับสมบูรณ์สำหรับโมเดลสร้างวิดีโอ Magi 2 ของ Sand AI
รุ่นของโมเดล {#}
API นี้รองรับโมเดลสามรุ่น:
Magi 2 Text to Video
ปลายทาง API
POST /api/v1/video/task
พารามิเตอร์คำขอ
จำเป็น
ไม่บังคับ
ตัวอย่างคำขอ
const response = await fetch('https://api.flaq.ai/api/v1/video/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'magi-2-text-to-video',
prompt: 'The camera glides toward a lighthouse at dusk as waves crash against the rocks',
duration: 8,
aspect_ratio: '16:9',
sound: true
})
});
const { data } = await response.json();
const taskId = data.task_id;
Magi 2 Image to Video
พารามิเตอร์คำขอ
จำเป็น
ไม่บังคับ
ตัวอย่างคำขอ
{
model_name: 'magi-2-image-to-video',
image_url: 'https://example.com/first-frame.jpg',
image_end_url: 'https://example.com/last-frame.jpg',
prompt: 'The camera slowly pulls back to reveal a waterfall and the forest around it',
duration: 8,
aspect_ratio: '16:9',
sound: false
}
Magi 2 Reference to Video
พารามิเตอร์คำขอ
จำเป็น
สื่ออ้างอิง
สื่ออ้างอิงทุกประเภทเป็นตัวเลือกและใช้ร่วมกันในคำขอเดียวได้ หากไม่ได้ส่งอาร์เรย์ทั้งสามชุด โมเดลจะสร้างวิดีโอจากพรอมต์เพียงอย่างเดียว
ตัวระบุตำแหน่งสำหรับการอ้างอิงแบบ @ (AT)
การอ้างอิงแบบ @ (AT) ใช้ตัวระบุตำแหน่ง <<<...>>> ที่มีหมายเลขกำกับในพรอมต์ สื่อแต่ละประเภทเริ่มนับจาก 1 ตามลำดับในอาร์เรย์ของสื่อประเภทนั้น
ไม่บังคับ
ตัวอย่างคำขอ
{
model_name: 'magi-2-reference-to-video',
prompt: 'Use the reference image for the subject, the reference video for the camera movement, and the reference audio for the ambience',
duration: 8,
aspect_ratio: '16:9',
sound: true,
images: ['https://example.com/subject-reference.jpg'],
videos: ['https://example.com/camera-movement-reference.mp4'],
audios: ['https://example.com/ambience-reference.mp3']
}
ตัวอย่างคำขอสร้างวิดีโอโดยอ้างอิงสื่อด้วย @ (AT)
{
model_name: 'magi-2-reference-to-video',
prompt: 'Show the cyclist from <<<image_1>>> on the trail in <<<image_2>>>. Follow the camera movement in <<<video_1>>> and use <<<audio_1>>> as a reference for the forest ambience',
duration: 10,
aspect_ratio: '16:9',
sound: true,
images: [
'https://example.com/cyclist-reference.jpg',
'https://example.com/forest-trail-reference.png'
],
videos: ['https://example.com/camera-movement-reference.mp4'],
audios: ['https://example.com/forest-ambience-reference.mp3']
}
รูปแบบการตอบกลับ
การตอบกลับครั้งแรก
ทุกโมเดลส่ง task_id กลับมาเพื่อใช้ตรวจสอบสถานะเป็นระยะ:
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/video/{task_id}",
"task_status": "submitted"
}
}
การตอบกลับเมื่อตรวจสอบสถานะ
เรียก GET /api/v1/video/{taskId} เป็นระยะเพื่อตรวจสอบสถานะ:
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/video/{task_id}",
"task_status": "succeed",
"task_status_msg": null,
"task_result": {
"videos": [
{
"url": "https://example.com/generated-video.mp4"
}
]
}
}
}
ค่าสถานะ
submitted: ระบบรับงานแล้วและกำลังรอประมวลผล
processing: กำลังสร้างวิดีโอ
succeed: สร้างวิดีโอเสร็จแล้ว
failed: สร้างวิดีโอไม่สำเร็จ
แนวทางปฏิบัติที่แนะนำ
- พรอมต์: อธิบายฉาก การกระทำ การถ่ายทำ และเสียงที่ต้องการได้ยิน
- ภาพสำหรับเฟรม: ระบุ
image_url เสมอเมื่อสร้างวิดีโอจากภาพ รวมถึงในกรณีที่ระบุ image_end_url ด้วย
- ลำดับของสื่ออ้างอิง: จัดเรียงรายการใน
images, videos และ audios ตามลำดับที่ต้องการอ้างถึงใน prompt
- เสียง: ตั้งค่า
sound เป็น false เมื่อต้องการวิดีโอที่ไม่มีเสียง