Video Enhancement
This document provides code examples for Video Enhancement across popular programming languages and for common scenarios.
-
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
For a feature overview and detailed parameter descriptions, see Video Enhancement.
Install the SDK package
For information about the SDK package dependencies for popular languages, see SDK overview.
Configure environment variables
Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
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
Open a terminal in IntelliJ IDEA.
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_IDandALIBABA_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.Open File Explorer, right-click This PC, and then select Properties.
In the left-side navigation pane, click Advanced system settings.
On the Advanced tab of the System Properties dialog box, click Environment Variables.
In the Environment Variables dialog box, click New.
In the New System Variable dialog box, add the environment variables
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared.Restart the Windows operating system for the configurations to take effect.
Code examples
Process a file from OSS (Shanghai)
For code examples on how to query an asynchronous task result in popular languages, see Query an asynchronous task result.
/*
Import dependencies
<!-- 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.EnhanceVideoQualityResponse;
public class EnhanceVideoQuality {
public static com.aliyun.videoenhan20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
Initialize the configuration object com.aliyun.teaopenapi.models.Config.
This object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
*/
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// The service endpoint.
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 must 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 these environment variables before running the code example.
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
com.aliyun.videoenhan20200320.Client client = EnhanceVideoQuality.createClient(accessKeyId, accessKeySecret);
com.aliyun.videoenhan20200320.models.EnhanceVideoQualityRequest enhanceVideoQualityRequest = new com.aliyun.videoenhan20200320.models.EnhanceVideoQualityRequest()
.setVideoURL("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4")
.setBitrate(20)
.setFrameRate(50)
.setHDRFormat("PQ")
.setMaxIlluminance(600)
.setOutPutHeight(1920)
.setOutPutWidth(2560);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
EnhanceVideoQualityResponse enhanceVideoQualityResponse = client.enhanceVideoQualityWithOptions(enhanceVideoQualityRequest, runtime);
// Get the complete response.
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(enhanceVideoQualityResponse)));
// Get a specific field.
System.out.println(enhanceVideoQualityResponse.getBody());
} catch (TeaException teaException) {
// Get the complete error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
// Get a specific field.
System.out.println(teaException.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Import dependencies
# 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 EnhanceVideoQualityRequest
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 must 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 these environment variables before running the code example.
access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
# The service endpoint.
endpoint='videoenhan.cn-shanghai.aliyuncs.com',
# The region ID of the endpoint.
region_id='cn-shanghai'
)
enhance_video_quality_request = EnhanceVideoQualityRequest(
video_url='https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4',
out_put_width=2560,
out_put_height=1920,
frame_rate=50,
hdrformat='PQ',
max_illuminance=600
)
runtime = RuntimeOptions()
try:
# Initialize the client.
client = Client(config)
response = client.enhance_video_quality_with_options(enhance_video_quality_request, runtime)
# Get the complete response.
print(response.body)
except Exception as error:
# Get the complete error message.
print(error)
# Get a specific field.
print(error.code)
<?php
// Install dependencies
// 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\EnhanceVideoQualityRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class EnhanceVideoQuality {
/**
* Initialize the client by using an AccessKey ID and AccessKey Secret.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Videoenhan Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initialize the configuration object Darabonba\OpenApi\Models\Config.
// This object stores configurations such as your accessKeyId, accessKeySecret, and endpoint.
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// The service endpoint.
$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 must 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 these environment variables before running the example.
$accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
$accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
$client = self::createClient($accessKeyId, $accessKeySecret);
$enhanceVideoQualityRequest = new EnhanceVideoQualityRequest([
"videoURL" => "https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4",
"outPutWidth" => 2560,
"outPutHeight" => 1920,
"frameRate" => 50,
"HDRFormat" => "PQ",
"maxIlluminance" => 600,
"bitrate" => 20
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->enhanceVideoQualityWithOptions($enhanceVideoQualityRequest, $runtime);
# Get the complete response.
echo Utils::toJSONString($resp->body);
} catch (Exception $exception) {
# Get the complete 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;
}
// The `$argv` array is reserved for input parameters and should not be modified.
EnhanceVideoQuality::main(array_slice($argv, 1));
// Install dependencies
// 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 must 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 these environment variables before running the example.
accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The service endpoint.
config.endpoint = `videoenhan.cn-shanghai.aliyuncs.com`;
const client = new VideoenhanClient.default(config);
let enhanceVideoQualityRequest = new VideoenhanClient.EnhanceVideoQualityRequest({
videoURL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4",
outPutHeight: 1920,
frameRate: 50,
HDRFormat: "PQ",
maxIlluminance: 600,
bitrate: 20,
outPutWidth: 2560,
});
let runtime = new TeaUtil.RuntimeOptions({});
client.enhanceVideoQualityWithOptions(enhanceVideoQualityRequest, runtime)
.then(function (enhanceVideoQualityResponse) {
// Get the complete response.
console.log(enhanceVideoQualityResponse);
// Get a specific field.
console.log(enhanceVideoQualityResponse.body.data);
}, function (error) {
// Get the complete error message.
console.log(error);
// Get a specific field.
console.log(error.data.Code);
})
/**
Dependency: github.com/alibabacloud-go/videoenhan-20200320/v3
We recommend using 'go mod tidy' to install dependencies.
*/
package main
import (
"fmt"
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"
"os"
)
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 must 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 these environment variables before running the example.
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// Initialize the configuration object &openapi.Config. This object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret),
}
// The service endpoint.
config.Endpoint = tea.String("videoenhan.cn-shanghai.aliyuncs.com")
client, err := videoenhan20200320.NewClient(config)
if err != nil {
panic(err)
}
enhanceVideoQualityRequest := &videoenhan20200320.EnhanceVideoQualityRequest{
VideoURL: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4"),
Bitrate: tea.Int32(20),
FrameRate: tea.Int32(50),
HDRFormat: tea.String("PQ"),
MaxIlluminance: tea.Int32(600),
OutPutHeight: tea.Int32(1920),
OutPutWidth: tea.Int32(2560),
}
runtime := &util.RuntimeOptions{}
enhanceVideoQualityResponse, err := client.EnhanceVideoQualityWithOptions(enhanceVideoQualityRequest, runtime)
if err != nil {
// Get the complete error message.
fmt.Println(err.Error())
} else {
// Get the complete response.
fmt.Println(enhanceVideoQualityResponse)
}
}
// Install dependencies
// dotnet add package AlibabaCloud.SDK.Videoenhan20200320
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Videoenhan20200320.Models;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* Initialize the client by using an AccessKey ID and AccessKey Secret.
* @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 service endpoint.
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 must 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 these environment variables before running the code example.
AlibabaCloud.SDK.Videoenhan20200320.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
AlibabaCloud.SDK.Videoenhan20200320.Models.EnhanceVideoQualityRequest enhanceVideoQualityRequest = new AlibabaCloud.SDK.Videoenhan20200320.Models.EnhanceVideoQualityRequest
{
VideoURL = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4",
OutPutWidth = 2560,
OutPutHeight = 1920,
FrameRate = 50,
HDRFormat = "PQ",
MaxIlluminance = 600,
Bitrate = 20,
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Videoenhan20200320.Models.EnhanceVideoQualityResponse enhanceVideoQualityResponse = client.EnhanceVideoQualityWithOptions(enhanceVideoQualityRequest, runtime);
// Get the complete response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(enhanceVideoQualityResponse.Body));
// Get a specific field.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(enhanceVideoQualityResponse.Body.Data));
}
catch (TeaException error)
{
// Prints the error message.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Prints the error message.
Console.WriteLine(error.Message);
}
}
}
}
Process a local file or URL
For code examples on how to query an asynchronous task result in popular languages, see Query an asynchronous task result.
/*
Import dependencies
<!-- 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.EnhanceVideoQualityResponse;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.io.File;
public class EnhanceVideoQuality {
public static com.aliyun.videoenhan20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
Initialize the configuration object com.aliyun.teaopenapi.models.Config.
This object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
*/
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// The service endpoint.
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 must 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 these environment variables before running the code example.
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
com.aliyun.videoenhan20200320.Client client = EnhanceVideoQuality.createClient(accessKeyId, accessKeySecret);
// Scenario 1: Use a local file.
// InputStream inputStream = new FileInputStream(new File("/tmp/EnhanceVideoQuality-video.mp4"));
// Scenario 2: Use a publicly accessible URL.
URL url = new URL("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4");
InputStream inputStream = url.openConnection().getInputStream();
com.aliyun.videoenhan20200320.models.EnhanceVideoQualityAdvanceRequest enhanceVideoQualityAdvanceRequest = new com.aliyun.videoenhan20200320.models.EnhanceVideoQualityAdvanceRequest()
.setVideoURLObject(inputStream)
.setBitrate(20)
.setFrameRate(50)
.setHDRFormat("PQ")
.setMaxIlluminance(600)
.setOutPutHeight(1920)
.setOutPutWidth(2560);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
EnhanceVideoQualityResponse enhanceVideoQualityAdvanceResponse = client.enhanceVideoQualityAdvance(enhanceVideoQualityAdvanceRequest, runtime);
// Get the complete response.
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(enhanceVideoQualityAdvanceResponse)));
// Get a specific field.
System.out.println(enhanceVideoQualityAdvanceResponse.getBody());
} catch (TeaException teaException) {
// Get the complete error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
// Get a specific field.
System.out.println(teaException.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Import dependencies
# 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 EnhanceVideoQualityAdvanceRequest
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 must 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 these environment variables before running the code example.
access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
# The service endpoint.
endpoint='videoenhan.cn-shanghai.aliyuncs.com',
# The region ID of the endpoint.
region_id='cn-shanghai'
)
# Scenario 1: The file is stored locally.
# img = open(r'/tmp/EnhanceVideoQuality1.mp4', 'rb')
# Scenario 2: Use a publicly accessible URL.
url = 'https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4'
img = io.BytesIO(urlopen(url).read())
enhance_video_quality_request = EnhanceVideoQualityAdvanceRequest(
video_urlobject=img,
out_put_width=2560,
out_put_height=1920,
frame_rate=50,
hdrformat='PQ',
max_illuminance=600
)
runtime = RuntimeOptions()
try:
# Initialize the client.
client = Client(config)
response = client.enhance_video_quality_advance(enhance_video_quality_request, runtime)
# Get the complete response.
print(response.body)
except Exception as error:
# Get the complete error message.
print(error)
# Get a specific field.
print(error.code)
<?php
// Install dependencies
// 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\EnhanceVideoQualityAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;
class EnhanceVideoQualityAdvance {
/**
* Initialize the client by using an AccessKey ID and AccessKey Secret.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Videoenhan Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initialize the configuration object Darabonba\OpenApi\Models\Config.
// This object stores configurations such as your accessKeyId, accessKeySecret, and endpoint.
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// The service endpoint.
$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 must 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 these environment variables before running the example.
$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/EnhanceVideoQuality1.mp4', 'rb');
//$stream = new Stream($file);
// Scenario 2: Use a publicly accessible URL.
$file = fopen('https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4', 'rb');
$stream = new Stream($file);
$enhanceVideoQualityAdvanceRequest = new EnhanceVideoQualityAdvanceRequest([
"videoURLObject" => $stream,
"outPutWidth" => 2560,
"outPutHeight" => 1920,
"frameRate" => 50,
"HDRFormat" => "PQ",
"maxIlluminance" => 600,
"bitrate" => 20
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->enhanceVideoQualityAdvance($enhanceVideoQualityAdvanceRequest, $runtime);
# Get the complete response.
echo Utils::toJSONString($resp->body);
} catch (Exception $exception) {
# Get the complete 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;
}
// The `$argv` array is reserved for input parameters and should not be modified.
EnhanceVideoQualityAdvance::main(array_slice($argv, 1));
// Install dependencies
// 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');
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 must 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 these environment variables before running the example.
accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The service endpoint.
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 enhanceVideoQualityAdvanceRequest = new VideoenhanClient.EnhanceVideoQualityAdvanceRequest();
// Scenario 1: Use a local file.
// const fileStream = fs.createReadStream('/tmp/EnhanceVideoQuality1.mp4');
// enhanceVideoQualityAdvanceRequest.videoURLObject = fileStream;
// Scenario 2: Use a publicly accessible URL.
const url = new URL("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4");
const httpClient = (url.protocol == "https:") ? https : http;
enhanceVideoQualityAdvanceRequest.videoURLObject = await getResponse(httpClient, url);
enhanceVideoQualityAdvanceRequest.outPutHeight = 1920;
enhanceVideoQualityAdvanceRequest.frameRate = 50;
enhanceVideoQualityAdvanceRequest.HDRFormat = "PQ",
enhanceVideoQualityAdvanceRequest.maxIlluminance = 600;
enhanceVideoQualityAdvanceRequest.bitrate = 20;
enhanceVideoQualityAdvanceRequest.outPutWidth = 2560;
let runtime = new TeaUtil.RuntimeOptions({ });
client.enhanceVideoQualityAdvance(enhanceVideoQualityAdvanceRequest, runtime)
.then(function(enhanceVideoQualityResponse) {
// Get the complete response.
console.log(enhanceVideoQualityResponse);
// Get a specific field.
console.log(enhanceVideoQualityResponse.body.data);
}, function(error) {
// Get the complete error message.
console.log(error);
// Get a specific field.
console.log(error.data.Code);
})
} catch (error) {
console.log(error);
}
}();
/**
Dependency: github.com/alibabacloud-go/videoenhan-20200320/v3
We recommend using 'go mod tidy' to install dependencies.
*/
package main
import (
"fmt"
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"
"os"
)
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 must 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 these environment variables before running the example.
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// Initialize the configuration object &openapi.Config. This object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret),
}
// The service endpoint.
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/EnhanceVideoQuality1.mp4")
//if err != nil {
// fmt.Println("cannot open file", err)
// panic(err)
//}
//enhanceVideoQualityAdvanceRequest := &videoenhan20200320.EnhanceVideoQualityAdvanceRequest{
// VideoURLObject: file,
// Bitrate: tea.Int32(20),
// FrameRate: tea.Int32(50),
// HDRFormat: tea.String("PQ"),
// MaxIlluminance: tea.Int32(600),
// OutPutHeight: tea.Int32(1920),
// OutPutWidth: tea.Int32(2560),
//}
// Scenario 2: Use a publicly accessible URL.
httpClient := http.Client{}
resp, _ := httpClient.Get("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4")
enhanceVideoQualityAdvanceRequest := &videoenhan20200320.EnhanceVideoQualityAdvanceRequest{
VideoURLObject: resp.Body,
Bitrate: tea.Int32(20),
FrameRate: tea.Int32(50),
HDRFormat: tea.String("PQ"),
MaxIlluminance: tea.Int32(600),
OutPutHeight: tea.Int32(1920),
OutPutWidth: tea.Int32(2560),
}
runtime := &util.RuntimeOptions{}
enhanceVideoQualityAdvanceResponse, err := client.EnhanceVideoQualityAdvance(enhanceVideoQualityAdvanceRequest, runtime)
if err != nil {
// Get the complete error message.
fmt.Println(err.Error())
} else {
// Get the complete response.
fmt.Println(enhanceVideoQualityAdvanceResponse)
}
}
// Install dependencies
// dotnet add package AlibabaCloud.SDK.Videoenhan20200320
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Videoenhan20200320.Models;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* Initialize the client by using an AccessKey ID and AccessKey Secret.
* @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 service endpoint.
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 must 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 these environment variables before running the code example.
AlibabaCloud.SDK.Videoenhan20200320.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
AlibabaCloud.SDK.Videoenhan20200320.Models.EnhanceVideoQualityAdvanceRequest enhanceVideoQualityAdvanceRequest = new AlibabaCloud.SDK.Videoenhan20200320.Models.EnhanceVideoQualityAdvanceRequest
();
// Scenario 1: Use a local file.
// System.IO.Stream fileStream = new System.IO.FileStream(@"/tmp/EnhanceVideoQuality1.mp4", System.IO.FileMode.Open);
// enhanceVideoQualityAdvanceRequest.VideoURLObject = fileStream;
// Scenario 2: Use a publicly accessible URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/EnhanceVideoQuality/EnhanceVideoQuality1.mp4");
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
enhanceVideoQualityAdvanceRequest.VideoURLObject = stream;
enhanceVideoQualityAdvanceRequest.OutPutWidth = 2560;
enhanceVideoQualityAdvanceRequest.OutPutHeight = 1920;
enhanceVideoQualityAdvanceRequest.FrameRate = 50;
enhanceVideoQualityAdvanceRequest.HDRFormat = "PQ";
enhanceVideoQualityAdvanceRequest.MaxIlluminance = 600;
enhanceVideoQualityAdvanceRequest.Bitrate = 20;
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Videoenhan20200320.Models.EnhanceVideoQualityResponse enhanceVideoQualityResponse = client.EnhanceVideoQualityAdvance(enhanceVideoQualityAdvanceRequest, runtime);
// Get the complete response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(enhanceVideoQualityResponse.Body));
// Get a specific field.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(enhanceVideoQualityResponse.Body.Data));
}
catch (TeaException error)
{
// Prints the error message.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Prints the error message.
Console.WriteLine(error.Message);
}
}
}
}