Video super resolution

更新时间:
复制 MD 格式

This topic provides sample code for video super resolution in common programming languages and scenarios.

Note
  • For real-time assistance, start an online consultation.

  • If you have questions about API access or usage for the Alibaba Cloud Vision AI Platform, join our DingTalk group (ID: 23109592) to contact us.

Overview

See video super resolution for a functional overview and a detailed description of its parameters.

Install the SDK

For information about the SDK dependency packages for common languages, see SDK overview.

Configure environment variables

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

Important
  • An Alibaba Cloud account has full access to all API operations. We recommend that you use a RAM user for API calls or routine O&M. For more information, see Create a RAM user.

  • Do not save your AccessKey ID or AccessKey Secret in project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account may be compromised.

  • Configure environment variables on Linux and macOS

    1. Open a terminal in IntelliJ IDEA.

    2. Run the following commands to configure the environment variables.

      Replace <access_key_id> with the AccessKey ID of your RAM user and <access_key_secret> with the AccessKey Secret of your RAM user. If you need to configure more permissions, see Control access permissions using a RAM policy.

      export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
      export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  • Configure environment variables on Windows

    Create a new environment variable file, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared. Then, restart the Windows operating system. The following example uses Windows 10.

    1. Open File Explorer, right-click This PC, and then select Properties.

    2. In the left-side navigation pane, click Advanced system settings.

    3. On the Advanced tab of the System Properties dialog box, click Environment Variables.

    4. In the Environment Variables dialog box, click New.

    5. In the New System Variable dialog box, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared.

    6. Restart the Windows operating system for the configurations to take effect.

Sample code

OSS object URL

For sample code to query an asynchronous task result, see Query an asynchronous task result.

/*
Import the dependency package
<!-- https://mvnrepository.com/artifact/com.aliyun/videoenhan20200320 -->
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>videoenhan20200320</artifactId>
  <version>${aliyun.videoenhan.version}</version>
</dependency>
*/

import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.videoenhan20200320.models.SuperResolveVideoResponse;

public class SuperResolveVideo {
    public static com.aliyun.videoenhan20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        /*
          Initializes a Config object with your AccessKey ID, AccessKey Secret, and endpoint.
         */
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // The endpoint of the service.
        config.endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
        return new com.aliyun.videoenhan20200320.Client(config);
    }

    public static void main(String[] args) throws Exception {
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); 
        com.aliyun.videoenhan20200320.Client client = SuperResolveVideo.createClient(accessKeyId, accessKeySecret);
        com.aliyun.videoenhan20200320.models.SuperResolveVideoRequest superResolveVideoRequest = new com.aliyun.videoenhan20200320.models.SuperResolveVideoRequest()
                .setVideoUrl("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4")
                .setBitRate(5);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            SuperResolveVideoResponse superResolveVideoResponse = client.superResolveVideoWithOptions(superResolveVideoRequest, runtime);
            // Get the full response.
            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(superResolveVideoResponse)));
            // Get a specific field.
            System.out.println(superResolveVideoResponse.getBody());
        } catch (TeaException teaException) {
            // Get the full error message.
            System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
            // Get a specific field.
            System.out.println(teaException.getCode());
        }
    }
}
# -*- coding: utf-8 -*-
# Import the dependency package
# pip install alibabacloud_videoenhan20200320

import os
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions
from alibabacloud_videoenhan20200320.client import Client
from alibabacloud_videoenhan20200320.models import SuperResolveVideoRequest

config = Config(
  # To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  # If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  # Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.
  access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
  access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
  # The endpoint of the service.
  endpoint='videoenhan.cn-shanghai.aliyuncs.com',
  # The region that corresponds to the endpoint.
  region_id='cn-shanghai'
)
super_resolve_video_request = SuperResolveVideoRequest(
    video_url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4',
    bit_rate=5
)
runtime = RuntimeOptions()
try:
  # Initialize the client.
  client = Client(config)
  response = client.super_resolve_video_with_options(super_resolve_video_request, runtime)
  # Get the full response.
  print(response.body)
except Exception as error:
  # Get the full error message.
  print(error)
  # Get a specific field.
  print(error.code)
<?php

