This document provides sample code in common programming languages for Video Portrait Cartoonization.
For live support, visit Contact Us.
For inquiries about API integration, usage, or other topics related to the Vision AI Open Platform, join our DingTalk group (ID: 23109592).
Overview
For a detailed description of the Video Portrait Cartoonization feature and its parameters, see Video Portrait Cartoonization.
Install the SDK
For information about SDK dependencies for common programming 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.
Sample code
OSS file in the China (Shanghai) region
For sample code showing how to query asynchronous task results, see Query asynchronous task results.
// -*- coding: utf-8 -*-
// Import the required dependency packages.
// The minimum required SDK version for videoenhan20200320 is 2.0.13.
// You can find the latest SDK version in this repository: 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.GenerateHumanAnimeStyleVideoResponse;
public class GenerateHumanAnimeStyleVideo {
public static com.aliyun.videoenhan20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
Initializes the configuration object com.aliyun.teaopenapi.models.Config.
This object stores configuration parameters such as AccessKeyId, AccessKeySecret, 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 {
// For more information about how to create an AccessKey pair, 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 environment variables before running 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 = GenerateHumanAnimeStyleVideo.createClient(accessKeyId, accessKeySecret);
com.aliyun.videoenhan20200320.models.GenerateHumanAnimeStyleVideoRequest generateHumanAnimeStyleVideoRequest = new com.aliyun.videoenhan20200320.models.GenerateHumanAnimeStyleVideoRequest()
.setVideoUrl("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4")
.setCartoonStyle("anime");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// After you run the sample code, we recommend that you print the API response.
GenerateHumanAnimeStyleVideoResponse response = client.generateHumanAnimeStyleVideoWithOptions(generateHumanAnimeStyleVideoRequest, runtime);
// Get the complete response.
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
} catch (TeaException error) {
// Get the complete error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(error));
// Get a specific field from the response.
System.out.println(error.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Import the required dependency packages.
# The minimum required SDK version for videoenhan20200320 is 3.0.13.
# You can find the latest SDK version in this repository: https://pypi.org/project/alibabacloud-videoenhan20200320/
# 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 GenerateHumanAnimeStyleVideoRequest
config = Config(
# For more information about how to create an AccessKey pair, 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 environment variables before running 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 service endpoint.
endpoint='videoenhan.cn-shanghai.aliyuncs.com',
# The region that corresponds to the endpoint.
region_id='cn-shanghai'
)
generate_human_anime_style_video_request = GenerateHumanAnimeStyleVideoRequest(
video_url='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test/videoenhan/GenerateHumanAnimeStyleVideo.mp4',
cartoon_style='anime'
)
runtime = RuntimeOptions()
try:
# Initialize the client.
client = Client(config)
response = client.generate_human_anime_style_video_with_options(generate_human_anime_style_video_request, runtime)
# Get the complete response.
print(response.body)
except Exception as error:
# Get the complete error message.
print(error)
# Get a specific field from the response.
print(error.code)<?php
// Install the required dependency packages.
// The minimum required SDK version for videoenhan-20200320 is 2.0.13.
// You can find the latest SDK version in this repository: https://packagist.org/packages/alibabacloud/videoenhan-20200320
// 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\GenerateHumanAnimeStyleVideoRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class GenerateHumanAnimeStyleVideo {
/**
* Use the AccessKey pair to initialize the client.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Videoenhan Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initializes the configuration object Darabonba\OpenApi\Models\Config.
// This object stores configuration parameters such as 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){
// For more information about how to create an AccessKey pair, 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 environment variables before running the sample code.
$accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
$accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
$client = self::createClient($accessKeyId, $accessKeySecret);
$generateHumanAnimeStyleVideoRequest = new GenerateHumanAnimeStyleVideoRequest([
"videoUrl" => "https://viapi-test.oss-cn-shanghai.aliyuncs.com/test/videoenhan/GenerateHumanAnimeStyleVideo.mp4",
"cartoonStyle" => "anime"
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->generateHumanAnimeStyleVideoWithOptions($generateHumanAnimeStyleVideoRequest, $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 from the response.
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 a reserved parameter for input arguments. It does not need to be modified.
GenerateHumanAnimeStyleVideo::main(array_slice($argv, 1));// Install the required dependency package.
// npm install @alicloud/videoenhan20200320
// The minimum required SDK version for videoenhan20200320 is 3.0.12.
// You can find the latest SDK version in this repository: https://npmjs.com/package/@alicloud/videoenhan20200320
const VideoenhanClient = require('@alicloud/videoenhan20200320');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');
let config = new OpenapiClient.Config({
// For more information about how to create an AccessKey pair, 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 environment variables before running the sample code.
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 generateHumanAnimeStyleVideoRequest = new VideoenhanClient.GenerateHumanAnimeStyleVideoRequest({
cartoonStyle: "anime",
videoUrl: "https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4",
});
let runtime = new TeaUtil.RuntimeOptions({});
client.generateHumanAnimeStyleVideoWithOptions(generateHumanAnimeStyleVideoRequest, runtime)
.then(function (generateHumanAnimeStyleVideoResponse) {
// Get the complete response.
console.log(generateHumanAnimeStyleVideoResponse);
// Get a specific field from the response.
console.log(generateHumanAnimeStyleVideoResponse.body.data);
}, function (error) {
// Get the complete error message.
console.log(error);
// Get a specific field from the response.
console.log(error.data.Code);
})// -*- coding: utf-8 -*-
// Import the required dependency packages.
// The minimum required SDK version for videoenhan20200320 is 3.0.11.
// You can find the latest SDK version in this repository: https://pkg.go.dev/github.com/alibabacloud-go/videoenhan-20200320/v3
// go get github.com/alibabacloud-go/videoenhan-20200320/v3
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"
)
func main() {
// For more information about how to create an AccessKey pair, 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 environment variables before running the sample code.
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// Initializes the configuration object &openapi.Config. This object holds configuration parameters such as AccessKeyId, AccessKeySecret, 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 {
fmt.Println(err.Error())
}
generateHumanAnimeStyleVideoRequest := &videoenhan20200320.GenerateHumanAnimeStyleVideoRequest{
VideoUrl: tea.String("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4"),
CartoonStyle: tea.String("anime"),
}
runtime := &util.RuntimeOptions{}
generateHumanAnimeStyleVideoResponse, _err := client.GenerateHumanAnimeStyleVideoWithOptions(generateHumanAnimeStyleVideoRequest, runtime)
if _err != nil {
fmt.Println(_err.Error())
} else {
// Get the complete response.
fmt.Println(generateHumanAnimeStyleVideoResponse)
// Get a specific field from the response.
fmt.Println(generateHumanAnimeStyleVideoResponse.Body.Data)
}
}// Install the required dependency packages.
// dotnet add package AlibabaCloud.SDK.Videoenhan20200320
// The minimum required SDK version for videoenhan20200320 is 2.0.12.
// You can find the latest SDK version in this repository: https://nuget.org/packages/AlibabaCloud.SDK.Videoenhan20200320
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
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
{
/**
* Use the 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)
{
// Initializes the configuration object AlibabaCloud.OpenApiClient.Models.Config. This object holds configuration parameters such as AccessKeyId, AccessKeySecret, and endpoint.
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)
{
// For more information about how to create an AccessKey pair, 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 environment variables before running 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"));
AlibabaCloud.SDK.Videoenhan20200320.Models.GenerateHumanAnimeStyleVideoRequest generateHumanAnimeStyleVideoRequest = new AlibabaCloud.SDK.Videoenhan20200320.Models.GenerateHumanAnimeStyleVideoRequest
{
CartoonStyle = "anime",
VideoUrl = "https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4",
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Videoenhan20200320.Models.GenerateHumanAnimeStyleVideoResponse generateHumanAnimeStyleVideoResponse = client.GenerateHumanAnimeStyleVideoWithOptions(generateHumanAnimeStyleVideoRequest, runtime);
// Get the complete response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleVideoResponse.Body));
// Get a specific field from the response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleVideoResponse.Body.Data));
}
catch (TeaException error)
{
// Print the error message as needed.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Print the error message as needed.
Console.WriteLine(error.Message);
}
}
}
}Local file or file in another OSS region
For sample code showing how to query asynchronous task results, see Query asynchronous task results.
// -*- coding: utf-8 -*-
// Import the required dependency packages.
// The minimum required SDK version for videoenhan20200320 is 2.0.13.
// You can find the latest SDK version in this repository: 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.GenerateHumanAnimeStyleVideoResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
public class GenerateHumanAnimeStyleVideo {
public static com.aliyun.videoenhan20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
Initializes the configuration object com.aliyun.teaopenapi.models.Config.
This object stores configuration parameters such as AccessKeyId, AccessKeySecret, 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 {
// For more information about how to create an AccessKey pair, 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 environment variables before running 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 = GenerateHumanAnimeStyleVideo.createClient(accessKeyId, accessKeySecret);
// Scenario 1: Use a local file.
// InputStream inputStream = new FileInputStream(new File("/tmp/GenerateHumanAnimeStyleVideo1.mp4"));
// Scenario 2: Use a publicly accessible URL.
URL url = new URL("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4");
InputStream inputStream = url.openConnection().getInputStream();
com.aliyun.videoenhan20200320.models.GenerateHumanAnimeStyleVideoAdvanceRequest generateHumanAnimeStyleVideoAdvanceRequest = new com.aliyun.videoenhan20200320.models.GenerateHumanAnimeStyleVideoAdvanceRequest()
.setVideoUrlObject(inputStream)
.setCartoonStyle("anime");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// After you run the sample code, we recommend that you print the API response.
GenerateHumanAnimeStyleVideoResponse response = client.generateHumanAnimeStyleVideoAdvance(generateHumanAnimeStyleVideoAdvanceRequest, runtime);
// Get the complete response.
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
} catch (TeaException error) {
// Get the complete error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(error));
// Get a specific field from the response.
System.out.println(error.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Import the required dependency packages.
# The minimum required SDK version for videoenhan20200320 is 3.0.13.
# You can find the latest SDK version in this repository: https://pypi.org/project/alibabacloud-videoenhan20200320/
# 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 GenerateHumanAnimeStyleVideoAdvanceRequest
config = Config(
# For more information about how to create an AccessKey pair, 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 environment variables before running 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 service endpoint.
endpoint='videoenhan.cn-shanghai.aliyuncs.com',
# The region that corresponds to the endpoint.
region_id='cn-shanghai'
)
# Scenario 1: The file is stored locally.
#img = open(r'/tmp/GenerateHumanAnimeStyleVideo.mp4', 'rb')
# Scenario 2: Use a publicly accessible URL.
url = 'https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4'
img = io.BytesIO(urlopen(url).read())
generate_human_anime_style_video_request = GenerateHumanAnimeStyleVideoAdvanceRequest(
video_url_object=img,
cartoon_style='anime'
)
runtime = RuntimeOptions()
try:
# Initialize the client.
client = Client(config)
response = client.generate_human_anime_style_video_advance(generate_human_anime_style_video_request, runtime)
# Get the complete response.
print(response.body)
except Exception as error:
# Get the complete error message.
print(error)
# Get a specific field from the response.
print(error.code)<?php
// Install the required dependency packages.
// The minimum required SDK version for videoenhan-20200320 is 2.0.13.
// You can find the latest SDK version in this repository: https://packagist.org/packages/alibabacloud/videoenhan-20200320
// 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\GenerateHumanAnimeStyleVideoAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;
class GenerateHumanAnimeStyleVideoAdvance {
/**
* Use the AccessKey pair to initialize the client.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Videoenhan Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initializes the configuration object Darabonba\OpenApi\Models\Config.
// This object stores configuration parameters such as 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){
// For more information about how to create an AccessKey pair, 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 environment variables before running 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/GenerateHumanAnimeStyleVideo.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/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4', 'rb');
$stream = new Stream($file);
$generateHumanAnimeStyleVideoAdvanceRequest = new GenerateHumanAnimeStyleVideoAdvanceRequest([
"videoUrlObject" => $stream,
"cartoonStyle" => "anime"
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->generateHumanAnimeStyleVideoAdvance($generateHumanAnimeStyleVideoAdvanceRequest, $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 from the response.
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 a reserved parameter for input arguments. It does not need to be modified.
GenerateHumanAnimeStyleVideoAdvance::main(array_slice($argv, 1));// Install the required dependency package.
// npm install @alicloud/videoenhan20200320
// The minimum required SDK version for videoenhan20200320 is 3.0.12.
// You can find the latest SDK version in this repository: https://npmjs.com/package/@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({
// For more information about how to create an AccessKey pair, 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 environment variables before running the sample code.
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 generateHumanAnimeStyleVideoAdvanceRequest = new VideoenhanClient.GenerateHumanAnimeStyleVideoAdvanceRequest();
// Scenario 1: Use a local file.
// const fileStream = fs.createReadStream('/tmp/GenerateHumanAnimeStyleVideo.mp4');
// generateHumanAnimeStyleVideoAdvanceRequest.videoUrlObject = fileStream;
// generateHumanAnimeStyleVideoAdvanceRequest.cartoonStyle = "anime";
// Scenario 2: Use a publicly accessible URL.
const url = new URL("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4");
const httpClient = (url.protocol == "https:") ? https : http;
generateHumanAnimeStyleVideoAdvanceRequest.videoUrlObject = await getResponse(httpClient, url);
generateHumanAnimeStyleVideoAdvanceRequest.cartoonStyle = "anime";
let runtime = new TeaUtil.RuntimeOptions({ });
client.generateHumanAnimeStyleVideoAdvance(generateHumanAnimeStyleVideoAdvanceRequest, runtime)
.then(function(generateHumanAnimeStyleVideoResponse) {
// Get the complete response.
console.log(generateHumanAnimeStyleVideoResponse);
// Get a specific field from the response.
console.log(generateHumanAnimeStyleVideoResponse.body.data);
}, function(error) {
// Get the complete error message.
console.log(error);
// Get a specific field from the response.
console.log(error.data.Code);
})
} catch (error) {
console.log(error);
}
}();// -*- coding: utf-8 -*-
// Import the required dependency packages.
// The minimum required SDK version for videoenhan20200320 is 3.0.11.
// You can find the latest SDK version in this repository: https://pkg.go.dev/github.com/alibabacloud-go/videoenhan-20200320/v3
// go get github.com/alibabacloud-go/videoenhan-20200320/v3
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"
)
func main() {
// For more information about how to create an AccessKey pair, 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 environment variables before running the sample code.
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// Initializes the configuration object &openapi.Config. This object holds configuration parameters such as AccessKeyId, AccessKeySecret, 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 {
fmt.Println(err.Error())
}
// Scenario 1: Use a local file.
//file, err := os.Open("/tmp/GenerateHumanAnimeStyleVideo1.mp4")
//if err != nil {
// fmt.Println("can not open file", err)
//}
//generateHumanAnimeStyleVideoAdvanceRequest := &videoenhan20200320.GenerateHumanAnimeStyleVideoAdvanceRequest{
// VideoUrlObject: file,
// CartoonStyle: tea.String("anime"),
//}
// Scenario 2: Use a publicly accessible URL.
httpClient := http.Client{}
file1, _ := httpClient.Get("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4")
generateHumanAnimeStyleVideoAdvanceRequest := &videoenhan20200320.GenerateHumanAnimeStyleVideoAdvanceRequest{
VideoUrlObject: file1.Body,
CartoonStyle: tea.String("anime"),
}
runtime := &util.RuntimeOptions{}
generateHumanAnimeStyleVideoResponse, _err := client.GenerateHumanAnimeStyleVideoAdvance(generateHumanAnimeStyleVideoAdvanceRequest, runtime)
if _err != nil {
fmt.Println(_err.Error())
} else {
// Get the complete response.
fmt.Println(generateHumanAnimeStyleVideoResponse)
// Get a specific field from the response.
fmt.Println(generateHumanAnimeStyleVideoResponse.Body.Data)
}
}
// Install the required dependency packages.
// dotnet add package AlibabaCloud.SDK.Videoenhan20200320
// The minimum required SDK version for videoenhan20200320 is 2.0.12.
// You can find the latest SDK version in this repository: https://nuget.org/packages/AlibabaCloud.SDK.Videoenhan20200320
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
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
{
/**
* Use the 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)
{
// Initializes the configuration object AlibabaCloud.OpenApiClient.Models.Config. This object holds configuration parameters such as AccessKeyId, AccessKeySecret, and endpoint.
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)
{
// For more information about how to create an AccessKey pair, 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 environment variables before running 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"));
AlibabaCloud.SDK.Videoenhan20200320.Models.GenerateHumanAnimeStyleVideoAdvanceRequest generateHumanAnimeStyleVideoAdvanceRequest = new AlibabaCloud.SDK.Videoenhan20200320.Models.GenerateHumanAnimeStyleVideoAdvanceRequest
();
// Scenario 1: Use a local file.
//System.IO.StreamReader file = new System.IO.StreamReader(@"/tmp/GenerateHumanAnimeStyleVideo.mp4");
//generateHumanAnimeStyleVideoAdvanceRequest.VideoUrlObject = file.BaseStream;
//generateHumanAnimeStyleVideoAdvanceRequest.CartoonStyle = "anime";
// Scenario 2: Use a publicly accessible URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videoenhan/GenerateHumanAnimeStyleVideo/GenerateHumanAnimeStyleVideo1.mp4");
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
generateHumanAnimeStyleVideoAdvanceRequest.VideoUrlObject = stream;
generateHumanAnimeStyleVideoAdvanceRequest.CartoonStyle = "anime";
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Videoenhan20200320.Models.GenerateHumanAnimeStyleVideoResponse generateHumanAnimeStyleVideoResponse = client.GenerateHumanAnimeStyleVideoAdvance(generateHumanAnimeStyleVideoAdvanceRequest, runtime);
// Get the complete response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleVideoResponse.Body));
// Get a specific field from the response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleVideoResponse.Body.Data));
}
catch (TeaException error)
{
// Print the error message as needed.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Print the error message as needed.
Console.WriteLine(error.Message);
}
}
}
}