All Products
Search
Document Center

Alibaba Cloud Model Studio:Image-to-video: frame pertama dan terakhir

Last Updated:Jul 15, 2026

Model image-to-video Wan menghasilkan video yang mulus dari gambar frame pertama, gambar frame terakhir, dan prompt teks opsional.

  • Spesifikasi video: Durasi tetap 5 detik dan resolusi kustom (480P/720P/1080P).

  • Kemampuan tambahan: Penulisan ulang prompt dan Watermark.

Tautan cepat: Referensi API | Panduan prompt

Mulai

Prompt

Frame pertama

Frame terakhir

Video output

A cute blue monster with a slightly sad expression stands in the rain. The camera slowly zooms in and stops on the moment it looks up at the sky.

image

image

Sebelum memanggil API: Dapatkan Kunci API, tetapkan sebagai Variabel lingkungan, dan instal SDK DashScope.

Python SDK

Penting

Memerlukan SDK Python DashScope ≥ 1.25.8. Versi lama mungkin menampilkan error "url error, please check url!". Instal SDK.

import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope

# URL berikut untuk wilayah Singapura. Saat memanggil, ganti {WorkspaceId} dengan ID ruang kerja aktual Anda. URL berbeda-beda per wilayah. Dapatkan URL Anda: https://www.alibabacloud.com/help/en/model-studio/image-to-video-by-first-and-last-frame-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# Kunci API berbeda per wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY", "YOUR_API_KEY")

print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
                          model="wan2.2-kf2v-flash",
                          prompt="A cute blue monster with a slightly sad expression stands in the rain. The camera slowly zooms in and stops on the moment it looks up at the sky.",
                          first_frame_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/ixdxvt/wan-kf2v-blue-1.png",
                          last_frame_url="https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/nhtdrc/wan-kf2v-blue-2.png",
                          duration=5,  # Tetap 5 detik. Jangan ubah.
                          prompt_extend=True,
                          watermark=True)
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))

Java SDK

Penting

Memerlukan SDK Java DashScope ≥ 2.22.6. Versi lama mungkin menampilkan error "url error, please check url!". Instal SDK.

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;

public class Image2Video {

    static {
        // URL berikut untuk wilayah Singapura. Saat memanggil, ganti {WorkspaceId} dengan ID ruang kerja aktual Anda. URL berbeda-beda per wilayah. Dapatkan URL Anda: https://www.alibabacloud.com/help/en/model-studio/image-to-video-by-first-and-last-frame-api-reference
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // Jika Anda belum menetapkan variabel lingkungan, ganti baris di bawah ini dengan: apiKey="sk-xxx"
    // Kunci API berbeda per wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void image2video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.2-kf2v-flash")
                        .prompt("A cute blue monster with a slightly sad expression stands in the rain. The camera slowly zooms in and stops on the moment it looks up at the sky.")
                        .firstFrameUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/ixdxvt/wan-kf2v-blue-1.png")
                        .lastFrameUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/nhtdrc/wan-kf2v-blue-2.png")
                        .resolution("720P")
                        .promptExtend(true)
                        .watermark(true)
                        .build();
        System.out.println("please wait...");
        VideoSynthesisResult result = vs.call(param);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            image2video();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}

curl

Langkah 1: Buat tugas untuk mendapatkan ID tugas

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.2-kf2v-flash",
    "input": {
        "first_frame_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/ixdxvt/wan-kf2v-blue-1.png",
        "last_frame_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260126/nhtdrc/wan-kf2v-blue-2.png",
        "prompt": "A cute blue monster with a slightly sad expression stands in the rain. The camera slowly zooms in and stops on the moment it looks up at the sky."
    },
    "parameters": {
        "resolution": "720P",
        "prompt_extend": true,
        "watermark": true
    }
}'

Langkah 2: Dapatkan hasil menggunakan ID tugas

Ganti {task_id} dengan nilai task_id yang dikembalikan oleh pemanggilan API sebelumnya. task_id berlaku untuk kueri selama 24 jam.

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Contoh output

video_url kedaluwarsa setelah 24 jam. Unduh video tersebut segera.
{
    "request_id": "c1209113-8437-424f-a386-xxxxxx",
    "output": {
        "task_id": "966cebcd-dedc-4962-af88-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
         ...
    },
    ...
}

Ketersediaan

  • Model yang didukung berbeda-beda per wilayah. Sumber daya terisolasi antar wilayah. Untuk model yang didukung di setiap wilayah, lihat Konsol Model Studio.

  • Saat melakukan pemanggilan, pastikan model, URL titik akhir, dan Kunci API Anda semuanya berasal dari wilayah yang sama. Pemanggilan lintas-wilayah akan gagal.

Catatan

Kode contoh dalam topik ini berlaku untuk wilayah Singapura.

Kemampuan inti

Hasilkan video dari frame pertama dan terakhir

Model yang didukung: Semua model.

Menghasilkan video yang mulus dari gambar frame pertama dan frame terakhir.