//Install the dependency package
//composer require alibabacloud/videoenhan-20200320

use AlibabaCloud\SDK\Videoenhan\V20200320\Videoenhan;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Videoenhan\V20200320\Models\SuperResolveVideoRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class SuperResolveVideo {

    /**
     * Use an AccessKey pair to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Videoenhan Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        // Initializes a Config object with your AccessKey ID, AccessKey Secret, and endpoint.
        $config = new Config([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint of the service.
        $config->endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
        return new Videoenhan($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.    
        $accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');      
        $accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
        $client = self::createClient($accessKeyId, $accessKeySecret);
        $superResolveVideoRequest = new SuperResolveVideoRequest([
            "videoUrl" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4",
            "bitRate" => 5
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            $resp = $client->superResolveVideoWithOptions($superResolveVideoRequest, $runtime);
            # Get the full response.
            echo Utils::toJSONString($resp->body);
        } catch (Exception $exception) {
            # Get the full error message.
            echo Utils::toJSONString($exception);
            # Get a specific field.
            echo $exception->getCode();
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
//$argv is a reserved array for input parameters and does not need to be modified.
SuperResolveVideo::main(array_slice($argv, 1));
// Install the dependency package
// npm install @alicloud/videoenhan20200320
const VideoenhanClient = require('@alicloud/videoenhan20200320');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');

let config = new OpenapiClient.Config({
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code. 
  accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,   
  accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint of the service.
config.endpoint = `videoenhan.cn-shanghai.aliyuncs.com`;
const client = new VideoenhanClient.default(config);
let superResolveVideoRequest = new VideoenhanClient.SuperResolveVideoRequest({
  bitRate: 5,
  videoUrl: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4",
});
let runtime = new TeaUtil.RuntimeOptions({});
client.superResolveVideoWithOptions(superResolveVideoRequest, runtime)
  .then(function (superResolveVideoResponse) {
    // Get the full response.
    console.log(superResolveVideoResponse);
    // Get a specific field.
    console.log(superResolveVideoResponse.body.data);
  }, function (error) {
    // Get the full error message.
    console.log(error);
    // Get a specific field.
    console.log(error.data.Code);
  })
/**
This depends on github.com/alibabacloud-go/videoenhan-20200320/v3.
We recommend that you use go mod tidy to install the dependencies.
*/

package main

import (
	"fmt"
	"os"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
	videoenhan20200320 "github.com/alibabacloud-go/videoenhan-20200320/v3/client"
)

func main() {  
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.  
  accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")  
  accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
  // Initializes a Config object with your AccessKey ID, AccessKey Secret, and endpoint.
  config := &openapi.Config{
    AccessKeyId: tea.String(accessKeyId),
    AccessKeySecret: tea.String(accessKeySecret)
	}
	// The endpoint of the service.
	config.Endpoint = tea.String("videoenhan.cn-shanghai.aliyuncs.com")
	client, err := videoenhan20200320.NewClient(config)
	if err != nil {
		panic(err)
	}
	superResolveVideoRequest := &videoenhan20200320.SuperResolveVideoRequest{
		BitRate:  tea.Int32(5),
		VideoUrl: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4"),
	}
	runtime := &util.RuntimeOptions{}
	superResolveVideoResponse, err := client.SuperResolveVideoWithOptions(superResolveVideoRequest, runtime)
	if err != nil {
		// Get the full error message.
		fmt.Println(err.Error())
	} else {
		// Get the full response.
		fmt.Println(superResolveVideoResponse)
	}
}
// Install the dependency package
// dotnet add package AlibabaCloud.SDK.Videoenhan20200320
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using AlibabaCloud.SDK.Videoenhan20200320.Models;
using Tea;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample
    {
        /**
            * Use an AccessKey pair to initialize the client.
            * @param accessKeyId
            * @param accessKeySecret
            * @return Client
            * @throws Exception
        */
        public static AlibabaCloud.SDK.Videoenhan20200320.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                AccessKeyId = accessKeyId,
                AccessKeySecret = accessKeySecret,
            };
            // The endpoint of the service.
            config.Endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
            return new AlibabaCloud.SDK.Videoenhan20200320.Client(config);
        }
        public static void Main(string[] args)
        {
            // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
            // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
            // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.
            AlibabaCloud.SDK.Videoenhan20200320.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
            SuperResolveVideoRequest superResolveVideoRequest = new SuperResolveVideoRequest
            {
                BitRate = 5,
                VideoUrl = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4",
            };
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            try
            {
                SuperResolveVideoResponse superResolveVideoResponse = client.SuperResolveVideoWithOptions(superResolveVideoRequest, runtime);
                // Get the full response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(superResolveVideoResponse.Body));
                // Get a specific field.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(superResolveVideoResponse.Body.Data));
            }
            catch (TeaException error)
            {
                // Print the error if needed.
                AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary
                {
                    { "message", _error.Message }
                });
                // Print the error if needed.
                Console.WriteLine(error.Message);
            }
        }
    }
}

