You need to enable JavaScript to run this app.
导航
媒资上传
最近更新时间:2025.05.13 19:35:44首次发布时间:2021.02.23 10:42:38
我的收藏
有用
有用
无用
无用

本文为您介绍如何使用视频点播服务端 PHP SDK 将音频、视频、图片等媒资文件上传至视频点播服务。

费用说明

媒资上传到视频点播中会产生存储费用,具体参见媒资存储计费

前提条件

上传音视频

直接上传本地文件

视频点播服务端 SDK 封装了 ApplyUploadInfo - 获取上传地址和凭证CommitUploadInfo - 确认上传接口以及上传逻辑,您只需简单配置即可进行上传。

说明

  • 完整的上传流程请见服务端上传
  • 上传任务成功提交后,您可通过媒资上传完成事件通知获取任务结果。配置方式请见事件通知概述
  • 上传文件时必须携带文件后缀。例如,如需上传 MP4 文件,携带 .mp4.MP4
  • 以下示例为 2022-01-01 版本的 ApplyUploadInfo 和 CommitUploadInfo 接口。若您使用 2020-08-01 版本,示例代码请见历史版本
<?php
require('../../vendor/autoload.php');

use Volc\Service\Vod\Models\Request\VodUploadMediaRequest;
use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse;
use Volc\Service\Vod\Upload\Functions;
use Volc\Service\Vod\Upload\VodUpload;
use Volc\Service\Vod\Upload\OptionInfo;
use Volc\Service\Vod\Upload\Template;

// Create a VOD instance in the specified region.
// $client = Volc\Service\Vod\Vod::getInstance('cn-north-1');
$client = VodUpload::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$space = 'your space';
$filePath = "file path";

$functions = new Functions();
$functions->addGetMetaFunc();
$functions->addSnapshotTimeFunc(2.1);
$impTemplate = new Template();
$impTemplate->TemplateIds = ["imp template id"];
$impTemplate->TemplateType = "imp";
$transcodeTemplate = new Template();
$transcodeTemplate->TemplateIds = ["transcode template id"];
$transcodeTemplate->TemplateType = "transcode";
$functions->addStartWorkflowTemplateFunc([$impTemplate, $transcodeTemplate]);
$optionInfo = new OptionInfo();
$optionInfo->IsHlsIndexOnly = true;
$functions->addOptionInfoFunc($optionInfo);
$functions = $functions->getFunctionsString();

$request = new VodUploadMediaRequest();
$request->setSpaceName($space);
$request->setFilePath($filePath);
$request->setFunctions($functions);
$request->setCallbackArgs("my callback");
$request->setFileName("hello/vod.mp4");
$request->setStorageClass(1);
$request->setUploadHostPrefer("");