Parameter:

  • first_frame_url: Wajib. Berikan gambar frame pertama.

  • last_frame_url: Wajib. Berikan gambar frame terakhir.

  • prompt: Opsional (disarankan). Mengontrol bagaimana video berubah seiring waktu.

Prompt

Frame pertama

Frame terakhir

Video keluaran

Realistic style. A curious black kitten looks up at the sky. The camera starts at eye level and gradually rises until it captures the kitten’s curious gaze from above.

首帧图像

尾帧图像

Python SDK

Memerlukan SDK Python DashScope ≥ 1.25.8. Tingkatkan jika diperlukan.
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope

# URL berikut untuk wilayah Singapura. Saat memanggil, ganti {WorkspaceId} dengan ID ruang kerja aktual Anda. URL berbeda-beda per wilayah. Dapatkan URL Anda: https://www.alibabacloud.com/help/en/model-studio/image-to-video-by-first-and-last-frame-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# Kunci API berbeda per wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY", "YOUR_API_KEY")

def sample_async_call_kf2v():
    # Panggilan asinkron mengembalikan task_id
    rsp = VideoSynthesis.async_call(api_key=api_key,
                                    model="wan2.2-kf2v-flash",
                                    prompt="Realistic style. A curious black kitten looks up at the sky. The camera starts at eye level and gradually rises until it captures the kitten’s curious gaze from above.",
                                    first_frame_url="https://wanx.alicdn.com/material/20250318/first_frame.png",
                                    last_frame_url="https://wanx.alicdn.com/material/20250318/last_frame.png",
                                    duration=5,  # Tetap 5 detik. Jangan ubah.
                                    prompt_extend=True,
                                    watermark=True)
    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))

    # 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_kf2v()

Java SDK

Memerlukan SDK Java DashScope ≥ 2.22.6. Tingkatkan jika diperlukan.

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;

public class Image2Video {

    static {
        // URL berikut untuk wilayah Singapura. Saat memanggil, ganti {WorkspaceId} dengan ID ruang kerja aktual Anda. URL berbeda-beda per wilayah. Dapatkan URL Anda: https://www.alibabacloud.com/help/en/model-studio/image-to-video-by-first-and-last-frame-api-reference
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // Jika Anda belum menetapkan variabel lingkungan, ganti baris di bawah ini dengan: apiKey="sk-xxx"
    // Kunci API berbeda per wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void image2video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.2-kf2v-flash")
                        .prompt("Realistic style. A curious black kitten looks up at the sky. The camera starts at eye level and gradually rises until it captures the kitten’s curious gaze from above.")
                        .firstFrameUrl("https://wanx.alicdn.com/material/20250318/first_frame.png")
                        .lastFrameUrl("https://wanx.alicdn.com/material/20250318/last_frame.png")
                        .resolution("720P")
                        .promptExtend(true)
                        .watermark(true)
                        .build();
        // Panggilan asinkron
        VideoSynthesisResult task = vs.asyncCall(param);
        System.out.println(JsonUtils.toJson(task));
        System.out.println("please wait...");

        // Dapatkan hasil
        VideoSynthesisResult result = vs.wait(task, apiKey);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            image2video();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}

curl

Langkah 1: Buat tugas untuk mendapatkan ID tugas

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.2-kf2v-flash",
    "input": {
        "first_frame_url": "https://wanx.alicdn.com/material/20250318/first_frame.png",
        "last_frame_url": "https://wanx.alicdn.com/material/20250318/last_frame.png",
        "prompt": "Realistic style. A curious black kitten looks up at the sky. The camera starts at eye level and gradually rises until it captures the kitten’s curious gaze from above."
    },
    "parameters": {
        "resolution": "720P",
        "prompt_extend": true,
        "watermark": true
    }
}'

Langkah 2: Dapatkan hasil menggunakan ID tugas

Ganti {task_id} dengan nilai task_id yang dikembalikan oleh pemanggilan API sebelumnya. task_id berlaku untuk kueri selama 24 jam.

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Gambar input

  • Jumlah gambar: Satu gambar frame pertama dan satu gambar frame terakhir.

  • Metode input: URL gambar, jalur file lokal.