Local file or public URL

For sample code to query an asynchronous task result, see Query an asynchronous task result.

/*
Import the dependency package
<!-- https://mvnrepository.com/artifact/com.aliyun/videoenhan20200320 -->
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>videoenhan20200320</artifactId>
  <version>${aliyun.videoenhan.version}</version>
</dependency>
*/

import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.videoenhan20200320.models.SuperResolveVideoResponse;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;

public class SuperResolveVideo {
    public static com.aliyun.videoenhan20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        /*
          Initializes a Config object with your AccessKey ID, AccessKey Secret, and endpoint.
         */
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // The endpoint of the service.
        config.endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
        return new com.aliyun.videoenhan20200320.Client(config);
    }

    public static void main(String[] args) throws Exception {
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); 
        com.aliyun.videoenhan20200320.Client client = SuperResolveVideo.createClient(accessKeyId, accessKeySecret);
        // Scenario 1: Use a local file.
        // InputStream inputStream = new FileInputStream(new File("/tmp/SuperResolveVideo1.mp4"));
        // Scenario 2: Use a publicly accessible URL.
        URL url = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4");
        InputStream inputStream = url.openConnection().getInputStream();
        com.aliyun.videoenhan20200320.models.SuperResolveVideoAdvanceRequest superResolveVideoAdvanceRequest = new com.aliyun.videoenhan20200320.models.SuperResolveVideoAdvanceRequest()
                .setVideoUrlObject(inputStream)
                .setBitRate(5);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            SuperResolveVideoResponse superResolveVideoAdvanceResponse = client.superResolveVideoAdvance(superResolveVideoAdvanceRequest, runtime);
            // Get the full response.
            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(superResolveVideoAdvanceResponse)));
            // Get a specific field.
            System.out.println(superResolveVideoAdvanceResponse.getBody());
        } catch (TeaException teaException) {
            // Get the full error message.
            System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
            // Get a specific field.
            System.out.println(teaException.getCode());
        }
    }
}
# -*- coding: utf-8 -*-
# Import the dependency package
# pip install alibabacloud_videoenhan20200320

import os
import io
from urllib.request import urlopen
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions
from alibabacloud_videoenhan20200320.client import Client
from alibabacloud_videoenhan20200320.models import SuperResolveVideoAdvanceRequest

config = Config(
  # To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  # If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  # Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.
  access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
  access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
  # The endpoint of the service.
  endpoint='videoenhan.cn-shanghai.aliyuncs.com',
  # The region that corresponds to the endpoint.
  region_id='cn-shanghai'
)
# Scenario 1: Use a local file.
# img = open(r'/tmp/SuperResolveVideo1.mp4', 'rb')
# Scenario 2: Use a publicly accessible URL.
url = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4'
img = io.BytesIO(urlopen(url).read())
super_resolve_video_request = SuperResolveVideoAdvanceRequest()
super_resolve_video_request.video_url_object = img
super_resolve_video_request.bit_rate = 5
runtime = RuntimeOptions()
try:
  # Initialize the client.
  client = Client(config)
  response = client.super_resolve_video_advance(super_resolve_video_request, runtime)
  # Get the full response.
  print(response.body)
except Exception as error:
  # Get the full error message.
  print(error)
  # Get a specific field.
  print(error.code)
<?php

//Install the dependency package
//composer require alibabacloud/videoenhan-20200320

