全部產品
Search
文件中心

Intelligent Media Services:體育賽事集錦成片

更新時間:Jun 26, 2025

本文旨在介紹在智能圖文匹配成片-體育賽事集錦情境下的合成參數、SDK調用樣本。

重要
  • 注意:在此介面中,所有媒資的OSS URL中的地區(region)必須與調用OpenAPI服務地址中的地區(region)保持一致。

  • 支援的地區:華東2(上海)。

  • 在實際使用過程中,請將文檔所有參數樣本中的 [your-bucket]、[your-region-id]、[your-file-name]、[your-file-path]、媒資ID(例如:“****9d46c8b4548681030f6e****”)等參數替換為您的實際值。

說明
  • 為了更好地閱讀本文,建議您在閱讀本文之前先通過智能一鍵成片操作指南瞭解【智能圖文匹配成片-體育賽事集錦】相關的概念與使用流程。

使用說明

InputConfig 參數說明

使用者可通過配置InputConfig,指定視頻素材、口播、背景音樂、貼紙等基礎素材的參數配置。

參數

類型

說明

樣本值

是否必填

SportsCategory

String

體育賽事類型

籃球:basketball

乒乓球:pingpong

basketball

InputMedia

String

輸入的體育賽事素材。支援MediaId 或 MediaURL

  • 僅支援單個素材。

  • 僅可使用視訊,素材支援的格式詳見視頻格式

****9d46c8b4548681030f6e****

FaceRegister

List<FaceInfo>

人物標識,數組長度小於等於5。

詳見參數樣本

SlowMotionLogoRegister

SlowMotionLogoRegister

縮時攝影標識。如果成片中需包含縮時攝影,需提供源片中縮時攝影之前出現的logo標識資訊。數組長度小於等於5。

詳見參數樣本

TransferNameRegister

List<TransferNameInfo>

名稱轉寫標識,將記分牌中的隊名縮寫轉寫為完整隊名。數組長度小於等於10。

詳見參數樣本

FaceInfo 參數說明

欄位

類型

描述

樣本值

必填

FaceUrls

List<String>

  • 人臉圖片連結,最好同時帶有正臉和側臉。請確保人臉圖片中僅包含一名個體,並且人臉應清晰可見,無明顯遮擋或缺失現象。

  • 支援的格式詳見圖片格式

