Quick start

Updated at:

The AIWorkflow module of the AI Education server runs AI analysis on video media assets in ApsaraVideo VOD. Configure App Server, start it locally, and make your first API call to get a complete video AI analysis flow running end to end.

Key concepts

The following concepts are used throughout this topic and the rest of the AI Education server documentation:

For the complete parameters and response structures of each API operation, see API reference.

  • Workflow — An AI analysis workflow provided by ApsaraVideo VOD. A workflow analyzes video media assets automatically and generates content such as summaries, chapters, and key points. Create a workflow in the ApsaraVideo VOD console. After creation, the workflow has a unique WorkflowId.

  • Media asset (Media) — A video resource that is uploaded to ApsaraVideo VOD. Each media asset has a unique MediaId.

  • Workflow task (WorkflowTask) — The task instance that is generated after you submit a workflow. Query its execution status by TaskId.

  • AI analysis result (AiAnalysisResult) — The structured analysis result that is generated after the workflow finishes. The Summary and Chapter result types are supported.

Prerequisites

The AIWorkflow module is part of the VodAppServer project and shares the same environment and configuration as App Server. Make sure that the following requirements are met before you make your first call.

Environment requirements

Component

Version requirement

Description

JDK

1.8 or later

Required runtime environment.

Maven

3.x or later

Build tool.

Spring Boot

2.6.6

Framework version used by the project. Keep this version to avoid dependency conflicts.

Important

Before using the AIWorkflow module, you need to submit a work order to apply for the opening AIWorkflow to obtain the workflow ID.

Account and resource requirements

  • Region — Activate ApsaraVideo VOD in the region that you use, and specify that region ID everywhere the service is configured or called: the region key in the configuration file, the ALIYUN_VOD_REGION environment variable, and the optional regionId request parameter. The samples in this topic use cn-shanghai.

  • Access credentials — An AccessKey pair for a RAM user that has only the permissions required by ApsaraVideo VOD.

  • AI analysis workflow — A workflow that is created in the ApsaraVideo VOD console. You submit tasks with its WorkflowId.

  • Media asset — A video that is uploaded to ApsaraVideo VOD. You submit tasks with its MediaId.

Configure the service

Edit src/main/resources/application.yml in the VodAppServer project and specify the service port and your Alibaba Cloud access credentials:

server:
  port: 9000

aliyun:
  vod:
    ak: YOUR_ACCESS_KEY_ID      # Alibaba Cloud AccessKey ID
    sk: YOUR_ACCESS_KEY_SECRET  # Alibaba Cloud AccessKey secret
    region: cn-shanghai         # Region ID. Must match the region in which the service is activated in the ApsaraVideo VOD console
Warning

Do not commit an AccessKey pair to a code repository in plaintext. In production, inject the credentials through environment variables or a credential management service, and use a RAM user that has only the permissions required by ApsaraVideo VOD.

For more information about region selection and environment variable configuration, see the configuration file section of the App Server integration guide.

Start the service

Run the following command in the root directory of the VodAppServer project:

mvn spring-boot:run

After the service starts, the AIWorkflow API operations are available at http://localhost:9000 by default.

Running App Server locally is the default path for this quick start. For a serverless production setup, see Deploy App Server to Function Compute.

Quick walkthrough

Complete one full call in the following three steps: submit an analysis task, query the task status, and get the analysis result. The samples use the default local endpoint http://localhost:9000. If App Server runs elsewhere, replace the endpoint with your own service endpoint.

Step 1: Submit a workflow task

Submit an AI analysis task for a specific media asset:

curl -X POST http://localhost:9000/SubmitWorkflowJob \
  -d 'MediaId=YOUR_MEDIA_ID&WorkflowId=YOUR_WORKFLOW_ID&regionId=cn-shanghai'

