This topic provides sample code that shows how to use the video splitting SDK for common scenarios in popular programming languages.
-
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 an overview of the video splitting feature and its request parameters, see video splitting.
SDK installation
For information about SDK dependencies for popular programming languages, see the 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
File in OSS (Shanghai)
For sample code on how to query the results of an asynchronous task in popular languages, see Query asynchronous task results.
// Minimum SDK version: 1.0.8 or later for videorecog20200320.
// You can find the latest SDK version in this repository: https://mvnrepository.com/artifact/com.aliyun/videorecog20200320
// <dependency>
// <groupId>com.aliyun</groupId>
// <artifactId>videorecog20200320</artifactId>
// <version>${aliyun.videorecog.version}</version>
// </dependency>
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.videorecog20200320.models.SplitVideoPartsResponse;
public class SplitVideoParts {
public static com.aliyun.videorecog20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
Initializes the configuration object com.aliyun.teaopenapi.models.Config.
This object stores configurations 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 = "videorecog.cn-shanghai.aliyuncs.com";
return new com.aliyun.videorecog20200320.Client(config);
}
public static void main(String[] args) throws Exception {
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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.videorecog20200320.Client client = SplitVideoParts.createClient(accessKeyId, accessKeySecret);
com.aliyun.videorecog20200320.models.SplitVideoPartsRequest splitVideoPartsRequest = new com.aliyun.videorecog20200320.models.SplitVideoPartsRequest()
.setVideoUrl("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// Print the API response for debugging.
SplitVideoPartsResponse response = client.splitVideoPartsWithOptions(splitVideoPartsRequest, runtime);
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
} catch (TeaException error) {
// Get the full error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(error));
// Get a specific field.
System.out.println(error.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Import dependencies.
# Minimum SDK version: 3.0.7 or later for alibabacloud-videorecog20200320.
# You can find the latest SDK version in this repository: https://pypi.org/project/alibabacloud-videorecog20200320/
# pip install alibabacloud_videorecog20200320
import os
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions
from alibabacloud_videorecog20200320.client import Client
from alibabacloud_videorecog20200320.models import SplitVideoPartsRequest
config = Config(
# To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
# If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
# Read the access key ID and access key secret from environment variables. You must configure the 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='videorecog.cn-shanghai.aliyuncs.com',
# The ID of the service region.
region_id='cn-shanghai'
)
split_video_parts_request = SplitVideoPartsRequest(
video_url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4'
)
runtime = RuntimeOptions()
try:
# Initialize the client.
client = Client(config)
response = client.split_video_parts_with_options(split_video_parts_request, runtime)
# Get the entire response.
print(response.body)
except Exception as error:
# Get the full error message.
print(error)
# Get a specific field.
print(error.code)
<?php
// Install dependencies.
// Minimum SDK version: 1.0.9 or later for alibabacloud/videorecog-20200320.
// You can find the latest SDK version in this repository: https://packagist.org/packages/alibabacloud/videorecog-20200320
// composer require alibabacloud/videorecog-20200320
use AlibabaCloud\SDK\Videorecog\V20200320\Videorecog;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Videorecog\V20200320\Models\SplitVideoPartsRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class SplitVideoParts {
/**
* Initialize the client by using an access key ID and an access key secret.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Videorecog Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initializes the configuration object Darabonba\OpenApi\Models\Config.
// This object stores configurations such as accessKeyId, accessKeySecret, and endpoint.
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// The service endpoint.
$config->endpoint = "videorecog.cn-shanghai.aliyuncs.com";
return new Videorecog($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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);
$splitVideoPartsRequest = new SplitVideoPartsRequest([
"videoUrl" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4"
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->splitVideoPartsWithOptions($splitVideoPartsRequest, $runtime);
// Get the entire 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 arguments and does not need to be modified.
SplitVideoParts::main(array_slice($argv, 1));
// Install dependencies.
// npm install @alicloud/videorecog20200320
// Minimum SDK version: 3.0.6 or later for @alicloud/videorecog20200320.
// You can find the latest SDK version in this repository: https://npmjs.com/package/@alicloud/videorecog20200320
const VideorecogClient = require('@alicloud/videorecog20200320');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');
let config = new OpenapiClient.Config({
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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 = `videorecog.cn-shanghai.aliyuncs.com`;
const client = new VideorecogClient.default(config);
let splitVideoPartsRequest = new VideorecogClient.SplitVideoPartsRequest({
videoUrl: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4",
});
let runtime = new TeaUtil.RuntimeOptions({});
client.splitVideoPartsWithOptions(splitVideoPartsRequest, runtime)
.then(function (splitVideoPartsResponse) {
// Get the entire response.
console.log(splitVideoPartsResponse);
// Get a specific field.
console.log(splitVideoPartsResponse.body.data);
}, function (error) {
// Get the full error message.
console.log(error);
// Get a specific field.
console.log(error.data.Code);
})
// Import dependencies.
// Minimum SDK version: 2.0.8 or later for github.com/alibabacloud-go/videorecog-20200320/v2.
// You can find the latest SDK version in this repository: github.com/alibabacloud-go/videorecog-20200320/v2
// go get github.com/alibabacloud-go/videorecog-20200320/v2
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"
videorecog20200320 "github.com/alibabacloud-go/videorecog-20200320/v2/client"
)
func main() {
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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 stores configurations such as AccessKeyId, AccessKeySecret, and Endpoint.
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret)
}
// The service endpoint.
config.Endpoint = tea.String("videorecog.cn-shanghai.aliyuncs.com")
client, err := videorecog20200320.NewClient(config)
if err != nil {
fmt.Println(err.Error())
}
splitVideoPartsRequest := &videorecog20200320.SplitVideoPartsRequest{
VideoUrl: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4"),
}
runtime := &util.RuntimeOptions{}
splitVideoPartsResponse, _err := client.SplitVideoPartsWithOptions(splitVideoPartsRequest, runtime)
if _err != nil {
fmt.Println(_err.Error())
} else {
// Get the entire response.
fmt.Println(splitVideoPartsResponse)
// Get a specific field.
fmt.Println(splitVideoPartsResponse.Body.Data)
}
}
// Install the dependency package.
// dotnet add package AlibabaCloud.SDK.Videorecog20200320
// Minimum SDK version: 2.0.7 or later for AlibabaCloud.SDK.Videorecog20200320.
// You can find the latest SDK version in this repository: https://nuget.org/packages/AlibabaCloud.SDK.Videorecog20200320
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.Videorecog20200320.Models;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* Initialize the client by using an access key ID and an access key secret.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static AlibabaCloud.SDK.Videorecog20200320.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 = "videorecog.cn-shanghai.aliyuncs.com";
return new AlibabaCloud.SDK.Videorecog20200320.Client(config);
}
public static void Main(string[] args)
{
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the environment variables before running the sample code.
AlibabaCloud.SDK.Videorecog20200320.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
AlibabaCloud.SDK.Videorecog20200320.Models.SplitVideoPartsRequest splitVideoPartsRequest = new AlibabaCloud.SDK.Videorecog20200320.Models.SplitVideoPartsRequest
{
VideoUrl = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4",
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Videorecog20200320.Models.SplitVideoPartsResponse splitVideoPartsResponse = client.SplitVideoPartsWithOptions(splitVideoPartsRequest, runtime);
// Get the entire response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(splitVideoPartsResponse.Body));
// Get a specific field.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(splitVideoPartsResponse.Body.Data));
}
catch (TeaException error)
{
// Prints the error for debugging.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Prints the error for debugging.
Console.WriteLine(error.Message);
}
}
}
}
Local file or URL
For sample code on how to query the results of an asynchronous task in popular languages, see Query asynchronous task results.
// Minimum SDK version: 1.0.8 or later for videorecog20200320.
// You can find the latest SDK version in this repository: https://mvnrepository.com/artifact/com.aliyun/videorecog20200320
// <dependency>
// <groupId>com.aliyun</groupId>
// <artifactId>videorecog20200320</artifactId>
// <version>${aliyun.videorecog.version}</version>
// </dependency>
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.videorecog20200320.models.SplitVideoPartsResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
public class SplitVideoParts {
public static com.aliyun.videorecog20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
Initializes the configuration object com.aliyun.teaopenapi.models.Config.
This object stores configurations 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 = "videorecog.cn-shanghai.aliyuncs.com";
return new com.aliyun.videorecog20200320.Client(config);
}
public static void main(String[] args) throws Exception {
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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.videorecog20200320.Client client = SplitVideoParts.createClient(accessKeyId, accessKeySecret);
// Scenario 1: Use a local file.
// InputStream inputStream = new FileInputStream(new File("/tmp/SplitVideoParts1.mp4"));
// Scenario 2: Use an accessible URL.
URL url = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4");
InputStream inputStream = url.openConnection().getInputStream();
com.aliyun.videorecog20200320.models.SplitVideoPartsAdvanceRequest splitVideoPartsAdvanceRequest = new com.aliyun.videorecog20200320.models.SplitVideoPartsAdvanceRequest()
.setVideoUrlObject(inputStream);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// Print the API response for debugging.
SplitVideoPartsResponse response = client.splitVideoPartsAdvance(splitVideoPartsAdvanceRequest, runtime);
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
} catch (TeaException error) {
// Get the full error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(error));
// Get a specific field.
System.out.println(error.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Import dependencies.
# Minimum SDK version: 3.0.7 or later for alibabacloud-videorecog20200320.
# You can find the latest SDK version in this repository: https://pypi.org/project/alibabacloud-videorecog20200320/
# pip install alibabacloud_videorecog20200320
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_videorecog20200320.client import Client
from alibabacloud_videorecog20200320.models import SplitVideoPartsAdvanceRequest
config = Config(
# To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
# If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
# Read the access key ID and access key secret from environment variables. You must configure the 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='videorecog.cn-shanghai.aliyuncs.com',
# The ID of the service region.
region_id='cn-shanghai'
)
# Scenario 1: Use a local file.
#img = open(r'/tmp/SplitVideoParts1.mp4', 'rb')
# Scenario 2: Use an accessible URL.
url = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4'
img = io.BytesIO(urlopen(url).read())
split_video_parts_request = SplitVideoPartsAdvanceRequest()
split_video_parts_request.video_url_object = img
runtime = RuntimeOptions()
try:
# Initialize the client.
client = Client(config)
response = client.split_video_parts_advance(split_video_parts_request, runtime)
# Get the entire response.
print(response.body)
except Exception as error:
# Get the full error message.
print(error)
# Get a specific field.
print(error.code)
<?php
// Install dependencies.
// Minimum SDK version: 1.0.9 or later for alibabacloud/videorecog-20200320.
// You can find the latest SDK version in this repository: https://packagist.org/packages/alibabacloud/videorecog-20200320
// composer require alibabacloud/videorecog-20200320
use AlibabaCloud\SDK\Videorecog\V20200320\Videorecog;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Videorecog\V20200320\Models\SplitVideoPartsAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;
class SplitVideoPartsAdvance {
/**
* Initialize the client by using an access key ID and an access key secret.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Videorecog Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initializes the configuration object Darabonba\OpenApi\Models\Config.
// This object stores configurations such as accessKeyId, accessKeySecret, and endpoint.
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// The service endpoint.
$config->endpoint = "videorecog.cn-shanghai.aliyuncs.com";
return new Videorecog($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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/SplitVideoParts1.mp4', 'rb');
//$stream = new Stream($file);
// Scenario 2: Use an accessible URL.
$file = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4', 'rb');
$stream = new Stream($file);
$splitVideoPartsAdvanceRequest = new SplitVideoPartsAdvanceRequest([
"videoUrlObject" => $stream
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->splitVideoPartsAdvance($splitVideoPartsAdvanceRequest, $runtime);
// Get the entire 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 arguments and does not need to be modified.
SplitVideoPartsAdvance::main(array_slice($argv, 1));
// Install dependencies.
// npm install @alicloud/videorecog20200320
// Minimum SDK version: 3.0.6 or later for @alicloud/videorecog20200320.
// You can find the latest SDK version in this repository: https://npmjs.com/package/@alicloud/videorecog20200320
const VideorecogClient = require('@alicloud/videorecog20200320');
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 access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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 = `videorecog.cn-shanghai.aliyuncs.com`;
const client = new VideorecogClient.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 splitVideoPartsAdvanceRequest = new VideorecogClient.SplitVideoPartsRequest();
// Scenario 1: Use a local file.
// const fileStream = fs.createReadStream('/tmp/SplitVideoParts1.mp4');
// splitVideoPartsAdvanceRequest.videoUrlObject = fileStream;
// Scenario 2: Use an accessible URL.
const url = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4");
const httpClient = (url.protocol == "https:") ? https : http;
splitVideoPartsAdvanceRequest.videoUrlObject = await getResponse(httpClient, url);
let runtime = new TeaUtil.RuntimeOptions({ });
client.splitVideoPartsAdvance(splitVideoPartsAdvanceRequest, runtime)
.then(function(splitVideoPartsResponse) {
// Get the entire response.
console.log(splitVideoPartsResponse);
// Get a specific field.
console.log(splitVideoPartsResponse.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);
}
}();
// Import dependencies.
// Minimum SDK version: 2.0.8 or later for github.com/alibabacloud-go/videorecog-20200320/v2.
// You can find the latest SDK version in this repository: github.com/alibabacloud-go/videorecog-20200320/v2
// go get github.com/alibabacloud-go/videorecog-20200320/v2
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"
videorecog20200320 "github.com/alibabacloud-go/videorecog-20200320/v2/client"
"net/http"
)
func main() {
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the 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 stores configurations such as AccessKeyId, AccessKeySecret, and Endpoint.
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret)
}
// The service endpoint.
config.Endpoint = tea.String("videorecog.cn-shanghai.aliyuncs.com")
client, err := videorecog20200320.NewClient(config)
if err != nil {
fmt.Println(err.Error())
}
// Scenario 1: Use a local file.
//file, err := os.Open("/tmp/SplitVideoParts1.mp4")
//if err != nil {
// fmt.Println("can not open file", err)
//}
//splitVideoPartsAdvanceRequest := &videorecog20200320.SplitVideoPartsAdvanceRequest{
// VideoUrlObject: file,
//}
// Scenario 2: Use an accessible URL.
httpClient := http.Client{}
file1, _ := httpClient.Get("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4")
splitVideoPartsAdvanceRequest := &videorecog20200320.SplitVideoPartsAdvanceRequest{
VideoUrlObject: file1.Body,
}
runtime := &util.RuntimeOptions{}
splitVideoPartsResponse, _err := client.SplitVideoPartsAdvance(splitVideoPartsAdvanceRequest, runtime)
if _err != nil {
fmt.Println(_err.Error())
} else {
// Get the entire response.
fmt.Println(splitVideoPartsResponse)
// Get a specific field.
fmt.Println(splitVideoPartsResponse.Body.Data)
}
}
// Install the dependency package.
// dotnet add package AlibabaCloud.SDK.Videorecog20200320
// Minimum SDK version: 2.0.7 or later for AlibabaCloud.SDK.Videorecog20200320.
// You can find the latest SDK version in this repository: https://nuget.org/packages/AlibabaCloud.SDK.Videorecog20200320
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.Videorecog20200320.Models;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* Initialize the client by using an access key ID and an access key secret.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static AlibabaCloud.SDK.Videorecog20200320.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 = "videorecog.cn-shanghai.aliyuncs.com";
return new AlibabaCloud.SDK.Videorecog20200320.Client(config);
}
public static void Main(string[] args)
{
// To create an access key ID and an access key secret, see https://help.aliyun.com/document_detail/175144.html.
// If you use an access key of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the access key ID and access key secret from environment variables. You must configure the environment variables before running the sample code.
AlibabaCloud.SDK.Videorecog20200320.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
AlibabaCloud.SDK.Videorecog20200320.Models.SplitVideoPartsAdvanceRequest splitVideoPartsAdvanceRequest = new AlibabaCloud.SDK.Videorecog20200320.Models.SplitVideoPartsAdvanceRequest
();
// Scenario 1: Use a local file.
//System.IO.StreamReader file = new System.IO.StreamReader(@"/tmp/SplitVideoParts1.mp4");
//splitVideoPartsAdvanceRequest.VideoUrlObject = file.BaseStream;
// Scenario 2: Use an accessible URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/SplitVideoParts/SplitVideoParts1.mp4");
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
splitVideoPartsAdvanceRequest.VideoUrlObject = stream;
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Videorecog20200320.Models.SplitVideoPartsResponse splitVideoPartsResponse = client.SplitVideoPartsAdvance(splitVideoPartsAdvanceRequest, runtime);
// Get the entire response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(splitVideoPartsResponse.Body));
// Get a specific field.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(splitVideoPartsResponse.Body.Data));
}
catch (TeaException error)
{
// Prints the error for debugging.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Prints the error for debugging.
Console.WriteLine(error.Message);
}
}
}
}