在 Amazon ECS 上使用视频转码 - Amazon Elastic Container Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

在 Amazon ECS 上使用视频转码

要在 Amazon ECS 上使用视频转码工作负载,请注册 Amazon EC2 VT1 实例。注册这些实例后,您可以将实时和预渲染的视频转码工作负载作为 Amazon ECS 上的任务运行。Amazon EC2 VT1 实例使用 Xilinx U30 媒体转码卡来加速实时和预渲染的视频转码工作负载。

注意

有关如何在 Amazon ECS 以外的容器中运行视频转码工作负载的说明,请参阅 Xilinx 文档

注意事项

在 Amazon ECS 上开始部署 VT1 之前,请注意以下事项:

  • 您的集群可以包含 VT1 和非 VT1 实例的组合。

  • 您需要一个 Linux 应用程序,该应用程序使用具有加速 AVC(H.264)和 HEVC(H.265)编解码器的 Xilinx U30 媒体转码卡。

    重要

    使用其他编解码器的应用程序可能不会在 VT1 实例上获得性能提升。

  • U30 卡上只能运行一个转码任务。每张卡都有两个与之关联的设备。您可以运行的转码任务数量与每个 VT1 实例的卡的数量一样。

  • 在创建服务或运行独立任务时,您可以在配置任务放置约束时使用实例类型属性。这样可以确保在您指定的容器实例上启动任务。这样做有助于确保您有效地使用资源,并确保视频转码工作负载任务在 VT1 实例上。有关更多信息,请参阅Amazon ECS 任务放置

    在以下示例中,任务在您的 default 集群上的 vt1.3xlarge 实例上运行。

    aws ecs run-task \ --cluster default \ --task-definition vt1-3xlarge-xffmpeg-processor \ --placement-constraints type=memberOf,expression="attribute:ecs.instance-type == vt1.3xlarge"
  • 您可以将容器配置为使用主机容器实例上可用的特定 U30 卡。您可以通过使用 linuxParameters 参数并指定设备详细信息来执行此操作。有关更多信息,请参阅任务定义要求

使用 VT1 AMI

您有两种选择可以在 Amazon EC2 上运行适用于 Amazon ECS 容器实例的 AMI。第一个选项是在 Amazon Web Services Marketplace 上使用 Xilinx 官方 AMI。第二种选择是从示例存储库构建自己的 AMI。

任务定义要求

要在 Amazon ECS 上运行视频转码容器,您的任务定义必须包含使用加速 H.264/AVC 和 H.265/HEVC 编解码器的视频转码应用程序。您可以按照 Xilinx Github 上的步骤来构建容器映像。

对于 VT1 实例类型系列而言,任务定义必须特定于实例类型。实例类型为 3xlarge、6xlarge 和 24xlarge。您必须将容器配置为使用主机容器实例上可用的特定 Xilinx U30 设备。您还可以使用 linuxParameters 参数执行此操作。下表详细介绍了特定于每种实例类型的卡和设备 SoC。

实例类型 vCPU RAM (GiB) U30 加速器卡 可寻址的 XCU30 SoC 设备 设备路径
vt1.3xlarge 12 24 1 2 /dev/dri/renderD128,/dev/dri/renderD129
vt1.6xlarge 24 48 2 4 /dev/dri/renderD128,/dev/dri/renderD129,/dev/dri/renderD130,/dev/dri/renderD131
vt1.24xlarge 96 182 8 16 /dev/dri/renderD128,/dev/dri/renderD129,/dev/dri/renderD130,/dev/dri/renderD131,/dev/dri/renderD132,/dev/dri/renderD133,/dev/dri/renderD134,/dev/dri/renderD135,/dev/dri/renderD136,/dev/dri/renderD137,/dev/dri/renderD138,/dev/dri/renderD139,/dev/dri/renderD140,/dev/dri/renderD141,/dev/dri/renderD142,/dev/dri/renderD143
重要

如果任务定义列出了 EC2 实例没有的设备,则任务将无法运行。当任务失败时,stoppedReason 中将出现以下错误消息:CannotStartContainerError: Error response from daemon: error gathering device information while adding custom device "/dev/dri/renderD130": no such file or directory

以下示例中,提供了用于 Amazon EC2 上 Linux 容器的任务定义的语法。此任务定义适用于按照 Xilinx 文档中提供的过程构建的容器映像。如果使用此示例,请将 image 替换为您自己的映像,然后将视频文件复制到 /home/ec2-user 目录中的实例。