$response = new VodCommitUploadInfoResponse();
try {
    $response = $client->uploadMedia($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
    echo $response->getResponseMetadata()->getError()->serializeToJsonString(), "\n";
}
echo $response->serializeToJsonString();
echo "\n";

if ($response->getResult() != null) {
    echo $response->getResult()->getData()->getVid(), "\n";
    echo $response->getResult()->getData()->getPosterUri(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n";
}

URL 批量拉取上传

视频点播服务端 SDK 封装了 URL 批量拉取上传 - UploadMediaByUrl 接口,您只需简单配置即可进行上传。完整的上传流程请见服务端上传

说明

  • 本接口主要适用于文件没有存储在本地服务器或终端,需要通过公网访问的 URL 地址上传的场景。源文件 URL 支持 HTTP 和 HTTPS。
  • 本接口为异步上传接口。上传任务成功提交后,系统会生成异步执行的任务,排队执行,不保证时效性。
  • 本接口的请求参数和返回参数说明详见 UploadMediaByUrl
  • 上传任务成功提交后,可通过以下方式获取任务结果:
<?php
require('../../vendor/autoload.php');

// Create a VOD instance in the specified region.
// $client = Vod::getInstance('cn-north-1');
$client = Volc\Service\Vod\Vod::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$request = new Volc\Service\Vod\Models\Request\VodUrlUploadRequest();
$request->setSpaceName("your SpaceName");

$urlSet = new Volc\Service\Vod\Models\Business\VodUrlUploadURLSet();
$urlSet->setSourceUrl("");
$urlSet->setStorageClass(1);
$urlSet->setFileExtension(".mp4");
$urlSet->setCallbackArgs("");
$customHeaders = ['your header key' => "your header value"]; // 自定义 Header,业务希望访问源视频 URL 携带的 Header(例如User-Agent)可以通过该参数传入,非必须字段
$urlSet->setCustomURLHeaders($customHeaders);
$request->setURLSets([$urlSet]);


$response = new Volc\Service\Vod\Models\Response\VodUrlUploadResponse();
try {
    $response = $client->uploadMediaByUrl($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response != null && $response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
    echo $response->getResponseMetadata()->getError()->serializeToJsonString(), "\n";
} else {
    echo $response->serializeToJsonString(), "\n";
}

上传素材

视频点播服务端 SDK 封装了 ApplyUploadInfo - 获取上传地址和凭证CommitUploadInfo - 确认上传接口以及上传逻辑,您只需简单配置即可进行上传。

说明

  • 完整的上传流程请见服务端上传
  • 上传任务成功提交后,您可通过素材上传完成事件通知获取任务结果。配置方式请见事件通知概述
  • 上传文件时必须携带文件后缀。例如,如需上传 MP4 文件,携带 .mp4.MP4
  • 以下示例为 2022-01-01 版本的 ApplyUploadInfo 和 CommitUploadInfo 接口。若您使用 2020-08-01 版本,示例代码请见历史版本
<?php
require('../../vendor/autoload.php');

use Volc\Service\Vod\Models\Request\VodUploadMaterialRequest;
use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse;
use Volc\Service\Vod\Upload\Functions;
use Volc\Service\Vod\Upload\VodUpload;
use Volc\Service\Vod\Upload\OptionInfo;

// Create a VOD instance in the specified region.
// $client = Volc\Service\Vod\Vod::getInstance('cn-north-1');
$client = VodUpload::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$space = 'your space';
$filePath = "file path";

//音视频素材上传
$functions = new Functions();
$functions->addGetMetaFunc();
$functions->addSnapshotTimeFunc(2.1);

$optionInfo = new OptionInfo();
$optionInfo->Title = '素材测试视频';
$optionInfo->Tags = 'test';
$optionInfo->Description = '素材测试,视频文件';
$optionInfo->Category = 'video';
$optionInfo->RecordType = 2;
$optionInfo->Format = 'mp4';
$functions->addOptionInfoFunc($optionInfo);

$functions = $functions->getFunctionsString();

$request = new VodUploadMaterialRequest();
$request->setSpaceName($space);
$request->setFilePath($filePath);
$request->setFunctions($functions);
$request->setFileType("media");

$request->setCallbackArgs("my callback");
$request->setUploadHostPrefer("");

$response = new VodCommitUploadInfoResponse();
try {
    $response = $client->uploadMaterial($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
    echo $response->getResponseMetadata()->getError(), "\n";
}
echo $response->serializeToJsonString();
echo "\n";

if ($response->getResult() != null) {
    echo $response->getResult()->getData()->getMid(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n";
}

////图片素材上传
//$functions = new Functions();
//$functions->addGetMetaFunc();
//
//$optionInfo = new OptionInfo();
//$optionInfo->Title = '素材测试图片';
//$optionInfo->Tags = 'test';
//$optionInfo->Description = '素材测试,图片文件';
//$optionInfo->Category = 'image';
//$optionInfo->RecordType = 2;
//$optionInfo->Format = 'jpg';
//$functions->addOptionInfoFunc($optionInfo);
//
//$functions = $functions->getFunctionsString();
//
//$request = new VodUploadMaterialRequest();
//$request->setSpaceName($space);
//$request->setFilePath($filePath);
//$request->setFunctions($functions);
//$request->setFileType("image");
//$request->setFileName("hello/vod/image");
//
//$request->setCallbackArgs("my callback");
//
//$response = new VodCommitUploadInfoResponse();
//try {
//    $response = $client->uploadMaterial($request);
//} catch (Exception $e) {
//    echo $e, "\n";
//} catch (Throwable $e) {
//    echo $e, "\n";
//}
//if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
//    echo $response->getResponseMetadata()->getError(), "\n";
//}
//echo $response->serializeToJsonString();
//echo "\n";
//
//if ($response->getResult() != null) {
//    echo $response->getResult()->getData()->getMid(), "\n";
//    echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n";
//    echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n";
//}

////字幕素材上传
//$functions = new Functions();
//$functions->addGetMetaFunc();
//
//$optionInfo = new OptionInfo();
//$optionInfo->Title = '素材测试字幕';
//$optionInfo->Tags = 'test';
//$optionInfo->Description = '素材测试,字幕文件';
//$optionInfo->Category = 'subtitle';
//$optionInfo->RecordType = 2;
//$optionInfo->Format = 'vtt';
//$functions->addOptionInfoFunc($optionInfo);
//
//$functions = $functions->getFunctionsString();
//
//$request = new VodUploadMaterialRequest();
//$request->setSpaceName($space);
//$request->setFilePath($filePath);
//$request->setFunctions($functions);
//$request->setFileType("object");
//$request->setFileName("hello/vod/object");
//
//$request->setCallbackArgs("my callback");
//
//$response = new VodCommitUploadInfoResponse();
//try {
//    $response = $client->uploadMaterial($request);
//} catch (Exception $e) {
//    echo $e, "\n";
//} catch (Throwable $e) {
//    echo $e, "\n";
//}
//if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
//    echo $response->getResponseMetadata()->getError(), "\n";
//}
//echo $response->serializeToJsonString();
//echo "\n";
//
//if ($response->getResult() != null) {
//    echo $response->getResult()->getData()->getMid(), "\n";
//    echo $response->getResult()->getData()->getSourceInfo()->getSize(), "\n";
//}

后续操作

查看上传结果

您可以通过配置上传事件通知及时获取上传的进展和状态,详细介绍请见上传事件通知

上传后自动转码

您可以通过工作流实现上传后自动转码,详细介绍请见工作流

发布音视频

音视频资源上传至视频点播服务之后,默认为未发布状态,此时无法获取到播放地址。因此在音视频播放前,您需要先修改音视频状态为已发布。具体操作请参见修改音视频发布状态

常见问题

我在上传过程中通过 FileName 参数设置了文件名称,但上传后控制台显示"未命名",为什么没有显示我设置的文件名称?

这是因为在视频点播服务中,FileName 参数实际上指的是文件路径(即媒资在存储桶中的唯一标识和存储位置),而不是用户可见的文件名称。如需设置控制台显示的文件名称,您需要通过上传功能函数设置 FileTitle 参数。详见上传功能函数说明

RecordType、FileType、Category 这三个参数的区别及如何设置?

参数

说明

FileType

  • 作用:在 ApplyUploadInfo 接口中指定文件类型,用于分配不同的上传域名。
  • 取值
    • media:(默认)音视频文件(如 MP4、MP3)。
    • image:图片文件(如 JPG、PNG)。
    • object:其他类型文件(如字幕、字体)。

RecordType

  • 作用:在 CommitUploadInfo 接口的上传功能函数中指定媒资类型,决定生成音视频或素材的元数据。
  • 取值
    • 1:(默认)音视频。
    • 2:素材(如图片、字幕、字体等)。

Category

  • 作用:当 RecordType2(素材)时,进一步细化素材类型。
  • 取值videoaudioimagedynamic_imgsubtitlefont 等。

通过正确组合这三个参数,可确保文件上传至正确的域名并生成匹配的元数据。示例:

  • 上传音视频(如 MP4)
    • FileType 设为 media 或留空。
    • RecordType 设为 1 或留空。
    • Category 无需设置(仅当 RecordType=2 时生效)。
  • 上传素材图片(如 JPG)
    • FileType 设为 image(图片使用图片上传域名)。
    • RecordType 设为 2(素材)。
    • Category 设为 image(进一步指定为图片素材)。
  • 上传字幕文件(如 SRT)
    • FileType 设为 object(非音视频/图片的文件类型)。
    • RecordType 设为 2(素材)。
    • Category 设为 subtitle(进一步指定为字幕素材)。

说明

通过服务端 SDK 上传素材时,接口已默认设置 RecordType 为 2,用户无需再设置。

如果我想在上传后对媒资进行分类,该如何操作?

视频点播当前仅支持手动分类。您可在视频点播控制台指定空间内的分类管理页面创建分类并获取分类 ID,具体请见分类管理

更多示例

签发临时上传 Token

如果您使用客户端上传 SDK 进行上传,您需要在应用服务端通过 AK 和 SK 在本地签出临时上传 Token,不依赖外网。如希望同时生成多个临时上传 Token,您可以循环调用生成方法。更多信息,请见客户端上传

<?php
require('../../vendor/autoload.php');

use Volc\Service\Vod\Vod;
use Volc\Service\Vod\Upload\UploadPolicy;

// Create a VOD instance in the specified region.
// $client = Volc\Service\Vod\Vod::getInstance('cn-north-1');
$client = Volc\Service\Vod\Vod::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$expire = 60*60; // 请求的签名有效期

echo "\nSTS2鉴权签名\n";
// 使用 $spaces 来限制限制允许上传的空间
//$spaces = [''];
// 使用 $keyPtn 来限制上传的FileName路径
//     如: "test/*" 表示上传的文件必须包含 "test/" 前缀
//$keyPtn = '';
// 使用 $uploadPolicy来设置上传策略
//$uploadPolicy = new UploadPolicy();
//$uploadPolicy->ContentTypeBlackList = ['content-type1','content-type2'];
//$uploadPolicy->ContentTypeWhiteList = ['content-type1','content-type2'];
//$uploadPolicy->FileSizeUpLimit = 'file size';
//$uploadPolicy->FileSizeBottomLimit = 'file size';
//$response = $client->getUploadVideoAuthWithExpiredTime($expire, $spaces, $keyPtn, $uploadPolicy);
$response = $client->getUploadVideoAuthWithExpiredTime($expire);
echo json_encode($response);

echo "\nSTS2鉴权签名,过期时间默认1小时\n";
$vid = "";
$response = $client->getUploadVideoAuth();
echo json_encode($response);

获取上传地址和凭证

接口请求参数和返回参数说明详见 ApplyUploadInfo

<?php
require('../../vendor/autoload.php');

// Create a VOD instance in the specified region.
// $client = Volc\Service\Vod\Vod::getInstance('cn-north-1');
$client = Volc\Service\Vod\Vod::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$request = new Volc\Service\Vod\Models\Request\VodApplyUploadInfoRequest();
$request->setSpaceName("your SpaceName");
$request->setSessionKey("your SessionKey");
$request->setFileSize(0);
$request->setFileType("your FileType");
$request->setFileName("your FileName");
$request->setStorageClass(1);
$request->setFileExtension("your FileExtension");
$request->setClientNetWorkMode("your ClientNetWorkMode");
$request->setClientIDCMode("your ClientIDCMode");
$request->setNeedFallback(false);
$request->setUploadHostPrefer("your UploadHostPrefer");

$response = new Volc\Service\Vod\Models\Response\VodApplyUploadInfoResponse();
try {
    $response = $client->applyUploadInfo($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response != null && $response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
    echo $response->getResponseMetadata()->getError()->serializeToJsonString(), "\n";
} else {
    echo $response->serializeToJsonString(), "\n";
}

查询 URL 批量上传任务状态

接口请求参数和返回参数详见 OpenAPI:查询 URL 批量上传任务状态

<?php
require('../vendor/autoload.php');

use Volc\Service\Vod\Models\Business\VodURLSet;
use Volc\Service\Vod\Models\Request\VodQueryUploadTaskInfoRequest;
use Volc\Service\Vod\Models\Response\VodQueryUploadTaskInfoResponse;
use Volc\Service\Vod\Vod;

// Create a VOD instance in the specified region.
// $client = Vod::getInstance('cn-north-1');
$client = Vod::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$jobId = 'url jobId';
$jobIds = [$jobId];


$request = new VodQueryUploadTaskInfoRequest();
$request->setJobIds(implode(",", $jobIds));

$response = new VodQueryUploadTaskInfoResponse();
try {
    $response = $client->queryUploadTaskInfo($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata()->getError() != null) {
    print_r($response->getResponseMetadata()->getError());
}
echo $response->serializeToJsonString();
echo "\n";

$mediaInfo = new VodURLSet();
$mediaInfo = $response->getResult()->getData()->getMediaInfoList()[0];
echo $mediaInfo->getRequestId(), "\n";
echo $mediaInfo->getState(), "\n";

历史版本

2020-08-01 上传音视频

接口请求参数和返回参数说明详见 ApplyUploadInfoCommitUploadInfo

<?php
require('../vendor/autoload.php');

use Volc\Service\Vod\Models\Request\VodUploadMediaRequest;
use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse;
use Volc\Service\Vod\Upload\Functions;
use Volc\Service\Vod\Upload\VodUpload;

// Create a VOD instance in the specified region.
// $client = Vod::getInstance('cn-north-1');
$client = VodUpload::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$space = 'your space';
$filePath = "file path";

Functions::addGetMetaFunc();
Functions::addSnapshotTimeFunc(2.1);
$functions = Functions::getFunctionsString();

$request = new VodUploadMediaRequest();
$request->setSpaceName($space);
$request->setFilePath($filePath);
$request->setFunctions($functions);
$request->setCallbackArgs("my callback");

$response = new VodCommitUploadInfoResponse();
try {
    $response = $client->uploadMedia($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata()->getError() != null) {
    print_r($response->getResponseMetadata()->getError());
}
echo $response->serializeToJsonString();
echo "\n";

echo $response->getResult()->getData()->getVid(), "\n";
echo $response->getResult()->getData()->getPosterUri(), "\n";
echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n";
echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n";

2020-08-01 上传素材

接口请求参数和返回参数说明详见 ApplyUploadInfoCommitUploadInfo

<?php
require('../../vendor/autoload.php');

use Volc\Service\Vod\Models\Request\VodUploadMaterialRequest;
use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse;
use Volc\Service\Vod\Upload\Functions;
use Volc\Service\Vod\Upload\VodUpload;
use Volc\Service\Vod\Upload\OptionInfo;

// Create a VOD instance in the specified region.
// $client = Vod::getInstance('cn-north-1');
$client = VodUpload::getInstance();

// Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408.
// The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
// During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
// $client->setAccessKey('your ak');
// $client->setSecretKey('your sk');

$space = 'your space';
$filePath = "file path";

//音视频素材上传
Functions::addGetMetaFunc();
Functions::addSnapshotTimeFunc(2.1);

$optionInfo = new OptionInfo();
$optionInfo->Title = '素材测试视频';
$optionInfo->Tags = 'test';
$optionInfo->Description = '素材测试,视频文件';
$optionInfo->Category = 'video';
$optionInfo->RecordType = 2;
$optionInfo->Format = 'mp4';
Functions::addOptionInfoFunc($optionInfo);

$functions = Functions::getFunctionsString();

$request = new VodUploadMaterialRequest();
$request->setSpaceName($space);
$request->setFilePath($filePath);
$request->setFunctions($functions);
$request->setFileType("media");

$request->setCallbackArgs("my callback");

$response = new VodCommitUploadInfoResponse();
try {
    $response = $client->uploadMaterial($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
    echo $response->getResponseMetadata()->getError(), "\n";
}
echo $response->serializeToJsonString();
echo "\n";

if ($response->getResult() != null) {
    echo $response->getResult()->getData()->getMid(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n";
}

//图片素材上传
Functions::addGetMetaFunc();

$optionInfo = new OptionInfo();
$optionInfo->Title = '素材测试图片';
$optionInfo->Tags = 'test';
$optionInfo->Description = '素材测试,图片文件';
$optionInfo->Category = 'image';
$optionInfo->RecordType = 2;
$optionInfo->Format = 'jpg';
Functions::addOptionInfoFunc($optionInfo);

$functions = Functions::getFunctionsString();

$request = new VodUploadMaterialRequest();
$request->setSpaceName($space);
$request->setFilePath($filePath);
$request->setFunctions($functions);
$request->setFileType("image");

$request->setCallbackArgs("my callback");

$response = new VodCommitUploadInfoResponse();
try {
    $response = $client->uploadMaterial($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
    echo $response->getResponseMetadata()->getError(), "\n";
}
echo $response->serializeToJsonString();
echo "\n";

if ($response->getResult() != null) {
    echo $response->getResult()->getData()->getMid(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n";
}

//字幕素材上传
Functions::addGetMetaFunc();

$optionInfo = new OptionInfo();
$optionInfo->Title = '素材测试字幕';
$optionInfo->Tags = 'test';
$optionInfo->Description = '素材测试,字幕文件';
$optionInfo->Category = 'subtitle';
$optionInfo->RecordType = 2;
$optionInfo->Format = 'vtt';
Functions::addOptionInfoFunc($optionInfo);

$functions = Functions::getFunctionsString();

$request = new VodUploadMaterialRequest();
$request->setSpaceName($space);
$request->setFilePath($filePath);
$request->setFunctions($functions);
$request->setFileType("object");

$request->setCallbackArgs("my callback");

$response = new VodCommitUploadInfoResponse();
try {
    $response = $client->uploadMaterial($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) {
    echo $response->getResponseMetadata()->getError(), "\n";
}
echo $response->serializeToJsonString();
echo "\n";

if ($response->getResult() != null) {
    echo $response->getResult()->getData()->getMid(), "\n";
    echo $response->getResult()->getData()->getSourceInfo()->getSize(), "\n";
}