["http://[your-bucket].oss-[your-region-id].aliyuncs.com/test1.png","http://[your-bucket].oss-[your-region-id].aliyuncs.com/test1.png""]

Name

String

人物名稱,必須與輸入視頻中記分牌顯示的人名一致

張三

SlowMotionLogoRegister 參數說明

欄位

類型

描述

樣本值

必填

SlowMotionLogoUrls

List<String>

  • 源片中,縮時攝影畫面出現之前的Logo圖片連結。

  • 支援的格式詳見圖片格式

["http://[your-bucket].oss-[your-region-id].aliyuncs.com/test1.png","http://[your-bucket].oss-[your-region-id].aliyuncs.com/test1.png""]

TransferNameInfo 參數說明

欄位

類型

描述

樣本值

必填

OriginalName

String

賽事記分牌中的隊名縮寫

Rockets

TransferName

String

完整隊名

Houston Rockets

參數樣本

{
  "SportsCategory": "Basketball",
  "InputMedia": "http://[your-bucket].oss-[your-region-id].aliyuncs.com/[your-file-path]/[your-file-name]_{index}.mp4",
  "FaceRegister": [
    {
      "FaceUrls": ["http://testcdn.com/front.jpg", "http://testcdn.com/side.jpg"],
      "Name": "James"
    }
  ],
  "SlowMotionLogoRegister": {
  	"SlowMotionLogoUrls": ["http://testcdn.com/logo1.jpg", "http://testcdn.com/logo2.jpg"]
  },
  "TransferNameRegister": [
    {
      "OriginalName": "IND",
      "TransferName": "印地安納步行者"
    }
  ]
}

EditingConfig 參數說明

說明

暫不支援配置EditingConfig相關參數

OutputConfig 參數說明

使用者可通過配置OutputConfig,指定成片輸出地址、名稱規則、成片的寬高、輸出成片數量等合成參數配置。

參數

類型

說明

樣本值

必填

MediaURL

String

輸出視頻地址,必須要有預留位置{index}。

規則:http://[your-bucket].oss-[your-region-id].aliyuncs.com/[your-file-path]/[your-file-name]_{index}.mp4

樣本:http://example.oss-cn-shanghai.aliyuncs.com/example/example_{index}.mp4

當GeneratePreviewOnly=false時,且成片輸出到OSS時必填

StorageLocation

String

指定輸出到VOD的媒資檔案儲存體地址。

規則:[your-vod-bucket].oss-[your-region-id].aliyuncs.com

樣本:outin-****6c886b4549d481030f6e****.oss-cn-shanghai.aliyuncs.com

當GeneratePreviewOnly=false時,且成片輸出到VOD時必填

FileName

String

輸出檔案名稱,必須要有預留位置{index}。

規則:[your-file-name]__{index}.mp4

樣本:example_{index}.mp4

當GeneratePreviewOnly=false時,且成片輸出到VOD時必填

GeneratePreviewOnly

Boolean

  • GeneratePreviewOnly = true時,表示當前任務僅產生預覽用的時間軸,不實際合成,可不填寫輸出視頻的地址和寬高。

  • 一鍵成片任務完成後,通過GetBatchMediaPoducingJob查詢任務結果,返回的子任務列表中會包含剪輯工程projectId,再調用GetEditingProject可擷取到預覽時間軸。

false

否,預設false

Count

Integer

輸出視頻數,當前支援Count=1,後續可能支援輸出多個視頻。

1

否,預設1

Width

Integer

成片寬,px

1080

Height

Integer

成片高,px

1920

Video

JSONObject

輸出視頻流相關配置,Crf、Codec等

{"Crf": 27}

參數樣本

{
 	"MediaURL": "http://[your-bucket].oss-[your-region-id].aliyuncs.com/xxx_{index}.mp4",
 	"Count": 1,
 	"Width": 1080,
 	"Height": 1920,
 	"Video": {"Crf": 27},
        "GeneratePreviewOnly":false
}

SDK調用樣本

前提條件

您已安裝IMS服務端SDK,詳情請參見準備工作

程式碼範例

展開查看程式碼範例

package com.example.vodservicesdktest.ice.editing;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import com.aliyun.ice20201109.Client;
import com.aliyun.ice20201109.models.GetBatchMediaProducingJobRequest;
import com.aliyun.ice20201109.models.GetBatchMediaProducingJobResponse;
import com.aliyun.ice20201109.models.SubmitSportsHighlightsJobRequest;
import com.aliyun.ice20201109.models.SubmitSportsHighlightsJobResponse;
import com.aliyun.teaopenapi.models.Config;

/**
 *  需要maven引入二方包依賴:
 *   <dependency>
 *      <groupId>com.aliyun</groupId>
 *      <artifactId>ice20201109</artifactId>
 *      <version>3.4.0</version>
 *  </dependency>
 *  <dependency>
 *      <groupId>com.alibaba</groupId>
 *      <artifactId>fastjson</artifactId>
 *      <version>1.2.9</version>
 *  </dependency>
 */
public class SportsHighlightsJobService {

    static final String regionId = "[your-region-id]";
    static final String bucket = "[your-bucket]";
    private Client iceClient;

    public static void main(String[] args) throws Exception {
        SportsHighlightsJobService scriptBatchEditingService = new SportsHighlightsJobService();
        scriptBatchEditingService.initClient();
        scriptBatchEditingService.runExample();
    }

    public void initClient() throws Exception {
        // 阿里雲帳號AccessKey擁有所有API的存取權限,建議您使用RAM使用者進行API訪問或日常營運。
        // 本樣本以將AccessKey ID和 AccessKey Secret儲存在環境變數為例說明。配置方法請參見:https://www.alibabacloud.com/help/zh/sdk/developer-reference/v2-manage-access-credentials
        com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();

        Config config = new Config();
        config.setCredential(credentialClient);

        // 如需寫入程式碼AccessKey ID和AccessKey Secret,代碼如下,但強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。
        // config.accessKeyId = <第二步建立的AccessKey ID>;
        // config.accessKeySecret = <第二步建立的AccessKey Secret>;
        config.endpoint = "ice." + regionId + ".aliyuncs.com";
        config.regionId = regionId;
        iceClient = new Client(config);
    }

    public void runExample() throws Exception {

        JSONObject inputConfig = new JSONObject();
        inputConfig.put("SportsCategory", "basketball");
        inputConfig.put("InputMedia", "http://[your-bucket].oss-[your-region-id].basketball.mp4");

        JSONArray transferNameRegisterArray = new JSONArray();
        JSONObject transferName = new JSONObject();
        transferName.put("OriginalName", "IND");
        transferName.put("TransferName", "印地安納步行者");
        transferNameRegisterArray.add(transferName);
        inputConfig.put("TransferNameRegister", transferNameRegisterArray);

        // 成片寬高,產生豎屏檔案
        //int outputWidth = 1080;
        //int outputHeight = 1920;

        //// 成片寬高,產生橫屏檔案
        int outputWidth = 1920;
        int outputHeight = 1080;

        // 成片oss地址,需包含{index} 預留位置
        String mediaUrl = "http://" + bucket + ".oss-" + regionId + ".aliyuncs.com/sports_highlights/output_{index}.mp4";

        JSONObject outputConfig = new JSONObject();
        outputConfig.put("MediaURL", mediaUrl);
        outputConfig.put("Width", outputWidth);
        outputConfig.put("Height", outputHeight);

        // 提交體育集錦任務
        SubmitSportsHighlightsJobRequest request = new SubmitSportsHighlightsJobRequest();
        request.setInputConfig(inputConfig.toJSONString());
        request.setOutputConfig(outputConfig.toJSONString());

        SubmitSportsHighlightsJobResponse response = iceClient.submitSportsHighlightsJob(request);
        String jobId = response.getBody().getJobId();
        System.out.println("Start sports highlights job, JobId: " + jobId);

        // 輪詢任務狀態直到全部結束
        System.out.println("Waiting job finished...");
        int maxTry = 3000;
        int i = 0;
        while (i < maxTry) {
            Thread.sleep(3000);
            i++;
            GetBatchMediaProducingJobRequest getRequest = new GetBatchMediaProducingJobRequest();
            getRequest.setJobId(jobId);
            GetBatchMediaProducingJobResponse getResponse = iceClient.getBatchMediaProducingJob(getRequest);
            String status = getResponse.getBody().getEditingBatchJob().getStatus();
            System.out.println("JobId: " + jobId + ", status:" + status);

            if ("Failed".equals(status)) {
                System.out.println("Job failed. JobInfo: " + JSONObject.toJSONString(getResponse.getBody().getEditingBatchJob()));
                throw new Exception("Produce failed. BatchJobId: " + jobId);
            }

            if ("Finished".equals(status)) {
                System.out.println("Job finished. JobInfo: " + JSONObject.toJSONString(getResponse.getBody().getEditingBatchJob()));
                break;
            }
        }
    }
}

API調用入參詳情

展開查看InputConfig

{
  "Category": "Basketball",
  "InputMedia": "http://[your-bucket].oss-[your-region-id].basketball-0707.mp4",
  "FaceRegister": [
    {
      "FaceUrls": ["http://testcdn.com/front.jpg", "http://testcdn.com/side.jpg"],
      "Name": "James"
    }
  ],
  "SlowMotionLogoRegister": {
  	"SlowMotionLogoUrls": ["http://testcdn.com/logo1.jpg", "http://testcdn.com/logo2.jpg"]
  },
  "TransferNameRegister": [
    {
      "OriginalName": "IND",
      "TransferName": "印地安納步行者"
    }
  ]
}

展開查看OutputConfig

{
  "Count": 1,
  "Height": 1080,
  "Width": 1920,
  "MediaURL": "http://[your-bucket].oss-[your-region-id].aliyuncs.com/[your-file-path]/[your-file-name]_{index}.mp4"
}

處理邏輯

  • 根據SportsCategory判斷體育賽事類型:籃球-basketball、乒乓球-pingpong。

  • 通過人物標識參數FaceRegister,來設定成片結果中需要出現的運動員鏡頭。

  • 通過縮時攝影標識參數SlowMotionLogoRegister,來設定成片結果中需要包含的縮時攝影回放。

  • 通過名稱轉寫設定參數TransferNameRegister,將記分牌中的隊名縮寫轉寫為完整隊名。

相關文檔