【Azure 媒体服务】使用编码预设文件(Preset.json)来自定义编码任务 -- 创建视频缩略图

简介: 【Azure 媒体服务】使用编码预设文件(Preset.json)来自定义编码任务 -- 创建视频缩略图

问题描述

在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

那么,如何来定义创建视频缩略图的预设编码文件呢?

问题解答

准备 preset.json 文件

查阅 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}"
        }
    ]
}
  • @odata.type  的值为固定值 #Microsoft.Media.StandardEncoderPreset,表示标准编码预设文件
  • codecs为一个数组,表示对输入视频进行编码时要使用的编解码器列表。其中的两个 CopyVideo 和 CopyAudio 都是编码标记,告知编码器复复制输入视频比特流 和 制输入音频比特流。
  • formats 表示编码要生成输出的文件,这里表示输出一个MP4文件。

当需要创建一个缩略图的编码文件时候,可以使用codecs 中的 JpgImage 或者 PngImage ,输出的 formats 则使用对应的 JpgFormatPngFormat 。本例中使用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}。关于它们的详细说明,参照官网说明:

JpgImagehttps://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgimage

JpgFormathttps://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgformat

 

执行 transform create 指令

az ams transform create --account-name yourmediaservicename --resource-group yourresourcegroup --name generate-thumbnail --preset custom-preset.json

如果在执行中遇见错误,可以使用 --debug 参数来查看调试详细的错误。

当执行成功后,会输出如下内容:

检验自定义编码文件的输出成果:

 

参考资料

JpgImagehttps://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgimage

JpgFormathttps://learn.microsoft.com/en-us/rest/api/media/transforms/create-or-update?tabs=HTTP#jpgformat

az ams transform createhttps://learn.microsoft.com/en-us/cli/azure/ams/transform?view=azure-cli-latest#az-ams-transform-create-examples

相关文章
|
18天前
|
存储 JSON JavaScript
|
20天前
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
|
20天前
|
存储 SQL JSON
【Azure Logic App】微软云逻辑应用连接到数据库,执行存储过程并转换执行结果为JSON数据
【Azure Logic App】微软云逻辑应用连接到数据库,执行存储过程并转换执行结果为JSON数据
【Azure Logic App】微软云逻辑应用连接到数据库,执行存储过程并转换执行结果为JSON数据
|
20天前
|
JSON 开发工具 数据格式
【Azure Event Hub】Event Hub的Process Data页面无法通过JSON格式预览数据
【Azure Event Hub】Event Hub的Process Data页面无法通过JSON格式预览数据
|
20天前
|
JSON 数据格式 Python
【Azure Developer】Python 读取 json文件及过滤出需要的结果
【Azure Developer】Python 读取 json文件及过滤出需要的结果
|
21天前
|
JSON 数据格式 索引
【Azure Developer】Azure Logic App 示例: 解析 Request Body 的 JSON 的表达式? triggerBody()?
【Azure Developer】Azure Logic App 示例: 解析 Request Body 的 JSON 的表达式? triggerBody()?
|
21天前
|
JSON Java API
【Azure Developer】如何验证 Azure AD的JWT Token (JSON Web 令牌)?
【Azure Developer】如何验证 Azure AD的JWT Token (JSON Web 令牌)?
|
22天前
|
JSON 数据格式
【应用服务 App Service】在Azure Web App的部署文件中,是否可以限制某些文件无法被访问?(如json)
【应用服务 App Service】在Azure Web App的部署文件中,是否可以限制某些文件无法被访问?(如json)
|
25天前
|
JSON 前端开发 JavaScript
|
15天前
|
存储 JSON API
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者
——在成长的路上,我们都是同行者。这篇关于商品详情API接口的文章,希望能帮助到您。期待与您继续分享更多API接口的知识,请记得关注Anzexi58哦! 淘宝API接口(如淘宝开放平台提供的API)允许开发者获取淘宝商品的各种信息,包括商品详情。然而,需要注意的是,直接访问淘宝的商品数据API通常需要商家身份或开发者权限,并且需要遵循淘宝的API使用协议。
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者

热门文章

最新文章