use AlibabaCloud\SDK\Videoenhan\V20200320\Videoenhan;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Videoenhan\V20200320\Models\SuperResolveVideoAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;

class SuperResolveVideoAdvance {

    /**
     * Use an AccessKey pair to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Videoenhan Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        // Initializes a Config object with your AccessKey ID, AccessKey Secret, and endpoint.
        $config = new Config([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint of the service.
        $config->endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
        return new Videoenhan($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.
        $accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
        $accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'); 
        $client = self::createClient($accessKeyId, $accessKeySecret);
        // Scenario 1: Use a local file.
        //$file = fopen('/tmp/SuperResolveVideo1.mp4', 'rb');
        //$stream = new Stream($file);
        // Scenario 2: Use a publicly accessible URL.
        $file = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4', 'rb');
        $stream = new Stream($file);
        $superResolveVideoAdvanceRequest = new SuperResolveVideoAdvanceRequest([
            "videoUrlObject" => $stream,
            "bitRate" => 5
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            $resp = $client->superResolveVideoAdvance($superResolveVideoAdvanceRequest, $runtime);
            # Get the full response.
            echo Utils::toJSONString($resp->body);
        } catch (Exception $exception) {
            # Get the full error message.
            echo Utils::toJSONString($exception);
            # Get a specific field.
            echo $exception->getCode();
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
//$argv is a reserved array for input parameters and does not need to be modified.
SuperResolveVideoAdvance::main(array_slice($argv, 1));
// Install the dependency package
// npm install @alicloud/videoenhan20200320
const VideoenhanClient = require('@alicloud/videoenhan20200320');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');
const fs = require('fs');
const http = require('http');
const https = require('https');
const { URL } = require('url');

let config = new OpenapiClient.Config({
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code. 
  accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,   
  accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint of the service.
config.endpoint = `videoenhan.cn-shanghai.aliyuncs.com`;
const client = new VideoenhanClient.default(config);
const getResponse = function (httpClient, url) {
  return new Promise((resolve, reject) => {
    httpClient.get(url, function (response) {
      resolve(response);
    })
  })
}
const request = async function () {
  try {
    let superResolveVideoAdvanceRequest = new VideoenhanClient.SuperResolveVideoAdvanceRequest();
    // Scenario 1: Use a local file.
    // const fileStream = fs.createReadStream('/tmp/SuperResolveVideo1.mp4');
    // superResolveVideoAdvanceRequest.videoUrlObject = fileStream;
    // superResolveVideoAdvanceRequest.bitRate = 5;
    
    // Scenario 2: Use a publicly accessible URL.
    const url = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4");
    const httpClient = (url.protocol == "https:") ? https : http;
    superResolveVideoAdvanceRequest.videoUrlObject = await getResponse(httpClient, url);
    superResolveVideoAdvanceRequest.bitRate = 5;
    let runtime = new TeaUtil.RuntimeOptions({ });
    client.superResolveVideoAdvance(superResolveVideoAdvanceRequest, runtime)
      .then(function(superResolveVideoResponse) {
        // Get the full response.
        console.log(superResolveVideoResponse);
        // Get a specific field.
        console.log(superResolveVideoResponse.body.data);
      }, function(error) {
        // Get the full error message.
        console.log(error);
        // Get a specific field.
        console.log(error.data.Code);
      })
  } catch (error) {
    console.log(error);
  }
}();
/**
This depends on github.com/alibabacloud-go/videoenhan-20200320/v3.
We recommend that you use go mod tidy to install the dependencies.
*/

package main

import (
	"fmt"
	"os"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
	videoenhan20200320 "github.com/alibabacloud-go/videoenhan-20200320/v3/client"
	"net/http"
)

func main() {
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.  
  accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")  
  accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
  // Initializes a Config object with your AccessKey ID, AccessKey Secret, and endpoint.
  config := &openapi.Config{
    AccessKeyId: tea.String(accessKeyId),
    AccessKeySecret: tea.String(accessKeySecret)
	}
	// The endpoint of the service.
	config.Endpoint = tea.String("videoenhan.cn-shanghai.aliyuncs.com")
	client, err := videoenhan20200320.NewClient(config)
	if err != nil {
		panic(err)
	}
	// Scenario 1: Use a local file.
	//file, err := os.Open("/tmp/SuperResolveVideo1.mp4")
	//if err != nil {
	//	fmt.Println("can not open file", err)
	//	panic(err)
	//}
	//superResolveVideoAdvanceRequest := &videoenhan20200320.SuperResolveVideoAdvanceRequest{
	//	BitRate:        tea.Int32(5),
	//	VideoUrlObject: file,
	//}
	// Scenario 2: Use a publicly accessible URL.
	httpClient := http.Client{}
	file, _ := httpClient.Get("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4")
	superResolveVideoAdvanceRequest := &videoenhan20200320.SuperResolveVideoAdvanceRequest{
		BitRate:        tea.Int32(5),
		VideoUrlObject: file.Body,
	}
	runtime := &util.RuntimeOptions{}
	superResolveVideoAdvanceResponse, err := client.SuperResolveVideoAdvance(superResolveVideoAdvanceRequest, runtime)
	if err != nil {
		// Get the full error message.
		fmt.Println(err.Error())
	} else {
		// Get the full response.
		fmt.Println(superResolveVideoAdvanceResponse)
	}
}
// Install the dependency package
// dotnet add package AlibabaCloud.SDK.Videoenhan20200320
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using AlibabaCloud.SDK.Videoenhan20200320.Models;
using Tea;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample
    {
        /**
            * Use an AccessKey pair to initialize the client.
            * @param accessKeyId
            * @param accessKeySecret
            * @return Client
            * @throws Exception
        */
        public static AlibabaCloud.SDK.Videoenhan20200320.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                AccessKeyId = accessKeyId,
                AccessKeySecret = accessKeySecret,
            };
            // The endpoint of the service.
            config.Endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
            return new AlibabaCloud.SDK.Videoenhan20200320.Client(config);
        }
        public static void Main(string[] args)
        {
            // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
            // If you are using a RAM user's AccessKey, you need to grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
            // Read the AccessKey ID and AccessKey Secret from environment variables. You must configure environment variables before you run the sample code.
           AlibabaCloud.SDK.Videoenhan20200320.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
           SuperResolveVideoAdvanceRequest superResolveVideoAdvanceRequest = new SuperResolveVideoAdvanceRequest
            ();
            // Scenario 1: Use a local file.
            // FileStream file = new FileStream(@"/tmp/SuperResolveVideo1.mp4", FileMode.Open);
            // superResolveVideoAdvanceRequest.VideoUrlObject = file;
            // superResolveVideoAdvanceRequest.BitRate = 5;

            // Scenario 2: Use a publicly accessible URL.
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/SuperResolveVideo/SuperResolveVideo1.mp4");
            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            superResolveVideoAdvanceRequest.VideoUrlObject = stream;
            superResolveVideoAdvanceRequest.BitRate = 5;
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            try
            {
                SuperResolveVideoResponse superResolveVideoResponse = client.SuperResolveVideoAdvance(superResolveVideoAdvanceRequest, runtime);
                // Get the full response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(superResolveVideoResponse.Body));
                // Get a specific field.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(superResolveVideoResponse.Body.Data));
            }
            catch (TeaException error)
            {
                // Print the error if needed.
                AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary
                {
                    { "message", _error.Message }
                });
                // Print the error if needed.
                Console.WriteLine(error.Message);
            }
        }
    }
}

FAQ

Can I cancel a video super resolution task after it is submitted? Will I be charged?

Video super resolution tasks are processed asynchronously. A cancellation API is available, but cancellation is only effective for tasks in the queued state. If a task is already in the processing state, the cancellation request has no effect. You are only charged for successful API calls; failed calls are not billed.

Does video super resolution support live streams or real-time stream processing?

Video super resolution does not support live streams or real-time stream processing. It only supports asynchronous super resolution processing of stored video files.

What should I do if the output video is choppy or has an abnormal duration after super resolution processing?

Cause: The input video uses a variable frame rate (VFR), but the model outputs a constant frame rate (CFR) by default. The frame rate conversion can cause the output video to appear choppy or have an incorrect duration.

Solution: Before calling the SuperResolveVideo API, convert your video to a constant frame rate (CFR) format and then upload it for processing.