All Products
Search
Document Center

Object Storage Service:Video information extraction

Last Updated:Jun 13, 2025

The video information extraction feature enables the retrieval of encapsulation details and audio and video streams from media files. The extracted video information can include video resolution, frame rate, audio and video codecs, duration, creation time, image width and height, and subtitle stream existence.

Scenarios

  • Video surveillance: Use video information extraction in security monitoring systems to identify and track the movement and abnormal activities of people, vehicles, or other objects.

  • Video search: Extract visual features or labels from videos to enable efficient retrieval of video content of interest.

  • Video editing: Automatically identify and extract key frames, audio clips, and subtitles to facilitate video editing and production.

  • Video management: Classify, manage, and use media files based on media metadata, such as the resolution, bitrate, frame rate, and coding.

Usage

Prerequisites

  • Intelligent Media Management (IMM) is activated. For more information, see Activate IMM.

  • The Object Storage Service (OSS) bucket that contains the video to detect is bound to an IMM project. You can bind a bucket to an IMM project in the OSS console or by using the IMM API.

    • For information about how to bind a bucket to an IMM project in the OSS console, see Get started.

    • For information about how to bind a bucket to an IMM project by using the IMM API, see AttachOSSBucket.

  • You are granted the required permissions. For more information, see Permissions.

Use OSS SDKs

The following sample code provides examples of extracting video information by using OSS SDKs for common programming languages. To extract video information by using other programming languages, you can modify the parameters based on the following sample code.

Java

OSS SDK for Java V3.17.4 or later is required.

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyuncs.exceptions.ClientException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

public class Demo {
    public static void main(String[] args) throws ClientException, ClientException {
        // Specify the endpoint of the region in which the bucket is located.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Specify the region in which the bucket is located. Example: cn-hangzhou.
        String region = "cn-hangzhou";
        // Obtain access credentials from environment variables. 
        // Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the name of the bucket.
        String bucketName = "examplebucket";
        // If the video is stored in the root directory of the bucket, enter only the video name. If the video is not stored in the root directory of the bucket, specify the full path of the video. Example: exampledir/example.mp4.
        String key = "example.mp4";

        // Create an OSSClient instance.
        // When the OSSClient instance is no longer in use, call the shutdown method to release resources.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {
            // Create a processing instruction to use video information extraction.
            GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
            getObjectRequest.setProcess("video/info");

            // Use the getObject method.
            OSSObject ossObject = ossClient.getObject(getObjectRequest);

            // Read and display the video information.
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = ossObject.getObjectContent().read(buffer)) != -1) {
                baos.write(buffer, 0, bytesRead);
            }
            String videoInfo = baos.toString("UTF-8");
            System.out.println("Video Info:");
            System.out.println(videoInfo);
        } catch (IOException e) {
            System.out.println("Error: " + e.getMessage());
        } finally {
            // Shut down the OSSClient instance.
            ossClient.shutdown();
        }
    }
}

PHP

OSS SDK for PHP V2.7.0 or later is required.

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;

try {
    // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
    $provider = new EnvironmentVariableCredentialsProvider(); 
    // Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
    $endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
    // Specify the name of the bucket. Example: examplebucket. 
    $bucket = 'examplebucket';
    // If the video is stored in the root directory of the bucket, enter only the video name. If the video is not stored in the root directory of the bucket, specify the full path of the video. Example: exampledir/example.mp4. 
    $key = 'example.mp4'; 

    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,        
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        // Specify the ID of the Alibaba Cloud region in which the bucket is located. 
        "region" => "cn-hangzhou"
    );
    $ossClient = new OssClient($config);
  // Create a processing instruction to use video information extraction. 
  $options[$ossClient::OSS_PROCESS] = "video/info";
  $result = $ossClient->getObject($bucket,$key,$options);
  var_dump($result);
} catch (OssException $e) {
  printf($e->getMessage() . "\n");
  return;
}

Python

OSS SDK for Python V2.18.4 or later is required.

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. 
# Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the ID of the Alibaba Cloud region in which the bucket is located. 
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# If the video is stored in the root directory of the bucket, enter the video name. 
# If the video is not stored in the root directory of the bucket, specify the full path of the video. Example: exampledir/example.mp4. 
key = 'example.mp4'

# Create a processing instruction to use video information extraction. 
process = 'video/info'

try:
    # Pass the processing instruction to the get_object method by using the process parameter. 
    result = bucket.get_object(key, process=process)

    # Read and display the video information. 
    video_info = result.read().decode('utf-8')
    print("Video Info:")
    print(video_info)
except oss2.exceptions.OssError as e:
    print("Error:", e)

Go

