在Azure门户上创建Transform Encoding时候,只能选择 Built-in Preset 编码方式(如:H265ContentAwareEncoding)
在创建编码任务时,除了在门户上可选的几种内置的编码格式外,还可以通过自定义的编码预设文件(Preset.json)对视频文件进行编码。如 az ams transform 命令:
# Create a transform with a custom Standard Encoder preset from a JSON file and Low relative priority.
az ams transform create -a myAmsAccount -n transformName -g myResourceGroup --preset "C:\MyPresets\CustomPreset.json" --relative-priority Low
那么,如何来定义创建视频缩略图的预设编码文件呢?
查阅 az ams transform 命令的参数 --preset 的所介绍的一句话 “ In addition to the allowed values, you can also pass a path to a custom Standard Encoder preset JSON file. See https://docs.microsoft.com/rest/api/media/transforms/createorupdate#standardencoderpreset for further details on the settings to use to build a custom preset.”
查看 standard encoder preset 的介绍中包含 @odata.type,codecs,formats 等内容。
如:
{
"@odata.type": "#Microsoft.Media.StandardEncoderPreset",
"codecs": [
{
"@odata.type": "#Microsoft.Media.CopyVideo"
},
{
"@odata.type": "#Microsoft.Media.CopyAudio"
}
],
"formats": [
{
"@odata.type": "#Microsoft.Media.Mp4Format",
"filenamePattern": "{Basename}_{Bitrate}{Extension}"
}
]
}
当需要创建一个缩略图的编码文件时候,可以使用codecs 中的 JpgImage 或者 PngImage ,输出的 formats 则使用对应的 JpgFormat 和 PngFormat 。本例中使用JpgImage作为参考:
{
"@odata.type": "#Microsoft.Media.StandardEncoderPreset",
"codecs": [
{
"@odata.type": "#Microsoft.Media.CopyVideo"
},
{
"@odata.type": "#Microsoft.Media.CopyAudio"
},
{
"@odata.type": "#Microsoft.Media.JpgImage",
"start": "PT05S",
"step": "PT05S",
"range": 1,
"spriteColumn":10,
"layers": [
{
"width": "1024",
"height": "768",
"quality": 90
}
]
}
],
"formats": [
{
"@odata.type": "#Microsoft.Media.Mp4Format",
"filenamePattern": "{Basename}_{Bitrate}{Extension}"
},
{
"@odata.type": "#Microsoft.Media.JpgFormat",
"filenamePattern": "{Basename}_{Index}{Extension}"
}
]
}
以上内容会对输入视频的第5秒生成1张缩略图(range为1),宽1024px,高768px,质量为90. 输入的文件名格式为{Basename}_{Index}{Extension}。关于它们的详细说明,参照官网说明:
JpgImage :https://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgimage
JpgFormat :https://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgformat
az ams transform create --account-name yourmediaservicename --resource-group yourresourcegroup --name generate-thumbnail --preset custom-preset.json
如果在执行中遇见错误,可以使用 --debug 参数来查看调试详细的错误。
当执行成功后,会输出如下内容:
检验自定义编码文件的输出成果:
JpgImage :https://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgimage
JpgFormat :https://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgformat
az ams transform create :https://learn.microsoft.com/en-us/cli/azure/ams/transform?view=azure-cli-latest#az-ams-transform-create-examples