Metode 1: URL gambar (HTTP API dan SDK) Direkomendasikan

  • URL publik: HTTP atau HTTPS (misalnya, https://xxxx/xxx.png).

Metode 2: Jalur file lokal (SDK saja)

Persyaratan jalur berbeda-beda per bahasa:

Python SDK: Mendukung jalur absolut dan relatif.

Sistem operasi

Input File Path

Contoh (jalur absolut)

Contoh (jalur relatif)

Linux / macOS

file://{jalur absolut atau relatif}

file:///home/images/test.png

file://./images/test.png

Windows

file://D:/images/test.png

file://./images/test.png

Java SDK: Hanya mendukung jalur absolut.

Sistem operasi

Input file path

Contoh (jalur absolut)

Linux / macOS

file://{jalur absolut}

file:///home/images/test.png

Windows

file:///{jalur absolut}

file:///D:/images/test.png

Kode contoh: Beberapa metode input gambar

Python SDK

import os
from http import HTTPStatus
# DashScope SDK >= 1.23.4
from dashscope import VideoSynthesis
import dashscope

dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# Dapatkan Kunci API DashScope (yang merupakan Kunci API Studio Model Anda) dari variabel lingkungan.
api_key = os.getenv("DASHSCOPE_API_KEY")

# ========== Metode input gambar (pilih salah satu) ==========
# [Metode 1] Gunakan URL gambar publik
first_frame_url = "https://wanx.alicdn.com/material/20250318/first_frame.png"
last_frame_url = "https://wanx.alicdn.com/material/20250318/last_frame.png"

# [Metode 2] Gunakan jalur file lokal (file:// + jalur file)
# Gunakan jalur absolut:
# first_frame_url = "file://" + "/path/to/your/first_frame.png"  # Linux/macOS
# last_frame_url = "file://" + "C:/path/to/your/last_frame.png"  # Windows
# Atau gunakan jalur relatif:
# first_frame_url = "file://" + "./first_frame.png"              # Gunakan jalur aktual Anda.
# last_frame_url = "file://" + "./last_frame.png"                # Gunakan jalur aktual Anda.

def sample_sync_call_kf2v():
    print('please wait...')
    rsp = VideoSynthesis.call(api_key=api_key,
                              model="wan2.2-kf2v-flash",
                              prompt="Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
                              first_frame_url=first_frame_url,
                              last_frame_url=last_frame_url,
                              resolution="720P",
                              prompt_extend=True)
    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_sync_call_kf2v()

Java SDK

// Copyright (c) Alibaba, Inc. and its affiliates.

// DashScope SDK >= 2.20.1
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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.HashMap;
import java.util.Map;


public class Kf2vSyncIntl {

    static {
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // Dapatkan Kunci API DashScope (yang merupakan Kunci API Studio Model Anda) dari variabel lingkungan.
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    /**
     * Metode input gambar (pilih salah satu):
     *
     * [Metode 1] URL publik
     */
    static String firstFrameUrl = "https://wanx.alicdn.com/material/20250318/first_frame.png";
    static String lastFrameUrl = "https://wanx.alicdn.com/material/20250318/last_frame.png";

     /**
     * [Metode 2] Jalur file lokal (file://+jalur absolut atau file:///+jalur absolut)
     */
    // static String firstFrameUrl = "file://" + "/your/path/to/first_frame.png";  // Linux/macOS
    // static String lastFrameUrl = "file:///" + "C:/path/to/your/img.png";        // Windows

    public static void syncCall() {

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("prompt_extend", true);
        parameters.put("resolution", "720P");

        VideoSynthesis videoSynthesis = new VideoSynthesis();
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.2-kf2v-flash")
                        .prompt("Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.")
                        .firstFrameUrl(firstFrameUrl)
                        .lastFrameUrl(lastFrameUrl)
                        .parameters(parameters)
                        .build();
        VideoSynthesisResult result = null;
        try {
            // Melakukan panggilan sinkron. Ini mungkin memerlukan waktu.
            result = videoSynthesis.call(param);
        } catch (ApiException | NoApiKeyException e){
            throw new RuntimeException(e.getMessage());
        } catch (InputRequiredException e) {
            throw new RuntimeException(e);
        }
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        syncCall();
    }
}

Video output

  • Jumlah video: Satu.

  • Spesifikasi: Spesifikasi berbeda-beda per model. Lihat Spesifikasi video.

  • Kedaluwarsa URL: 24 jam.

  • Dimensi: Ditentukan oleh gambar frame pertama dan pengaturan resolution.

    • Model mempertahankan rasio aspek frame pertama dan menskalakan jumlah piksel total ke target. Dimensi output disesuaikan secara otomatis agar dapat dibagi 16 (persyaratan encoding).

    • Contoh: Input 750×1000 (3:4) dengan resolution="720P" (target ≈920K piksel) mungkin menghasilkan output 816×1104 (rasio ≈0,739, ≈900K piksel, keduanya dapat dibagi 16).

Penagihan dan Pembatasan laju

Referensi API

Image-to-video - frame pertama dan terakhir - Referensi API

FAQ

T: Bagaimana cara menghasilkan video dengan rasio aspek tertentu (seperti 3:4)?

J: API tidak mendukung kontrol rasio aspek langsung — hanya resolution.

Parameter resolution mengontrol jumlah piksel, bukan rasio aspek. Model mempertahankan rasio aspek frame pertama (first_frame_url) dengan penyesuaian minor untuk encoding (dimensi harus kelipatan 16). Untuk video 3:4, unggah gambar frame pertama dengan rasio 3:4.

Contoh: Input 750×1000 (3:4) dengan resolution="720P" (target ≈920K piksel) mungkin menghasilkan output 816×1104 (rasio ≈0,739, ≈900K piksel, keduanya dapat dibagi 16).

T: Mengapa saya mendapatkan error “url error, please check url!” saat menjalankan kode SDK?

J: Pastikan versi SDK Anda memenuhi persyaratan minimum: SDK Python DashScope ≥ 1.25.8 atau SDK Java DashScope ≥ 2.22.6. Versi lama mungkin menampilkan error "url error, please check url!". Tingkatkan SDK.