Parameters:

  • MediaId — The ID of the ApsaraVideo VOD media asset.

  • WorkflowId — The ID of the AI analysis workflow.

  • regionId — The region ID. This parameter is optional. If you leave it blank, the region in the configuration file is used.

Sample response:

{
  "RequestId": "xxx",
  "JobId": "job_xxx"
}

Submitting the task generates a workflow task, which you query by TaskId in the next step.

Step 2: Query the workflow task

Query the execution status of the workflow task by task ID. Get the analysis result only after the status changes to Success:

curl -X POST http://localhost:9000/GetWorkflowTask \
  -d 'TaskId=YOUR_TASK_ID'

Replace YOUR_TASK_ID with the TaskId of the workflow task that step 1 generated. [TODO: confirm - how to obtain TaskId from the SubmitWorkflowJob response]

Step 3: Get the AI analysis result

Get the structured analysis result by result type. The following sample gets the video summary:

curl -X POST http://localhost:9000/GetMediaAiAnalysisByResultType \
  -d 'MediaId=YOUR_MEDIA_ID&ResultType=Summary'

If the response contains content, AIWorkflow works as expected.

Typical scenarios

The following table maps each scenario to the operation and the ResultType value that it uses:

Scenario

Operation

ResultType

Returned data

Get a video summary

GetMediaAiAnalysisByResultType

Summary

The structured summary of the media asset.

Get video chapters

GetMediaAiAnalysisByResultType

Chapter

The structured chapter list of the media asset.

Get all analysis results at once

GetMediaAiAnalysisByResultType

Left blank

All structured AI analysis results of the media asset.

Get raw analysis data

GetMediaAiAnalysis

Not applicable

The raw JSON data returned by ApsaraVideo VOD.

Scenario 1: Get a video summary

Use a video summary for course overviews and pre-class preview prompts. Call GetMediaAiAnalysisByResultType with ResultType=Summary, as shown in Step 3: Get the AI analysis result. A summary contains a paragraph summary, a conversational summary, a mind map summary, and Markdown content. Choose the form that fits your frontend display.

Sample response:

{
  "AiAnalysisResult": [
    {
      "Title": "Video summary",
      "ResultType": "Summary",
      "Extra": "",
      "SummaryContent": {
        "ParagraphSummary": "This video mainly introduces...",
        "ConversationalSummary": [
          {
            "SpeakerId": "1",
            "SpeakerName": "Host",
            "Summary": "The opening introduces the topic of this session..."
          }
        ],
        "MindMapSummary": [
          {
            "Title": "Core topic",
            "Topic": ["Subtopic 1", "Subtopic 2"]
          }
        ],
        "MarkdownContent": "# Video summary\n\nThis video mainly introduces..."
      }
    }
  ]
}

Scenario 2: Get video chapters

Use video chapters for course outlines and playback that jumps to a specific key point. A chapter result contains the start and end time, a thumbnail, and a list of key points. Your frontend can render the outline and locate the playback position directly from this result.

curl -X POST http://localhost:9000/GetMediaAiAnalysisByResultType \
  -d 'MediaId=YOUR_MEDIA_ID&ResultType=Chapter'

Sample response:

{
  "AiAnalysisResult": [
    {
      "Title": "Video chapters",
      "ResultType": "Chapter",
      "Extra": "",
      "ChapterContentItems": [
        {
          "ChapterId": 1,
          "ChapterTitle": "Chapter 1: Introduction",
          "StartTime": 0,
          "EndTime": 120000,
          "ThumbnailUrl": "https://xxx.jpg",
          "Summary": "This chapter covers the background knowledge...",
          "KnowledgePoints": [
            {
              "PointId": 1,
              "Point": "Core concept",
              "Description": "Detailed description"
            }
          ]
        }
      ]
    }
  ]
}
Note

The StartTime and EndTime values of a chapter are in milliseconds. Convert the unit when you map them to the player progress.

Scenario 3: Get all analysis results at once

