简介
本文档提供关于转码模板接口的 API 概览和 SDK 示例代码。
新增转码模板
功能说明
用于新增转码模板。
方法原型
public Guzzle\\Service\\Resource\\Model createMediaTranscodeTemplate(array $args = array());
请求示例
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的 region 可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', //协议头部,默认为 http'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {// https://cloud.tencent.com/document/product/436/54037 新增转码模板$result = $cosClient->createMediaTranscodeTemplate(array('Bucket' => 'examplebucket-125000000', //存储桶名称,由 BucketName-Appid 组成,可以在 COS 控制台查看 https://console.cloud.tencent.com/cos5/bucket'Tag' => 'Transcode','Name' => 'Transcode-Template-Name','Container' => array('Format' => '','ClipConfig' => array('Duration' => '',),),'Video' => array('Codec' => '','Width' => '','Height' => '','Fps' => '','Remove' => '','Profile' => '','Bitrate' => '','Crf' => '','Gop' => '','Preset' => '','Bufsize' => '','Maxrate' => '','Pixfmt' => '','LongShortMode' => '','Rotate' => '',),'TimeInterval' => array('Start' => '','Duration' => '',),'Audio' => array('Codec' => '','Samplerate' => '','Bitrate' => '','Channels' => '','Remove' => '','KeepTwoTracks' => '','SwitchTrack' => '','SampleFormat' => '',),'TransConfig' => array('AdjDarMethod' => '','IsCheckReso' => '','ResoAdjMethod' => '','IsCheckVideoBitrate' => '','VideoBitrateAdjMethod' => '','IsCheckAudioBitrate' => '','AudioBitrateAdjMethod' => '','DeleteMetadata' => '','IsHdr2Sdr' => '','HlsEncrypt' => array('IsHlsEncrypt' => '','UriKey' => '',),),));// 请求成功print_r($result);} catch (\\Exception $e) {// 请求失败echo($e);}
参数说明
Request 中的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
Tag | Request | 模板类型:Transcode | String | 是 |
Name | Request | 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64 | String | 是 |
Container | Request | 容器格式 | Container | 是 |
Video | Request | 视频信息 | Container | 否 |
Audio | Request | 音频信息 | Container | 否 |
TransConfig | Request | 转码配置 | Container | 否 |
TimeInterval | Request | 时间区间 | Container | 否 |
AudioMix | Request | Container | 否 | |
AudioMixArray | Request | 混音参数,最多同时传2个 | Container 数组 | 否 |
说明:
不传 Video,相当于删除视频信息。不传 Audio,相当于删除音频信息。Video 和 Audio 不可以同时不传。
AudioMix 和 AudioMixArray 在 Audio.Remove 为 false 时生效。
AudioMixArray 是一个数组,每一个子项内容同 AudioMix。AudioMix 优先级更高,设置 AudioMix 时,AudioMixArray 无效。
Container 类型
Container
的具体数据描述如下:节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
Format | Request.Container | 封装格式,取值见下方的音频视频支持格式表 | String | 是 |
ClipConfig | Request.Container | 分片配置,当 format 为 hls 和 dash 时有效 | Container | 否 |
Container 类型 ClipConfig 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 是否必选 |
Duration | Request.Container.ClipConfig | 分片时长,默认5s | String | 否 |
设定 container,音频视频支持的格式如下表所示:
Container | Audio Codecs | Video Codecs |
mp4/hls/mkv | aac、mp3 | H.264、H.265、AV1 |
ts/flv/avi/mov | aac、mp3 | H.264 |
dash | aac | H.264 |
WebM | Vorbis、opus | VP8、VP9、AV1 |
aac | aac | 不支持 |
mp3 | mp3 | 不支持 |
flac | flac | 不支持 |
amr | amr | 不支持 |
adts | aac | 不支持 |
m4a | aac | 不支持 |
wav | pcm_s16le | 不支持 |
Container 类型
Video
的具体数据描述如下:节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
Codec | Request.Video | 编解码格式 H.264 H.265 VP8 VP9 AV1 | String | H.264 当 Format 为 WebM 时,为 VP8 | 否 |
Profile | Request.Video | 编码级别 仅H.264支持此参数 支持 baseline、main、high、auto 当 Pixfmt 为 auto 时,参数值将被设置为 auto baseline:适合移动设备,不限制 I 帧和 p 帧,不支持隔行扫描,没有切片数据分区,此profile下部分编码 level 受限。 main:适合标准分辨率设备 high:适合高分辨率设备,支持 8*8 的 block auto:与源视频保持一致,可能为 baseline、main、high、high10、high422、high444 | String | high | 否 |
Bitrate | Request.Video | 视频输出文件的码率 值范围:[10, 50000], 单位:Kbps 设置为 auto 表示自适应码率 | String | 无 | 否 |
Width | Request.Video | 宽 值范围:[128, 4096] 单位:px 若只设置 Width 时,按照视频原始比例计算 Height 必须为偶数 | String | 视频原始宽度 | 否 |
Fps | Request.Video | 帧率 值范围:(0, 60] 单位:fps | String | 无 | 否 |
Preset | Request.Video | 视频算法器预置 H.264 支持该参数,取值 veryfast、fast、medium、slow、slower VP8 支持该参数,取值 good、realtime AV1 支持该参数,取值 universal、medium H.265 和 VP9 不支持该参数 | String | 当 Codec 为 H.264 时,为 medium 当 Codec 为 VP8 时,为 good | 否 |
Height | Request.Video | 高 值范围:[128, 4096] 单位:px 若只设置 Height 时,按照视频原始比例计算 Width 必须为偶数 | String | 视频原始高度 | 否 |
Remove | Request.Video | 是否删除视频流,取值 true 或 false | String | false | 否 |
Crf | Request.Video | 码率-质量控制因子 值范围:(0, 51] 如果设置了 Crf,则 Bitrate 的设置失效 当 Bitrate 为空时,默认为25 | String | 无 | 否 |
Gop | Request.Video | 关键帧间最大帧数,值范围:[1, 100000] | String | 无 | 否 |
Bufsize | Request.Video | 缓冲区大小 值范围:[1000, 128000] 单位:Kb Codec 为 VP8/VP9时不支持此参数 | String | 无 | 否 |
Maxrate | Request.Video | 视频码率峰值 值范围:[10, 50000] 单位:Kbps Codec 为 VP8/VP9时不支持此参数 | String | 无 | 否 |
Pixfmt | Request.Video | 视频颜色格式 H.264支持:yuv420p、yuv422p、yuv444p、yuvj420p、yuvj422p、yuvj444p、auto H.265支持:yuv420p、yuv420p10le、auto Codec 为 VP8/VP9/AV1时不支持此参数 | String | 无 | 否 |
LongShortMode | Request.Video | 长短边自适应 取值 true 或 false。 Codec 为 VP8/VP9/AV1时不支持此参数。 | String | false | 否 |
Rotate | Request.Video | 旋转角度 值范围:[0, 360) 单位:度 | String | 无 | 否 |
Roi | Request.Video | Roi 强度 取值为 none、low、medium、high Codec 为 VP8/VP9时不支持此参数 | String | none | 否 |
Crop | Request.Video | 自由裁剪 自定义裁切: width:height:left:top。示例:1280:800:0:140 width和height的值需要大于0,left 和 top 的值需要大于等于0 Codec 为 H.265/AV1时不支持此参数。 开启自适应编码时, 不支持此参数。 开启 roi 时, 不支持此参数。 | String | 无 | 否 |
Interlaced | Request.Video | 开启隔行扫描 false/true Codec 为 H.265/AV1时不支持此参数。 开启自适应码率时, 不支持此参数。 开启 roi 时, 不支持此参数。 | String | false | 否 |
Container 类型
Audio
的具体数据描述如下:节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
Codec | Request.Audio | 编解码格式,取值 aac、mp3、flac、amr、Vorbis、opus、pcm_s16le | String | aac 当 format 为 WebM 时,为 Vorbis 当 format 为 wav 时,为 pcm_s16le | 否 |
Samplerate | Request.Audio | 采样率 单位:Hz 可选 8000、11025、12000、16000、22050、24000、32000、44100、48000、88200、96000 不同的封装,mp3 支持不同的采样率,如下表所示 当 Codec 设置为 amr 时,只支持8000 当 Codec 设置为 opus 时,支持8000,16000,24000,48000 | String | 44100 当 Codec 为 opus 时,默认值为48000 | 否 |
Bitrate | Request.Audio | 原始音频码率 单位:Kbps 值范围:[8,1000] | String | 无 | 否 |
Channels | Request.Audio | 声道数 当 Codec 设置为 aac/flac,支持1、2、4、5、6、8 当 Codec 设置为 mp3/opus 时,支持1、2 当 Codec 设置为 Vorbis 时,只支持2 当 Codec 设置为 amr,只支持1 当 Codec 设置为 pcm_s16le 时,只支持1、2 当封装格式为 dash 时,不支持8 | String | 无 | 否 |
Remove | Request.Audio | 是否删除源音频流,取值 true、false | String | false | 否 |
SampleFormat | Request.Audio | 采样位宽 当 Codec 设置为 aac,支持 fltp 当 Codec 设置为 mp3,支持 fltp、s16p、s32p 当 Codec 设置为 flac,支持s16、s32、s16p、s32p 当 Codec 设置为 amr,支持s16、s16p 当 Codec 设置为 opus,支持s16 当 Codec 设置为 pcm_s16le,支持s16 当 Codec 设置为 Vorbis,支持 fltp 当 Video.Codec 为 H.265时,此参数无效 | String | 无 | 否 |
说明:
Y 表示支持这种采样率,N 表示不支持。
Audio.Codec 采样率支持情况,如下表所示:
Audio.Codec | aac | amr | flac | opus | Vorbis | pcm_s16le | mp3 |
8000 | Y | Y | Y | Y | Y | Y | 封装不同,支持不同 |
| 11025 | Y | N | Y | N | Y | Y |
| 12000 | Y | N | Y | N | Y | Y |
| 16000 | Y | N | Y | Y | Y | Y |
| 22050 | Y | N | Y | N | Y | Y |
| 24000 | Y | N | Y | Y | Y | Y |
| 32000 | Y | N | Y | N | Y | Y |
| 44100 | Y | N | Y | N | Y | Y |
| 48000 | Y | N | Y | Y | Y | Y |
| 88200 | Y | N | Y | N | Y | Y |
| 96000 | Y | N | Y | N | Y | Y |
当 Audio.Codec 为 mp3时,Container.Format 的采样率兼容情况如下所示:
封装格式/音频采样率 | 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000 | 88200 | 96000 |
flv | N | N | N | N | Y | N | N | Y | N | N | N |
mp4 | N | N | N | Y | Y | Y | Y | Y | Y | N | N |
hls/ts/mp3/mkv/avi/mov | Y | Y | Y | Y | Y | Y | Y | Y | Y | N | N |
Container 类型
TransConfig
的具体数据描述如下:节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
AdjDarMethod | Request.TransConfig | 分辨率调整方式 取值 scale、crop、pad、none 当输出视频的宽高比与原视频不等时,根据此参数做分辨率的相应调整 | String | none | 否 |
IsCheckReso | Request.TransConfig | 是否检查分辨率,取值 true、false 当为 false 时,按照配置参数转码 | String | false | 否 |
ResoAdjMethod | Request.TransConfig | 分辨率调整方式 当 IsCheckReso 为 true 时生效,取值0、1 0 表示使用原视频分辨率 1 表示返回转码失败 | String | 0 | 否 |
IsCheckVideoBitrate | Request.TransConfig | 是否检查视频码率,取值 true、false 当为 false 时,按照配置参数转码 | String | false | 否 |
VideoBitrateAdjMethod | Request.TransConfig | 视频码率调整方式 IsCheckVideoBitrate 为 true 时生效,取值0、1 当输出视频码率大于原视频码率时,0表示使用原视频码率;1表示返回转码失败 | String | 0 | 否 |
IsCheckAudioBitrate | Request.TransConfig | 是否检查音频码率,取值 true、false 当为 false 时,按照配置参数转码 | String | false | 否 |
AudioBitrateAdjMethod | Request.TransConfig | 音频码率调整方式 IsCheckAudioBitrate 为 true 时生效,取值0、1 当输出音频码率大于原音频码率时,0表示使用原音频码率;1表示返回转码失败 | String | 0 | 否 |
IsCheckVideoFps | Request.TransConfig | 是否检查视频帧率,取值 true、false 当为 false 时,按照配置参数转码 | String | false | 否 |
VideoFpsAdjMethod | Request.TransConfig | 视频帧率调整方式 IsCheckVideoFps 为 true 时生效,取值0、1 当输出视频帧率大于原视频帧率时,0表示使用原视频帧率;1表示返回转码失败 | String | 0 | 否 |
DeleteMetadata | Request.TransConfig | 是否删除文件中的 MetaData 信息,取值 true、false | String | false | 否 |
IsHdr2Sdr | Request.TransConfig | 是否开启 HDR 转 SDR,取值 true、false | String | false | 否 |
TranscodeIndex | Request.TransConfig | 指定处理的流编号,对应媒体信息中的 Response.MediaInfo.Stream.Video.Index 和 Response.MediaInfo.Stream.Audio.Index,详见 获取媒体信息接口 | String | 无 | 否 |
HlsEncrypt | Request.TransConfig | hls 加密配置 | Container | 无 | 否 |
AdjDarMethod 参数图示:


Container 类型 HlsEncrypt 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
IsHlsEncrypt | Request.TransConfig.HlsEncrypt | 是否开启 HLS 加密,取值 true、false 当 Container.Format 为 hls 时支持加密 | String | false | 否 |
UriKey | Request.TransConfig.HlsEncrypt | HLS 加密的 key 当 IsHlsEncrypt 为 true 时,该参数才有意义 | String | 无 | 否 |
Container 类型
TimeInterval
的具体数据描述如下:节点名称(关键字) | 父节点 | 描述 | 类型 | 默认值 | 是否必选 |
Start | Request.TimeInterval | 开始时间 [0 视频时长] 单位为秒 支持 float 格式,执行精度精确到毫秒 | String | 0 | 否 |
Duration | Request.TimeInterval | 持续时间 [0 视频时长] 单位为秒 支持 float 格式,执行精度精确到毫秒 | String | 视频原始时长 | 否 |
返回结果示例
GuzzleHttp\\Command\\Result Object([Body] => GuzzleHttp\\Psr7\\Stream Object([stream:GuzzleHttp\\Psr7\\Stream:private] => Resource id #88[size:GuzzleHttp\\Psr7\\Stream:private] =>[seekable:GuzzleHttp\\Psr7\\Stream:private] => 1[readable:GuzzleHttp\\Psr7\\Stream:private] => 1[writable:GuzzleHttp\\Psr7\\Stream:private] => 1[uri:GuzzleHttp\\Psr7\\Stream:private] => php://temp[customMetadata:GuzzleHttp\\Psr7\\Stream:private] => Array())[RequestId] => NjJhODM3OTRfZmNjYTNiMCUOACNOISTY3ODQ=[ContentType] => application/xml[ContentLength] => 2021[Bucket] => examplebucket-125000000[Location] => examplebucket-125000000.ci.ap-guangzhou.myqcloud.com/template[Response] => Array([RequestId] => NjJhODM3OTRfZmNjYTNiMCUOACNOISTY3ODQ=[Template] => Array([TemplateId] => t102b2c576bdzx8c90z8c09z8c0203a4c61a[Name] => Transcode-Template-Name[State] => Normal[Tag] => Transcode[TransTpl] => Array([Container] => Array([Format] => hls[ClipConfig] => Array([Duration] => 5))[Video] => Array([Codec] => H.264[Profile] => high[Bitrate] => 1000[Crf] => 1[Width] => 1280[Height] => 720[Fps] => 30[Gop] => 1[Preset] => medium[Bufsize] => 1000[Maxrate] => 30[Remove] => false[Pixfmt] => yuv420p[LongShortMode] => true[Rotate] => 0)[Audio] => Array([Codec] => aac[Profile] =>[Samplerate] => 44100[Bitrate] => 128[Channels] => 4[Remove] => false[KeepTwoTracks] => false[SwitchTrack] => false[SampleFormat] => fltp)[TransConfig] => Array([IsCheckReso] => false[IsCheckVideoBitrate] => true[IsCheckAudioBitrate] => false[ResoAdjMethod] => 1[VideoBitrateAdjMethod] => 0[AudioBitrateAdjMethod] => 0[AdjDarMethod] => scale[IsStreamCopy] => false[DeleteMetadata] => false[IsHdr2Sdr] => false[HlsEncrypt] => Array([IsHlsEncrypt] => false[UriKey] => https://www.xxx.com/xxx))[TimeInterval] => Array([Start] => 0[Duration] => 60))[CreateTime] => 2022-06-14T15:24:04+0800[UpdateTime] => 2022-06-14T15:24:04+0800[BucketId] => examplebucket-125000000[Category] => Custom)))
更新转码模板
功能说明
用于更新转码模板。
方法原型
public Guzzle\\Service\\Resource\\Model updateMediaTranscodeTemplate(array $args = array());
请求示例
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的 region 可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', //协议头部,默认为 http'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {// https://cloud.tencent.com/document/product/436/54040 更新转码模板$result = $cosClient->updateMediaTranscodeTemplate(array('Bucket' => 'examplebucket-125000000', //存储桶名称,由 BucketName-Appid 组成,可以在 COS 控制台查看 https://console.cloud.tencent.com/cos5/bucket'Key' => '', // TemplateId'Tag' => 'Transcode','Name' => 'Transcode-Template-Name','Container' => array('Format' => '','ClipConfig' => array('Duration' => '',),),'Video' => array('Codec' => '','Width' => '','Height' => '','Fps' => '','Remove' => '','Profile' => '','Bitrate' => '','Crf' => '','Gop' => '','Preset' => '','Bufsize' => '','Maxrate' => '','Pixfmt' => '','LongShortMode' => '','Rotate' => '',),'TimeInterval' => array('Start' => '','Duration' => '',),'Audio' => array('Codec' => '','Samplerate' => '','Bitrate' => '','Channels' => '','Remove' => '','KeepTwoTracks' => '','SwitchTrack' => '','SampleFormat' => '',),'TransConfig' => array('AdjDarMethod' => '','IsCheckReso' => '','ResoAdjMethod' => '','IsCheckVideoBitrate' => '','VideoBitrateAdjMethod' => '','IsCheckAudioBitrate' => '','AudioBitrateAdjMethod' => '','DeleteMetadata' => '','IsHdr2Sdr' => '','HlsEncrypt' => array('IsHlsEncrypt' => '','UriKey' => '',),),));// 请求成功print_r($result);} catch (\\Exception $e) {// 请求失败echo($e);}
参数说明
Request 中的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 |
Key | 无 | 模版 ID | String | 是 |
Request | 无 | Container | 是 |
返回结果示例
GuzzleHttp\\Command\\Result Object([Body] => GuzzleHttp\\Psr7\\Stream Object([stream:GuzzleHttp\\Psr7\\Stream:private] => Resource id #88[size:GuzzleHttp\\Psr7\\Stream:private] =>[seekable:GuzzleHttp\\Psr7\\Stream:private] => 1[readable:GuzzleHttp\\Psr7\\Stream:private] => 1[writable:GuzzleHttp\\Psr7\\Stream:private] => 1[uri:GuzzleHttp\\Psr7\\Stream:private] => php://temp[customMetadata:GuzzleHttp\\Psr7\\Stream:private] => Array())[RequestId] => NjJhODNhNDRfNzgwYzdkNjZXIUCIOZCIOxMWFjNTg=[ContentType] => application/xml[ContentLength] => 2023[Key] => t102b2c576bd09e61as98d90a8d90a4c61a[Bucket] => examplebucket-125000000[Location] => examplebucket-125000000.ci.ap-guangzhou.myqcloud.com/template/t102b2c576bdf144d09e61402203a4c61a[Response] => Array([RequestId] => NjJhODNhNDRfNzgwYzdkNjZXIUCIOZCIOxMWFjNTg=[Template] => Array([TemplateId] => t102b2c576bd09e61as98d90a8d90a4c61a[Name] => Transcode-Template-Name[State] => Normal[Tag] => Transcode[TransTpl] => Array([Container] => Array([Format] => hls[ClipConfig] => Array([Duration] => 5))[Video] => Array([Codec] => H.264[Profile] => high[Bitrate] => 1000[Crf] => 1[Width] => 1280[Height] => 720[Fps] => 30[Gop] => 1[Preset] => medium[Bufsize] => 1000[Maxrate] => 30[Remove] => false[Pixfmt] => yuv420p[LongShortMode] => true[Rotate] => 0)[Audio] => Array([Codec] => aac[Profile] =>[Samplerate] => 44100[Bitrate] => 128[Channels] => 4[Remove] => false[KeepTwoTracks] => false[SwitchTrack] => false[SampleFormat] => fltp)[TransConfig] => Array([IsCheckReso] => false[IsCheckVideoBitrate] => true[IsCheckAudioBitrate] => false[ResoAdjMethod] => 1[VideoBitrateAdjMethod] => 0[AudioBitrateAdjMethod] => 0[AdjDarMethod] => scale[IsStreamCopy] => false[DeleteMetadata] => false[IsHdr2Sdr] => false[HlsEncrypt] => Array([IsHlsEncrypt] => false[UriKey] => https://www.xxx.com/xxx))[TimeInterval] => Array([Start] => 0[Duration] => 60))[CreateTime] => 2022-06-14T15:24:04+0800[UpdateTime] => 2022-06-14T15:35:32+0800[BucketId] => examplebucket-125000000[Category] => Custom)))