Model Wan image-to-video menghasilkan video yang mulus dari first-frame image dan text prompt.
Referensi: Panduan pengguna
Cakupan
Untuk memastikan pemanggilan API berhasil, model, URL endpoint, dan kunci API harus berada di wilayah yang sama. Pemanggilan lintas-wilayah akan gagal.
Pilih model: Pastikan model tersedia di wilayah target Anda.
Pilih URL: Gunakan URL endpoint regional yang sesuai, baik berupa URL HTTP maupun URL SDK DashScope.
Konfigurasikan kunci API: Ambil kunci API untuk wilayah tersebut, lalu konfigurasikan kunci API dalam variabel lingkungan (sedang ditinggalkan dan digabung ke Konfigurasi Kunci API).
Instal SDK: Jika ingin melakukan panggilan menggunakan SDK, instal SDK DashScope.
Kode contoh dalam topik ini berlaku untuk wilayah Singapura.
Panggilan HTTP
Tugas image-to-video memakan waktu—biasanya 1 hingga 5 menit—sehingga API menggunakan pemanggilan asinkron dua langkah: Buat tugas → Polling hasil.
Langkah 1: Buat tugas
Singapura
POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Virginia
POST https://dashscope-us.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Beijing
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Setelah tugas dibuat, gunakan
task_idyang dikembalikan untuk menanyakan hasilnya.task_idberlaku selama 24 jam. Jangan membuat tugas duplikat. Sebagai gantinya, gunakan polling untuk mengambil hasilnya.Untuk tutorial pemula, lihat Gunakan Postman atau cURL.
Parameter permintaan | Narasi multi-shotFitur ini hanya didukung oleh model wan2.6. Aktifkan dengan mengatur Dubbing otomatisFitur ini hanya didukung oleh model wan2.6 dan wan2.5. Jika Anda tidak menyediakan Sediakan file audioFitur ini hanya didukung oleh model wan2.6 dan wan2.5. Untuk menentukan musik latar atau narasi suara untuk video Anda, masukkan URL file audio kustom Anda di parameter Hasilkan video tanpa suaraHanya model-model berikut yang mendukung pembuatan video tanpa suara:
Gunakan prompt negatifGunakan parameter negative_prompt untuk mencegah munculnya “flowers” dalam video yang dihasilkan. |
Headers | |
Content-Type Tipe konten dari permintaan. Harus berupa | |
Authorization Kredensial autentikasi menggunakan kunci API Model Studio. Contoh: | |
X-DashScope-Async Mengaktifkan pemrosesan asinkron. Harus diatur ke Penting Mengembalikan error "current user api does not support synchronous calls" jika tidak disertakan. | |
Body permintaan | |
model Nama model. Untuk informasi selengkapnya mengenai model dan harga, lihat Model pricing. Contoh: wan2.6-i2v-flash. | |
input Informasi input dasar, seperti prompt. | |
parameters Parameter pemrosesan video, termasuk resolusi, durasi, penulisan ulang prompt, dan Watermark. |
Parameter respons | Respons berhasilSimpan Respons errorPembuatan task gagal. Lihat kode kesalahan untuk mengatasi masalah tersebut. |
output Informasi output task. | |
request_id Identifier unik untuk permintaan. Gunakan untuk pelacakan dan troubleshooting masalah. | |
code Kode kesalahan. Dikembalikan hanya ketika permintaan gagal. Lihat kode kesalahan untuk detailnya. | |
message Pesan kesalahan detail. Dikembalikan hanya ketika permintaan gagal. Lihat kode kesalahan untuk detailnya. |
Langkah 2: Kueri hasil
Singapore
GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
Virginia
GET https://dashscope-us.aliyuncs.com/api/v1/tasks/{task_id}
Beijing
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
Saran polling: Pembuatan video dapat memakan waktu beberapa menit. Gunakan mekanisme polling dengan interval kueri yang wajar, misalnya 15 detik, untuk mengambil hasilnya.
Transisi status task: PENDING → RUNNING → SUCCEEDED atau FAILED.
URL hasil: Setelah task berhasil, URL video akan dikembalikan. URL tersebut berlaku selama 24 jam. Setelah Anda mendapatkan URL-nya, segera unduh dan simpan video tersebut ke layanan penyimpanan permanen, seperti Object Storage Service (OSS).
Masa berlaku task_id: 24 jam. Setelah periode ini, Anda tidak dapat lagi melakukan kueri terhadap hasilnya, dan API akan mengembalikan status task sebagai
UNKNOWN.
Parameter permintaan | Hasil Kueri TugasGanti |
Header | |
Authorization Kredensial otentikasi menggunakan kunci API Model Studio. Contoh: | |
Parameter path URL | |
task_id ID dari task yang akan dikueri. |
Parameter respons | Task berhasilURL video hanya disimpan selama 24 jam, lalu secara otomatis di-purge. Segera simpan video yang dihasilkan. Task gagalJika task gagal, Kueri task kedaluwarsa
|
output Informasi output task. | |
usage Statistik output. Hanya hasil yang berhasil yang dihitung. | |
request_id Identifier unik untuk permintaan. Gunakan untuk pelacakan dan troubleshooting masalah. |
Panggilan SDK DashScope
Nama parameter SDK sebagian besar sesuai dengan API HTTP. Struktur parameter mengikuti konvensi spesifik bahasa.
Karena tugas image-to-video memakan waktu—biasanya 1 hingga 5 menit—SDK membungkus alur panggilan HTTP asinkron dan mendukung pemanggilan sinkron maupun asinkron.
Waktu pemrosesan aktual bergantung pada panjang antrian dan eksekusi layanan. Tunggu hasilnya dengan sabar.
Memanggil SDK Python
Pastikan versi SDK Python DashScope Anda minimal 1.25.8 sebelum menjalankan kode berikut.
Jika versinya terlalu lama, kesalahan seperti “url error, please check url!” dapat terjadi. Perbarui SDK seperti dijelaskan dalam Instal SDK.
Atur base_http_api_url berdasarkan wilayah model:
Singapura
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
Virginia
dashscope.base_http_api_url = 'https://dashscope-us.aliyuncs.com/api/v1'
Beijing
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
Kode contoh
Panggilan sinkron
Panggilan sinkron memblokir hingga video dihasilkan. Contoh ini menunjukkan tiga metode input gambar: URL publik, enkripsi Base64, dan jalur file lokal.
Contoh permintaan
import base64
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import mimetypes
import dashscope
# Berikut adalah endpoint untuk wilayah Singapura. Untuk informasi lebih lanjut, lihat: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# Jika Anda belum mengonfigurasi variabel lingkungan DASHSCOPE_API_KEY, ganti baris berikut dengan kunci API Model Studio Anda: api_key="sk-xxx"
# Untuk mendapatkan kunci API, kunjungi: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- Fungsi bantu: Untuk enkripsi Base64 ---
# Format: data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("Format gambar tidak didukung atau tidak dikenali")
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
return f"data:{mime_type};base64,{encoded_string}"
"""
Metode input gambar:
Contoh ini menunjukkan tiga cara untuk memberikan gambar input.
1. URL publik: Cocok untuk gambar yang dapat diakses publik.
2. File lokal: Cocok untuk pengembangan dan pengujian lokal.
3. Enkripsi Base64: Cocok untuk gambar pribadi atau skenario yang memerlukan transmisi terenkripsi.
"""
# [Metode 1] Gunakan URL gambar yang dapat diakses publik
# Contoh: Gunakan URL gambar publik
img_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
# [Metode 2] Gunakan file lokal (mendukung jalur absolut dan relatif)
# Persyaratan format: file:// + jalur file
# Contoh (jalur absolut):
# img_url = "file://" + "/path/to/your/img.png" # Linux/macOS
# img_url = "file://" + "C:/path/to/your/img.png" # Windows
# Contoh (jalur relatif):
# img_url = "file://" + "./img.png" # Jalur relatif terhadap direktori skrip saat ini
# [Metode 3] Gunakan gambar terenkripsi Base64
# img_url = encode_file("./img.png")
# Atur URL audio
audio_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
def sample_call_i2v():
# Panggilan sinkron yang mengembalikan hasil langsung.
print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
model='wan2.6-i2v-flash',
prompt='A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.',
img_url=img_url,
audio_url=audio_url,
resolution="720P",
duration=10,
prompt_extend=True,
watermark=False,
negative_prompt="",
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("video_url:", rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_call_i2v()Contoh respons
video_url berlaku selama 24 jam. Segera unduh.
{
"status_code": 200,
"request_id": "2794c7a3-fe8c-4dd4-a1b7-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "c15d5b14-07c4-4af5-b862-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"submit_time": "2026-01-22 23:24:46.527",
"scheduled_time": "2026-01-22 23:24:46.565",
"end_time": "2026-01-22 23:25:59.978",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise."
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"input_video_duration": 0,
"output_video_duration": 10,
"audio": true,
"SR": 720
}
}Panggilan asinkron
Contoh ini menunjukkan panggilan asinkron. Mengembalikan ID tugas segera. Anda harus melakukan polling untuk hasil atau menunggu hingga selesai.
Contoh permintaan
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# Berikut adalah endpoint untuk wilayah Singapura. Untuk mendapatkan endpoint wilayah lain, kunjungi: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan kunci API Model Studio Anda: api_key="sk-xxx"
# Dapatkan kunci API Anda: https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
# Gunakan URL gambar yang dapat diakses publik
img_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
# Atur URL audio
audio_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
def sample_async_call_i2v():
# Panggilan asinkron, mengembalikan task_id
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-i2v-flash',
prompt='A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.',
img_url=img_url,
audio_url=audio_url,
resolution="720P",
duration=10,
prompt_extend=True,
watermark=False,
negative_prompt="",
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("task_id: %s" % rsp.output.task_id)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
# Dapatkan informasi tentang tugas asinkron.
status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
if status.status_code == HTTPStatus.OK:
print(status.output.task_status)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(status.status_code, status.code, status.message))
# Tunggu hingga tugas asinkron selesai.
rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_i2v()Contoh respons
1. Contoh respons untuk pembuatan tugas
{
"status_code": 200,
"request_id": "6dc3bf6c-be18-9268-9c27-xxxxxx",
"code": "",
"message": "",
"output": {
"task_id": "686391d9-7ecf-4290-a8e9-xxxxxx",
"task_status": "PENDING",
"video_url": ""
},
"usage": null
}2. Contoh respons untuk menanyakan hasil tugas
video_url berlaku selama 24 jam. Segera unduh.
{
"status_code": 200,
"request_id": "2794c7a3-fe8c-4dd4-a1b7-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "c15d5b14-07c4-4af5-b862-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"submit_time": "2026-01-22 23:24:46.527",
"scheduled_time": "2026-01-22 23:24:46.565",
"end_time": "2026-01-22 23:25:59.978",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise."
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"input_video_duration": 0,
"output_video_duration": 10,
"audio": true,
"SR": 720
}
}Pemanggilan SDK Java
Pastikan versi SDK Java DashScope Anda minimal 2.22.6 sebelum menjalankan kode berikut.
Jika versinya terlalu lama, kesalahan seperti “url error, please check url!” dapat terjadi. Perbarui SDK seperti dijelaskan dalam Instal SDK.
Atur baseHttpApiUrl berdasarkan wilayah model:
Singapura
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
Virginia
Constants.baseHttpApiUrl = "https://dashscope-us.aliyuncs.com/api/v1";
Beijing
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
Kode contoh
Panggilan sinkron
Panggilan sinkron memblokir hingga video dihasilkan. Contoh ini menunjukkan tiga metode input gambar: URL publik, enkripsi Base64, dan jalur file lokal.
Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
public class Image2Video {
static {
// URL wilayah Singapura. Dapatkan URL: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan kunci API Model Studio Anda: apiKey="sk-xxx"
// Dapatkan kunci API Anda: https://www.alibabacloud.com/help/zh/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* Metode input gambar: Pilih salah satu dari tiga berikut
*
* 1. Gunakan URL publik - Cocok untuk gambar yang dapat diakses publik
* 2. Gunakan file lokal - Cocok untuk pengembangan dan pengujian lokal
* 3. Gunakan enkripsi Base64 - Cocok untuk gambar pribadi atau skenario yang memerlukan transmisi terenkripsi
*/
// [Metode 1] URL publik
static String imgUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png";
// [Metode 2] Jalur file lokal (file://+jalur absolut)
// static String imgUrl = "file://" + "/your/path/to/img.png"; // Linux/macOS
// static String imgUrl = "file://" + "/C:/your/path/to/img.png"; // Windows
// [Metode 3] Enkripsi Base64
// static String imgUrl = Image2Video.encodeFile("/your/path/to/img.png");
// Atur URL audio
static String audioUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3";
public static void image2video() throws ApiException, NoApiKeyException, InputRequiredException {
// Atur parameter
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("seed", 12345);
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-i2v-flash")
.prompt("A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.")
.imgUrl(imgUrl)
.audioUrl(audioUrl)
.duration(10)
.parameters(parameters)
.resolution("720P")
.negativePrompt("")
.build();
System.out.println("please wait...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
/**
* Enkode file menjadi string Base64
* @param filePath Jalur file
* @return String Base64 dalam format: data:{MIME_type};base64,{base64_data}
*/
public static String encodeFile(String filePath) {
Path path = Paths.get(filePath);
if (!Files.exists(path)) {
throw new IllegalArgumentException("File tidak ada: " + filePath);
}
// Deteksi tipe MIME
String mimeType = null;
try {
mimeType = Files.probeContentType(path);
} catch (IOException e) {
throw new IllegalArgumentException("Tidak dapat mendeteksi tipe file: " + filePath);
}
if (mimeType == null || !mimeType.startsWith("image/")) {
throw new IllegalArgumentException("Format gambar tidak didukung atau tidak dikenali");
}
// Baca konten file dan enkode
byte[] fileBytes = null;
try{
fileBytes = Files.readAllBytes(path);
} catch (IOException e) {
throw new IllegalArgumentException("Tidak dapat membaca konten file: " + filePath);
}
String encodedString = Base64.getEncoder().encodeToString(fileBytes);
return "data:" + mimeType + ";base64," + encodedString;
}
public static void main(String[] args) {
try {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}Contoh respons
video_url berlaku selama 24 jam. Segera unduh.
{
"request_id": "87c091bb-7a3c-4904-8501-xxxxxx",
"output": {
"task_id": "413ed6e4-5f3a-4f57-8d58-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.",
"submit_time": "2026-01-22 23:25:45.729",
"scheduled_time": "2026-01-22 23:25:45.771",
"end_time": "2026-01-22 23:26:44.942"
},
"usage": {
"video_count": 1,
"duration": 10.0,
"input_video_duration": 0.0,
"output_video_duration": 10.0,
"SR": "720"
},
"status_code": 200,
"code": "",
"message": ""
}Panggilan asinkron
Contoh ini menunjukkan panggilan asinkron. Mengembalikan ID tugas segera. Anda harus melakukan polling untuk hasil atau menunggu hingga selesai.
Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.util.HashMap;
import java.util.Map;
public class Image2Video {
static {
// URL berikut untuk wilayah Singapura. Untuk referensi API, kunjungi: https://www.alibabacloud.com/help/en/model-studio/image-to-video-api-reference
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan kunci API Model Studio Anda: api_key="sk-xxx"
// Dapatkan kunci API Anda: https://www.alibabacloud.com/help/zh/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
// Atur URL gambar input.
static String imgUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png";
// Atur URL audio.
static String audioUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3";
public static void image2video() throws ApiException, NoApiKeyException, InputRequiredException {
// Atur parameter.
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("seed", 12345);
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-i2v-flash")
.prompt("A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.")
.imgUrl(imgUrl)
.audioUrl(audioUrl)
.duration(10)
.parameters(parameters)
.resolution("720P")
.negativePrompt("")
.build();
// Panggilan asinkron
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
// Dapatkan hasilnya.
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
// Dapatkan daftar tugas.
public static void listTask() throws ApiException, NoApiKeyException {
VideoSynthesis is = new VideoSynthesis();
AsyncTaskListParam param = AsyncTaskListParam.builder().build();
param.setApiKey(apiKey);
VideoSynthesisListResult result = is.list(param);
System.out.println(result);
}
// Ambil hasil tugas tunggal.
public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
VideoSynthesis is = new VideoSynthesis();
// Jika DASHSCOPE_API_KEY diatur sebagai variabel lingkungan, apiKey bisa null.
VideoSynthesisResult result = is.fetch(taskId, apiKey);
System.out.println(result.getOutput());
System.out.println(result.getUsage());
}
public static void main(String[] args) {
try {
image2video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}Contoh respons
1. Contoh respons untuk pembuatan tugas
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. Contoh respons untuk menanyakan hasil tugas
video_url berlaku selama 24 jam. Segera unduh.
{
"request_id": "87c091bb-7a3c-4904-8501-xxxxxx",
"output": {
"task_id": "413ed6e4-5f3a-4f57-8d58-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=xxx",
"orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.",
"submit_time": "2026-01-22 23:25:45.729",
"scheduled_time": "2026-01-22 23:25:45.771",
"end_time": "2026-01-22 23:26:44.942"
},
"usage": {
"video_count": 1,
"duration": 10.0,
"input_video_duration": 0.0,
"output_video_duration": 10.0,
"SR": "720"
},
"status_code": 200,
"code": "",
"message": ""
}Batasan
Validitas data: Baik task_id maupun URL video hanya disimpan selama 24 jam. Setelah kedaluwarsa, tidak dapat ditanyakan atau diunduh.
Moderasi konten: Konten input (seperti prompt, gambar) dan video output menjalani pemeriksaan keamanan konten. Pelanggaran mengembalikan kesalahan seperti “IPInfringementSuspect” atau “DataInspectionFailed”. Lihat Pesan kesalahan.
Kode kesalahan
Jika pemanggilan model gagal dan mengembalikan pesan kesalahan, lihat Pesan kesalahan untuk troubleshooting.
FAQ
T: Bagaimana cara menghasilkan video dengan rasio aspek tertentu (misalnya, 3:4)?
J: Rasio aspek video output ditentukan oleh gambar first-frame input (img_url). Namun, rasio eksak (misalnya, tepat 3:4) tidak dijamin—penyimpangan kecil dapat terjadi.
Mengapa terjadi penyimpangan:
Model menggunakan rasio gambar input Anda sebagai garis dasar dan menghitung resolusi valid terdekat berdasarkan total piksel target (ditentukan oleh resolution). Karena lebar dan tinggi harus kelipatan 16, dilakukan penyesuaian kecil. Jadi meskipun rasio output tidak tepat 3:4, akan sangat mendekati.
Contoh: Gambar input 750×1000 (rasio aspek 3:4 = 0,75), dengan resolution = "720P" (target ~920.000 piksel) menghasilkan output 816×1104 (rasio aspek ≈ 0,739, ~900.000 piksel).
Praktik terbaik:
Kontrol input: Gunakan gambar dengan rasio aspek target Anda sebagai first frame.
Pasca-pemrosesan: Jika rasio ketat diperlukan, potong atau tambahkan padding pada video yang dihasilkan menggunakan alat editing.
T: Bagaimana cara mendapatkan daftar putih nama domain untuk penyimpanan video?
J: Video yang dihasilkan model disimpan di OSS. API mengembalikan URL publik sementara. Untuk mengonfigurasi daftar putih firewall untuk URL unduhan ini, perhatikan hal berikut: Penyimpanan dasar dapat berubah secara dinamis. Topik ini tidak menyediakan daftar putih nama domain OSS tetap untuk mencegah masalah akses akibat informasi yang kedaluwarsa. Jika Anda memiliki persyaratan kontrol keamanan, hubungi manajer akun Anda untuk mendapatkan daftar nama domain OSS terbaru.