If you leave ResultType blank, all AI analysis results of the media asset are returned. Use this scenario to load the summary and chapters together on a details page:

curl -X POST http://localhost:9000/GetMediaAiAnalysisByResultType \
  -d 'MediaId=YOUR_MEDIA_ID'

Scenario 4: Get raw analysis data

To get the raw JSON data returned by ApsaraVideo VOD without structural encapsulation, call the following operation. Use this scenario to parse the data yourself or to troubleshoot field differences:

curl -X POST http://localhost:9000/GetMediaAiAnalysis \
  -d 'MediaId=YOUR_MEDIA_ID'

Deploy App Server to Function Compute

(Optional) Deploy App Server to Alibaba Cloud Function Compute (FC) when you need a serverless setup instead of the local runtime. This path is not required to complete the quick walkthrough. The AIWorkflow module and the rest of App Server are the same Spring Boot service, so the deployment procedure is identical and AIWorkflow requires no extra changes. FC charges you based on actual usage.

Step 1: Build the project

# Go to the project directory
cd VodAppServer
# Package the project with Maven
mvn clean package
# After the packaging succeeds, target/VodAppServer-1.0-SNAPSHOT.jar is generated

Step 2: Prepare the deployment package

# Create the deployment directory structure
mkdir -p deploy/VodAppServer/target
# Copy the JAR file
cp target/VodAppServer-1.0-SNAPSHOT.jar deploy/VodAppServer/target/
# Go to the deployment directory
cd deploy
# Compress the directory into a ZIP file
zip -r VodAppServer.zip VodAppServer/

The directory structure of the deployment package is as follows:

VodAppServer.zip
└── VodAppServer/
    └── target/
        └── VodAppServer-1.0-SNAPSHOT.jar

Step 3: Create a function

Set the following environment variables for the function:

Environment variable

Setting

ACCESS_KEY_ID

The AccessKey ID of your Alibaba Cloud account.

ACCESS_KEY_SECRET

The AccessKey secret of your Alibaba Cloud account.

ALIYUN_VOD_REGION

The region ID of ApsaraVideo VOD. Use the region in which ApsaraVideo VOD is activated. Example: cn-shanghai.

Create the function:

  1. Go to the Functions page in the FC console and click Create Function.

  2. Select Web Function and click Create Web Function.

  3. Configure the following parameters:

    • Memory — Select 1024 MB.

    • Runtime environment — Select Custom Runtime > Java > Java8.

    • Code upload method — Select Upload ZIP.

    • Code package — Upload the VodAppServer.zip package that you created in Step 2.

    • Startup command — Enter java -jar /code/VodAppServer/target/VodAppServer-1.0-SNAPSHOT.jar.

    • Environment variables — In Advanced Settings > More Settings, add the environment variables listed in the preceding table.

    • Other parameters — Keep the default values, or change them based on your requirements.

  4. Check the configuration and click Create.

Step 4: Create a trigger

  1. On the Function Details page, click the Triggers tab.

  2. Click Create Trigger.

  3. Configure the following parameters:

    • Trigger Type — Select HTTP Trigger.

    • Version or Alias — Select LATEST.

    • Request Methods — Select GET, POST, PUT, and DELETE.

    • Authentication Method — Select No authentication.

    • Other parameters — Keep the default values, or change them based on your requirements.

  4. Check the configuration and click OK.

Step 5: Test the deployment

Call an AIWorkflow operation on the public endpoint that is generated for the HTTP trigger:

# Replace the endpoint with your actual endpoint
curl -X POST https://vod-app-function-xxx.cn-shanghai.fcapp.run/GetMediaAiAnalysisByResultType \
  -d 'MediaId=YOUR_MEDIA_ID&ResultType=Summary'

What's next

  • To learn the complete request parameters, response structures, data models, and error codes of each API operation, see API reference.

  • To combine AI analysis results with the client playback experience, such as chapter navigation and key point cards, see AI Education client development.