Model Wan image-to-video menghasilkan video yang mulus dari gambar frame pertama dan prompt teks.
Referensi: Panduan pengguna
Wan - image-to-video 2.7 yang baru dirilis mendukung first-frame-to-video, first-and-last-frame-to-video, dan kelanjutan video. Kami merekomendasikan penggunaannya sebagai pilihan utama Anda.
Model Wan image-to-video dalam topik ini (wan2.6 dan versi sebelumnya) hanya mendukung first-frame-to-video.
Ketersediaan
Model, URL endpoint, dan Kunci API harus berada di Wilayah yang sama — pemanggilan cross-region akan gagal.
Pilih model: Pastikan model tersedia di wilayah target Anda.
Pilih URL: Pilih URL endpoint regional yang sesuai. HTTP dan HTTPS didukung.
Konfigurasikan Kunci API: Pilih wilayah, dapatkan Kunci API, dan konfigurasikan dalam Variabel lingkungan.
Instal SDK: Jika Anda berencana memanggil API menggunakan SDK, instal SDK DashScope.
Kode contoh dalam topik ini berlaku untuk Wilayah Singapura.
HTTP
Tugas image-to-video memerlukan waktu 1–5 menit. Gunakan pemanggilan asinkron: buat tugas, lalu polling hasilnya.
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
Frankfurt
POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Ganti WorkspaceId dengan Workspace ID aktual Anda saat melakukan panggilan API.
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 panduan pemula, lihat Postman.
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 memberikan Menyediakan 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 dalam parameter Menghasilkan 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. |
Header | |
Content-Type Tipe konten permintaan. Harus | |
Authorization Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. | |
X-DashScope-Async Mengaktifkan pemrosesan asinkron. Permintaan HTTP hanya mendukung panggilan asinkron. Harus Penting Jika header permintaan ini tidak ada, kesalahan "current user api does not support synchronous calls" akan dikembalikan. | |
Body permintaan | |
model Nama model. Periksa harga model. Contoh: wan2.6-i2v-flash. | |
input Berisi informasi input dasar (misalnya, prompt). | |
parameters Parameter pemrosesan video (resolusi, durasi, penulisan ulang prompt, watermark). |
Parameter respons | Respons berhasilSimpan Respons kesalahanPembuatan tugas gagal. Lihat Pesan kesalahan. |
output Informasi output tugas. | |
request_id Identifier permintaan unik untuk pelacakan dan troubleshooting. | |
code Kode kesalahan, hanya dikembalikan untuk permintaan yang gagal. Lihat Pesan kesalahan. | |
message Pesan kesalahan terperinci. Hanya dikembalikan untuk permintaan yang gagal. Lihat Pesan kesalahan. |
Langkah 2: Tanyakan hasilnya
Singapura
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}
Frankfurt
GET https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
Ganti WorkspaceId dengan Workspace ID aktual Anda saat melakukan panggilan API.
Rekomendasi polling: Pembuatan video memerlukan beberapa menit. Gunakan mekanisme polling dengan interval yang wajar, misalnya 15 detik.
Transisi status tugas: PENDING → RUNNING → SUCCEEDED atau FAILED.
Tautan hasil: Setelah tugas berhasil, URL video yang berlaku selama 24 jam dikembalikan. Unduh dan simpan video ke penyimpanan permanen, seperti OSS.
Validitas
task_id: 24 jam. Setelah periode ini, kueri mengembalikan status tugas sebagaiUNKNOWN.
Parameter permintaan | Tanyakan hasil tugasGanti |
Header | |
Authorization Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. | |
Parameter jalur URL | |
task_id ID tugas. |
Parameter respons | Tugas berhasilURL video hanya berlaku selama 24 jam, lalu secara otomatis dihapus. Segera simpan video yang dihasilkan. Tugas gagalSaat tugas gagal, Kueri tugas kedaluwarsa
|
output Informasi output tugas. | |
usage Statistik output. Hanya dihitung untuk hasil yang berhasil. | |
request_id Identifier permintaan unik untuk pelacakan dan troubleshooting. |
SDK DashScope
Nama parameter SDK sebagian besar sesuai dengan API HTTP (struktur mengikuti konvensi bahasa).
Tugas image-to-video memerlukan waktu 1–5 menit. SDK membungkus alur panggilan HTTP asinkron dan mendukung pemanggilan sinkron maupun asinkron.
Waktu pemrosesan aktual tergantung pada panjang antrian dan eksekusi layanan. Tunggu hasilnya dengan sabar.
SDK Python
Membutuhkan SDK Python DashScope ≥ 1.25.8. Versi lama mungkin error (“url error, please check url!”) — lihat Instal SDK untuk memperbarui.
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'
Frankfurt
dashscope.base_http_api_url = 'https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1'
Ganti WorkspaceId dengan Workspace ID aktual Anda saat melakukan panggilan API.
Kode contoh
Panggilan sinkron
Panggilan sinkron memblokir hingga selesai. Tiga metode input gambar: URL publik, Base64, jalur file lokal.
Contoh permintaan
import base64
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import mimetypes
import dashscope
# URL wilayah Singapura. Dapatkan URL: 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")
# --- Fungsi bantu: Untuk encoding 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:
Pilih salah satu dari tiga metode berikut,
1. Gunakan URL publik - Cocok untuk gambar yang dapat diakses publik
2. Gunakan file lokal - Cocok untuk pengembangan dan pengujian lokal
3. Gunakan encoding Base64 - Cocok untuk gambar privat 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" # Relatif terhadap jalur file yang dapat dieksekusi saat ini
# [Metode 3] Gunakan gambar yang diencode 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, mengembalikan hasil langsung
print('mohon tunggu...')
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('Gagal, 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
Panggilan asinkron mengembalikan task ID segera. Polling hasilnya atau tunggu hingga selesai.
Contoh permintaan
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# URL wilayah Singapura. Dapatkan URL: 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('Gagal, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
# Dapatkan informasi tugas asinkron
status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
if status.status_code == HTTPStatus.OK:
print(status.output.task_status)
else:
print('Gagal, 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('Gagal, 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
}
}SDK Java
Membutuhkan SDK Java DashScope ≥ 2.22.6. Versi lama mungkin error (“url error, please check url!”) — lihat Instal SDK untuk memperbarui.
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";
Frankfurt
Constants.baseHttpApiUrl = "https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1";
Ganti WorkspaceId dengan Workspace ID aktual Anda saat melakukan panggilan API.
Kode contoh
Panggilan sinkron
Panggilan sinkron memblokir hingga selesai. Tiga metode input gambar: URL publik, Base64, 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 encoding Base64 - Cocok untuk gambar privat 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] Encoding 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("mohon tunggu...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
/**
* Encode 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 encode
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
Panggilan asinkron mengembalikan task ID segera. Polling hasilnya atau tunggu 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 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: 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("mohon tunggu...");
// Dapatkan hasil
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);
}
// Dapatkan 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: task_id dan URL video hanya disimpan selama 24 jam. Setelah kedaluwarsa, tidak dapat ditanyakan atau diunduh.
Moderasi konten: Input (prompt, gambar) dan output menjalani pemeriksaan keamanan. Pelanggaran mengembalikan kesalahan (misalnya, “IPInfringementSuspect”, “DataInspectionFailed”). Lihat .
Kode kesalahan
Untuk panggilan dan kesalahan yang gagal, lihat Pesan kesalahan untuk troubleshooting.
FAQ
T: Bagaimana cara menghasilkan video dengan rasio aspek tertentu (misalnya, 3:4)?
J: Rasio aspek output sesuai dengan gambar input (img_url), tetapi rasio pasti (misalnya, 3:4 ketat) tidak dijamin — kemungkinan terjadi penyimpangan kecil.
Mengapa terjadi penyimpangan:
Model menggunakan rasio gambar input sebagai garis dasar, menghitung resolusi valid terdekat berdasarkan piksel target (diatur oleh resolution). Lebar/tinggi harus kelipatan 16, sehingga memerlukan penyesuaian kecil. Rasio output mendekati target (misalnya, 3:4) tetapi tidak tepat.
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 sebagai frame pertama.
Pasca-pemrosesan: Untuk rasio ketat, potong atau tambahkan padding pada video yang dihasilkan dengan 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 unduh 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.