How can I run GPU-accelerated FFmpeg in an ECS container on EC2?
Asked by
MellowPine47
I'm trying to run FFmpeg with NVIDIA hardware acceleration in Docker on AWS. The workload would run as ECS tasks using the EC2 launch type, rather than standard Fargate. My current plan is to use a GPU-enabled instance such as G7e, install the appropriate NVIDIA GRID drivers and container toolkit, and use an FFmpeg image compiled with NVIDIA support. Has anyone configured this successfully and reliably? I'd especially appreciate examples covering the EC2 host, Docker runtime, ECS task definition, and launching jobs from Step Functions.
Answers
The main limitation is that regular Fargate doesnโt provide GPU passthrough. Youโll need an ECS cluster backed by GPU-capable EC2 instances. Start with an AWS ECS GPU-optimized AMI so the NVIDIA drivers, ECS agent, and container runtime are already set up. Then add a GPU resource requirement to the task definition and use an FFmpeg image built with NVIDIA support.
Reply to this answer
Build it incrementally rather than debugging the whole ECS setup at once. First launch a GPU-optimized EC2 instance and verify the device with `nvidia-smi`. Next, confirm that FFmpeg running directly on the host can access NVENC or CUDA. After that, run a minimal Docker container that executes `nvidia-smi`, followed by a container containing your NVIDIA-enabled FFmpeg build. Once those pieces work from the command line, add the ECS cluster, capacity configuration, task definition, and service or one-off task orchestration.
Reply to this answer
You may not need a G7e specifically. G6 and G7 instances can also be suitable for video transcoding and are often less expensive when you donโt need graphics-heavy workloads. Check the current AWS GPU and driver compatibility tables, but a missing mention in one example doesnโt necessarily mean those instance families are unsupported.
MellowPine47: Good point. Iโll compare G6 and G7 as well instead of assuming G7e is required. The earlier documentation I found may simply have been incomplete.
Reply to this answer
Add your answer
Answers are reviewed before publication.
MellowPine47: That clears up the biggest misunderstanding. I was thinking of Fargate-style tasks on EC2, but Iโll need to use the ECS EC2 launch type instead. The Step Functions integration will need a little more wiring, but this gives me a workable direction.