功能描述
UpdateMediaTemplate 用于更新转码模板。
请求
请求示例
PUT /template/<TemplateId> HTTP/1.1
Host: <BucketName-APPID>.ci.<Region>.myqcloud.com
Date: <GMT Date>
Authorization: <Auth String>
Content-Length: <length>
Content-Type: application/xml
<body>
说明:Authorization: Auth String (详情请参见 请求签名 文档)。
请求头
此接口仅使用公共请求头部,详情请参见 公共请求头部 文档。
请求体
该请求操作的实现需要有如下请求体。
<Request>
<Tag>Transcode</Tag>
<Name>TemplateName</Name>
<Container>
<Format>mp4</Format>
</Container>
<Video>
<Codec>H.264</Codec>
<Profile>high</Profile>
<Bitrate>1000</Bitrate>
<Crf></Crf>
<Width>1280</Width>
<Height></Height>
<Fps>30</Fps>
<Gop></Gop>
<Preset>medium</Preset>
<ScanMode></ScanMode>
<Bufsize>0</Bufsize>
<Maxrate>0</Maxrate>
</Video>
<Audio>
<Codec>aac</Codec>
<Samplerate>44100</Samplerate>
<Bitrate>128</Bitrate>
<Channels>4</Channels>
</Audio>
<TransConfig>
<AdjDarMethod>scale</AdjDarMethod>
<IsCheckReso>false</IsCheckReso>
<ResoAdjMethod>1</ResoAdjMethod>
</TransConfig>
<TimeInterval>
<Start>0</Start>
<Duration>60</Duration>
</TimeInterval>
</Request>
具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 |
---|---|---|---|---|
Request | 无 | 保存请求的容器 | Container | 是 |
Container 类型 Request 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 | 限制 |
---|---|---|---|---|---|
Tag | Request | 模板类型:Transcode | String | 是 | 无 |
Name | Request | 模板名称 仅支持中文、英文、数字、_、-和* | String | 是 | 无 |
Container | Request | 容器格式 | Container | 是 | 无 |
Video | Request | 视频信息 | Container | 否 | 不传 Video,相当于删除视频信息 |
TimeInterval | Request | 时间区间 | Container | 否 | 无 |
Audio | Request | 音频信息 | Container | 否 | 不传 Audio,相当于删除音频信息 |
TransConfig | Request | 转码配置 | Container | 否 | 无 |
Container 类型 Container 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 |
---|---|---|---|---|
Format | Request.Container | 容器格式:mp4、flv、hls、ts、mp3、aac、WebM、dash | 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 |
ts/flv | aac、mp3 | H.264 |
aac | aac | 不支持 |
mp3 | mp3 | 不支持 |
flac | flac | 不支持 |
amr | amr | 不支持 |
WebM | Vorbis、opus | VP8、VP9 |
dash | aac | H.264 |
Container 类型 Video 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 | 默认值 | 限制 |
---|---|---|---|---|---|---|
Codec | Request.Video | 编解码格式 | String | 否 | H.264,当 format 为 WebM 时,为 VP8 | 1. H.264 2. H.265 3. VP8 4. VP9 |
Width | Request.Video | 宽 | String | 否 | 视频原始宽度 | 1. 值范围:[128, 4096] 2. 单位:px 3. 若只设置 Width 时, 按照视频原始比例计算 Height 4. 必须为偶数 |
Height | Request.Video | 高 | String | 否 | 视频原始高度 | 1. 值范围:[128, 4096] 2. 单位:px 3. 若只设置 Height 时,按照视频原始比例计算 Width 4. 必须为偶数 |
Fps | Request.Video | 帧率 | String | 否 | 无 | 1. 值范围:(0, 60] 2. 单位:fps |
Remove | Request.Video | 是否删除视频流 | String | 否 | false | true、false |
Profile | Request.Video | 编码级别 | String | 否 | high | 1. 支持 baseline、main、high、auto 2. 当Pixfmt为auto时,该参数仅能设置为auto,当设置为其他选项时,参数值将被设置为auto 3. baseline:适合移动设备; 4. main:适合标准分辨率设备; 5. high:适合高分辨率设备; 6. 仅H.264支持此参数。 |
Bitrate | Request.Video | 视频输出文件的码率 | String | 否 | 无 | 1. 值范围:[10, 50000] 2. 单位:Kbps |
Crf | Request.Video | 码率-质量控制因子 | String | 否 | 无 | 1. 值范围:(0, 51] 2. 如果设置了 Crf,则 Bitrate 的设置失效 3. 当 Bitrate 为空时,默认为25 |
Gop | Request.Video | 关键帧间最大帧数 | String | 否 | 无 | 值范围:[1, 100000] |
Preset | Request.Video | 视频算法器预置 | String | 否 | medium,当 Codec 为 VP8 时,为 good | 1. H.264支持该参数,取值 veryfast、fast、medium、slow、slower 2. VP8 支持该参数,取值 good、realtime 3. H.265和VP9不支持该参数 |
Bufsize | Request.Video | 缓冲区大小 | String | 否 | 无 | 1. 值范围:[1000, 128000] 2. 单位:Kb 3. Codec 为 VP8/VP9时不支持此参数 |
Maxrate | Request.Video | 视频码率峰值 | String | 否 | 无 | 1. 值范围:[10, 50000] 2. 单位:Kbps 3. Codec 为 VP8/VP9时不支持此参数 |
Pixfmt | Request.Video | 视频颜色格式 | String | 否 | 无 | 1. H.264支持:yuv420p、yuv422p、yuv444p、yuvj420p、yuvj422p、yuvj444p、auto 2. H.265支持:yuv420p、yuv420p10le、auto 3. Codec 为 VP8/VP9时不支持此参数 |
LongShortMode | Request.Video | 长短边自适应 | String | 否 | false | 1. true、false 2. Codec 为 VP8/VP9时不支持此参数 |
Rotate | Request.Video | 旋转角度 | String | 否 | 无 | 1. 值范围:[0, 360) 2. 单位:度 |
Container 类型 TimeInterval 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 | 默认值 | 限制 |
---|---|---|---|---|---|---|
Start | Request.TimeInterval | 开始时间 | String | 否 | 0 |
|
Duration | Request.TimeInterval | 持续时间 | String | 否 | 视频时长 |
|
Container 类型 Audio 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 | 默认值 | 限制 |
---|---|---|---|---|---|---|
Codec | Request.Audio | 编解码格式 | String | 否 | aac,当 format 为 WebM 时,为 Vorbis | 取值 aac、mp3、flac、amr、Vorbis、opus |
Samplerate | Request.Audio | 采样率 | String | 否 | 44100,当 Codec 为 opus 时,默认值为48000 |
|
Bitrate | Request.Audio | 原始音频码率 | String | 否 | 无 |
|
Channels | Request.Audio | 声道数 | String | 否 | 无 |
|
Remove | Request.Audio | 是否删除源音频流 | String | 否 | false | 取值 true、false |
KeepTwoTracks | Request.Audio | 保持双音轨 | String | 否 | false | 取值 true、false。 当 Video.Codec 为H.265时,此参数无效 |
SwitchTrack | Request.Audio | 转换轨道 | String | 否 | false | 取值 true、false。 当 Video.Codec 为H.265时,此参数无效 |
SampleFormat | Request.Audio | 采样位宽 | String | 否 | 无 |
|
说明:Y 表示支持这种采样率,N 表示不支持。
Audio.Codec 采样率支持情况,如下表所示:
Audio.Codec | aac | amr | flac | opus | Vorbis | mp3 |
---|---|---|---|---|---|---|
8000 | Y | Y | Y | Y | Y | 封装不同,支持不同 |
11025 | Y | N | Y | N | Y | |
12000 | Y | N | Y | N | Y | |
16000 | Y | N | Y | Y | Y | |
22050 | Y | N | Y | N | Y | |
24000 | Y | N | Y | Y | Y | |
32000 | Y | N | Y | N | Y | |
44100 | Y | N | Y | N | Y | |
48000 | Y | N | Y | Y | Y | |
88200 | Y | N | Y | N | Y | |
96000 | Y | N | Y | N | 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 | N | Y | Y | Y | Y | Y | Y | Y | Y | N | N |
Container 类型 TransConfig 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 | 默认值 | 限制 |
---|---|---|---|---|---|---|
AdjDarMethod | Request.TransConfig | 分辨率调整方式 | String | 否 | none |
|
IsCheckReso | Request.TransConfig | 是否检查分辨率 | String | 否 | false |
|
ResoAdjMethod | Request.TransConfig | 分辨率调整方式 | String | 否 | 0 |
|
IsCheckVideoBitrate | Request.TransConfig | 是否检查视频码率 | String | 否 | false |
|
VideoBitrateAdjMethod | Request.TransConfig | 视频码率调整方式 | String | 否 | 0 |
|
IsCheckAudioBitrate | Request.TransConfig | 是否检查音频码率 | String | 否 | false |
|
AudioBitrateAdjMethod | Request.TransConfig | 音频码率调整方式 | String | 否 | 0 |
|
DeleteMetadata | Request.TransConfig | 是否删除文件中的 MetaData 信息 | String | 否 | false |
|
IsHdr2Sdr | Request.TransConfig | 是否开启 HDR 转 SDR | String | 否 | false | true、false |
HlsEncrypt | Request.TransConfig | hls 加密配置 | Container | 否 | 无 | 无 |
StreamSegmentTime | Request.TransConfig | dash等格式切片时间 | String | 否 | 5 |
|
AdjDarMethod 参数图示:
Container 类型 HlsEncrypt 的具体数据描述如下:
节点名称(关键字) | 父节点 | 描述 | 类型 | 必选 | 默认值 | 限制 |
---|---|---|---|---|---|---|
IsHlsEncrypt | Request.TransConfig.HlsEncrypt | 是否开启HLS加密 | String | 否 | false |
|
UriKey | Request.TransConfig.HlsEncrypt | HLS加密的key | String | 否 | 无 | 当 IsHlsEncrypt 为 true 时,该参数才有意义 |
响应
响应头
此接口仅返回公共响应头部,详情请参见 公共响应头部 文档。
响应体
该响应体返回为 application/xml 数据,包含完整节点数据的内容展示如下:
<Response>
<Template>
<Tag>Transcode</Tag>
<TemplateId>t1460606b9752148c4ab182f55163ba7cd</TemplateId>
<Name>TemplateName</Name>
<Container>
<Format>mp4</Format>
</Container>
<Video>
<Codec>H.264</Codec>
<Profile>high</Profile>
<Bitrate>1000</Bitrate>
<Crf></Crf>
<Width>1280</Width>
<Height></Height>
<Fps>30</Fps>
<Gop></Gop>
<Preset>medium</Preset>
<ScanMode></ScanMode>
<Bufsize>0</Bufsize>
<Maxrate>0</Maxrate>
</Video>
<Audio>
<Codec>aac</Codec>
<Samplerate>44100</Samplerate>
<Bitrate>128</Bitrate>
<Channels>4</Channels>
</Audio>
<TransConfig>
<AdjDarMethod>scale</AdjDarMethod>
<IsCheckReso>false</IsCheckReso>
<ResoAdjMethod>1</ResoAdjMethod>
</TransConfig>
<TimeInterval>
<Start>0</Start>
<Duration>60</Duration>
</TimeInterval>
<CreateTime>2020-08-05T11:35:24+0800</CreateTime>
<UpdateTime>2020-08-31T16:15:20+0800</UpdateTime>
</Template>
</Response>
具体的数据内容如下:
节点名称(关键字) | 父节点 | 描述 | 类型 |
---|---|---|---|
Response | 无 | 保存结果的容器,同 CreateMediaTemplate 中的Response | Container |
Container 节点 Response 的内容:
节点名称(关键字) | 父节点 | 描述 | 类型 |
---|---|---|---|
TemplateId | Response | 模板 ID | String |
Name | Response | 模板名字 | String |
Tag | Response | 模板类型,Transcode | String |
UpdateTime | Response | 更新时间 | String |
TimeInterval | Response | 同请求体中 Request.TimeInterval | Container |
Container | Response | 同请求体中 Request.Container | Container |
Video | Response | 同请求体中 Request.Video | Container |
Audio | Response | 同请求体中 Request.Audio | Container |
TransConfig | Response | 同请求体中 Request.TransConfig | Container |
错误码
该请求操作无特殊错误信息,常见的错误信息请参见 错误码 文档。
实际案例
请求
PUT /template/<TemplateId> HTTP/1.1
Authorization: q-sign-algorithm=sha1&q-ak=AKIDZfbOAo7cllgPvF9cXFrJD0a1ICvR****&q-sign-time=1497530202;1497610202&q-key-time=1497530202;1497610202&q-header-list=&q-url-param-list=&q-signature=28e9a4986df11bed0255e97ff90500557e0e****
Host: examplebucket-1250000000.ci.ap-beijing.myqcloud.com
Content-Length: 1666
Content-Type: application/xml
<Request>
<Tag>Transcode</Tag>
<Name>TemplateName</Name>
<Container>
<Format>mp4</Format>
</Container>
<Video>
<Codec>H.264</Codec>
<Profile>high</Profile>
<Bitrate>1000</Bitrate>
<Crf></Crf>
<Width>1280</Width>
<Height></Height>
<Fps>30</Fps>
<Gop></Gop>
<Preset>medium</Preset>
<ScanMode></ScanMode>
<Bufsize>0</Bufsize>
<Maxrate>0</Maxrate>
</Video>
<Audio>
<Codec>aac</Codec>
<Samplerate>44100</Samplerate>
<Bitrate>128</Bitrate>
<Channels>4</Channels>
</Audio>
<TransConfig>
<AdjDarMethod>scale</AdjDarMethod>
<IsCheckReso>false</IsCheckReso>
<ResoAdjMethod>1</ResoAdjMethod>
</TransConfig>
<TimeInterval>
<Start>0</Start>
<Duration>60</Duration>
</TimeInterval>
</Request>
响应
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 100
Connection: keep-alive
Date: Thu, 15 Jun 2017 12:37:29 GMT
Server: tencent-ci
x-ci-request-id: NTk0MjdmODlfMjQ4OGY3XzYzYzhf****
<Response>
<Template>
<Tag>Transcode</Tag>
<TemplateId>t1460606b9752148c4ab182f55163ba7cd</TemplateId>
<Name>TemplateName</Name>
<Container>
<Format>mp4</Format>
</Container>
<Video>
<Codec>H.264</Codec>
<Profile>high</Profile>
<Bitrate>1000</Bitrate>
<Crf></Crf>
<Width>1280</Width>
<Height></Height>
<Fps>30</Fps>
<Gop></Gop>
<Preset>medium</Preset>
<ScanMode></ScanMode>
<Bufsize>0</Bufsize>
<Maxrate>0</Maxrate>
</Video>
<Audio>
<Codec>aac</Codec>
<Samplerate>44100</Samplerate>
<Bitrate>128</Bitrate>
<Channels>4</Channels>
</Audio>
<TransConfig>
<AdjDarMethod>scale</AdjDarMethod>
<IsCheckReso>false</IsCheckReso>
<ResoAdjMethod>1</ResoAdjMethod>
</TransConfig>
<TimeInterval>
<Start>0</Start>
<Duration>60</Duration>
</TimeInterval>
<CreateTime>2020-08-05T11:35:24+0800</CreateTime>
<UpdateTime>2020-08-31T16:15:20+0800</UpdateTime>
</Template>
</Response>