OSS SDK for Go V3.0.2 or later is required.

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Obtain temporary access credentials from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Create an OSSClient instance. 
	// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.  
	// Specify the ID of the Alibaba Cloud region in which the bucket is located. Example: cn-hangzhou. 
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Specify the name of the bucket. Example: examplebucket. 
	bucketName := "examplebucket"

	bucket, err := client.Bucket(bucketName)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
        // If the video is stored in the root directory of the bucket, enter only the video name. If the video is not stored in the root directory of the bucket, specify the full path of the video. Example: exampledir/example.mp4. 
        // Create a processing instruction by using the oss.Process method. 
	body, err := bucket.GetObject("example.mp4", oss.Process("video/info"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	defer body.Close()

	data, err := io.ReadAll(body)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Println("data:", string(data))
}

Parameters

Action: video/info

Note

The returned information is in the JSON format. For more information, see DetectMediaMeta.

Use the OSS API

  • Sample request

    GET /example.mkv?x-oss-process=video/info HTTP/1.1
    Host: video-demo.oss-cn-hangzhou.aliyuncs.com
    Date: Fri, 28 Oct 2022 06:40:10 GMT
    Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
  • Sample success response

    HTTP/1.1 200 OK
    Server: AliyunOSS
    Date: Wed, 25 May 2022 12:43:57 GMT
    Content-Type: application/json;charset=utf-8
    Content-Length: 161
    Connection: keep-alive
    x-oss-request-id: 628E2481184E20F26C000009
    x-oss-transfer-acc-type: acc-none
    x-oss-data-location: oss-cn-hangzhou-a
    ETag: "D0F162350DA037F4DC2A142B2E116BD0"
    Last-Modified: Wed,
     25 May 2022 12:20:34 GMT
    x-oss-object-type: Normal
    x-oss-hash-crc64ecma: 2040549661341440100
    x-oss-storage-class: Standard
    x-oss-server-time: 12437
    
    {
      "RequestId":"E63E1EFB-6D65-59DE-A11D-B0B761FDB301",
      "Size":81714666,
      "VideoWidth":2160,
      "FormatLongName":"Matroska / WebM",
      "FormatName":"matroska,webm"
      "Duration":75.669,
      "Bitrate":8639169, 
      "ProduceTime":"2022-01-27T06:08:11Z",
      "StreamCount":4,
      "VideoHeight":3840,
      "VideoStreams":
      [
        {
    	    "CodecTag":"0x0000",
          "FrameRate":"50/1",
          "SampleAspectRatio":"1:1",
          "ColorSpace":"bt709",
          "StartTime":0.044,
          "ColorRange":"tv",
          "CodecName":"h264",
          "BitDepth":8,
          "Profile":"High",
          "DisplayAspectRatio":"9:16",
          "CodecTagString":"[0][0][0][0]",
          "HasBFrames":1,
          "AverageFrameRate":"50/1",
          "ColorPrimaries":"bt709",
          "CodecLongName":"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
          "Height":3840,
          "PixelFormat":"yuv420p",
          "Level":51,
          "Width":2160,
          "TimeBase":"1/1000"
        }
      ],
      "AudioStreams":
      [
        {
          "CodecTag":"0x0000",
          "CodecTagString":"[0][0][0][0]",
          "SampleRate":48000,
          "ChannelLayout":"stereo",
          "CodecLongName":"AAC (Advanced Audio Coding)",
          "Index":1,
          "CodecName":"aac",
          "TimeBase":"1/1000",
          "SampleFormat":"fltp",
          "Channels":2
        },
        {
          "CodecTag":"0x0000",
          "CodecTagString":"[0][0][0][0]",
          "SampleRate":48000,
          "ChannelLayout":"stereo",
          "CodecLongName":"AAC (Advanced Audio Coding)",
          "Index":2,
          "CodecName":"aac",
          "TimeBase":"1/1000",
          "SampleFormat":"fltp",
          "Channels":2
    	}
      ],
      "Subtitles":
      [
        {
          "CodecTag":"0x0000",
          "CodecTagString":"[0][0][0][0]",
          "CodecLongName":"SubRip subtitle",
          "Index":3,
          "Duration":75.669,
          "CodecName":"subrip"
        }
      ],
    }

Notes

  • The video information extraction feature supports only synchronous processing (x-oss-process).

  • Anonymous access is not supported.

  • Video information extraction requires calls to the DetectMediaMeta operation of IMM and incurs associated fees. For more information, see Billable items.

FAQ

How can I resolve a video playback issue caused by the codec used prior to uploading?

You can transcode the video by using the video transcoding feature of OSS or the live transcoding feature of IMM. For more information, see Video transcoding and Live transcoding.

How can I query the width and height of a video stored on OSS?

You can use IMM to query the width and height of a video stored on OSS. If the width or height of the video does not meet your requirements, you can transcode the video. For more information, see Video transcoding.