vt1.3xlarge
  1. 使用以下内容创建名为 vt1-3xlarge-ffmpeg-linux.json 的文本文件。

    { "family": "vt1-3xlarge-xffmpeg-processor", "requiresCompatibilities": ["EC2"], "placementConstraints": [ { "type": "memberOf", "expression": "attribute:ecs.os-type == linux" }, { "type": "memberOf", "expression": "attribute:ecs.instance-type == vt1.3xlarge" } ], "containerDefinitions": [ { "entryPoint": [ "/bin/bash", "-c" ], "command": [ "/video/ecs_ffmpeg_wrapper.sh" ], "linuxParameters": { "devices": [ { "containerPath": "/dev/dri/renderD128", "hostPath": "/dev/dri/renderD128", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD129", "hostPath": "/dev/dri/renderD129", "permissions": [ "read", "write" ] } ] }, "mountPoints": [ { "containerPath": "/video", "sourceVolume": "video_file" } ], "cpu": 0, "memory": 12000, "image": "0123456789012.dkr.ecr.us-west-2.amazonaws.com/aws/xilinx-xffmpeg", "essential": true, "name": "xilinix-xffmpeg" } ], "volumes": [ { "name": "video_file", "host": { "sourcePath": "/home/ec2-user" } } ] }
  2. 注册任务定义。

    aws ecs register-task-definition --family vt1-3xlarge-xffmpeg-processor --cli-input-json file://vt1-3xlarge-xffmpeg-linux.json --region us-east-1
vt1.6xlarge
  1. 使用以下内容创建名为 vt1-6xlarge-ffmpeg-linux.json 的文本文件。

    { "family": "vt1-6xlarge-xffmpeg-processor", "requiresCompatibilities": ["EC2"], "placementConstraints": [ { "type": "memberOf", "expression": "attribute:ecs.os-type == linux" }, { "type": "memberOf", "expression": "attribute:ecs.instance-type == vt1.6xlarge" } ], "containerDefinitions": [ { "entryPoint": [ "/bin/bash", "-c" ], "command": [ "/video/ecs_ffmpeg_wrapper.sh" ], "linuxParameters": { "devices": [ { "containerPath": "/dev/dri/renderD128", "hostPath": "/dev/dri/renderD128", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD129", "hostPath": "/dev/dri/renderD129", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD130", "hostPath": "/dev/dri/renderD130", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD131", "hostPath": "/dev/dri/renderD131", "permissions": [ "read", "write" ] } ] }, "mountPoints": [ { "containerPath": "/video", "sourceVolume": "video_file" } ], "cpu": 0, "memory": 12000, "image": "0123456789012.dkr.ecr.us-west-2.amazonaws.com/aws/xilinx-xffmpeg", "essential": true, "name": "xilinix-xffmpeg" } ], "volumes": [ { "name": "video_file", "host": { "sourcePath": "/home/ec2-user" } } ] }
  2. 注册任务定义。

    aws ecs register-task-definition --family vt1-6xlarge-xffmpeg-processor --cli-input-json file://vt1-6xlarge-xffmpeg-linux.json --region us-east-1
vt1.24xlarge
  1. 使用以下内容创建名为 vt1-24xlarge-ffmpeg-linux.json 的文本文件。

    { "family": "vt1-24xlarge-xffmpeg-processor", "requiresCompatibilities": ["EC2"], "placementConstraints": [ { "type": "memberOf", "expression": "attribute:ecs.os-type == linux" }, { "type": "memberOf", "expression": "attribute:ecs.instance-type == vt1.24xlarge" } ], "containerDefinitions": [ { "entryPoint": [ "/bin/bash", "-c" ], "command": [ "/video/ecs_ffmpeg_wrapper.sh" ], "linuxParameters": { "devices": [ { "containerPath": "/dev/dri/renderD128", "hostPath": "/dev/dri/renderD128", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD129", "hostPath": "/dev/dri/renderD129", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD130", "hostPath": "/dev/dri/renderD130", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD131", "hostPath": "/dev/dri/renderD131", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD132", "hostPath": "/dev/dri/renderD132", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD133", "hostPath": "/dev/dri/renderD133", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD134", "hostPath": "/dev/dri/renderD134", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD135", "hostPath": "/dev/dri/renderD135", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD136", "hostPath": "/dev/dri/renderD136", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD137", "hostPath": "/dev/dri/renderD137", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD138", "hostPath": "/dev/dri/renderD138", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD139", "hostPath": "/dev/dri/renderD139", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD140", "hostPath": "/dev/dri/renderD140", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD141", "hostPath": "/dev/dri/renderD141", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD142", "hostPath": "/dev/dri/renderD142", "permissions": [ "read", "write" ] }, { "containerPath": "/dev/dri/renderD143", "hostPath": "/dev/dri/renderD143", "permissions": [ "read", "write" ] } ] }, "mountPoints": [ { "containerPath": "/video", "sourceVolume": "video_file" } ], "cpu": 0, "memory": 12000, "image": "0123456789012.dkr.ecr.us-west-2.amazonaws.com/aws/xilinx-xffmpeg", "essential": true, "name": "xilinix-xffmpeg" } ], "volumes": [ { "name": "video_file", "host": { "sourcePath": "/home/ec2-user" } } ] }
  2. 注册任务定义。

    aws ecs register-task-definition --family vt1-24xlarge-xffmpeg-processor --cli-input-json file://vt1-24xlarge-xffmpeg-linux.json --region us-east-1