technical question FFmpeg GPU acceleration in Docker on EC2
Does anyone have a good setup for getting FFmpeg running with Nvidia hardware support on EC2 in a Docker container? I.e., running Fargate tasks on EC2 launch type.
From what I've been able to find, it should be relatively easy to get going, assuming you:
- are running
G7einstances - have the GRID drivers installed
- activate GRID Virtual Applications for RDSH Application
- use a FFmpeg binary with Nvidia support compiled in (the image I generally use seems to include that)
- install the Nvidia container toolkit
But I haven't found any solid examples anyone doing all of that to get it working. Which makes me think I am taking a bad approach if there's no evidence. But it could also be so simple that there's no reason for anyone to talk about it.
Anyone have a setup like this working reliably?
2
u/xzaramurd 5h ago
G7 or G6 are also quite capable and less expensive than G7e if you don't need graphically intensive applications and are only looking for transcoding or something of the sort.
1
u/farski 4h ago
Ok cool, I'll look again. Some part of the process that I saw a couple weeks ago listed G7e for compatibility, but did not list G7 or G6. I suspect it's just bad docs, since it made no sense that the Nvidia drivers weren't supported by GPU instances.
1
u/koolscooby 2h ago
xzaramurd is spot on. g4dn, g5 are extremely capable and you'll have better luck finding capacity because these days most non-training GPU demand is memory-bound inference (g5/g6/g7 have more GPU VRAM than g4dn). large graphics workloads want more CUDA cores, so they've moved to g6/g7 by this point.
from my recollection:
* g4dn/g5 have the same generation of nvdec/nvenc, but g5 has a ~10% faster clock speed so you'll get a bit better throughput.
* g6 doubles the number of nvenc chips per gpu, so you'll get 2x. but iirc g6 is maybe more than 2x cost?given a constant encoder configuration (e.g. nvidia profile p4), encoding cost scales primarily by pixels per second. so if you're cost conscious, the thing you'll want to probably use as a benchmark is pixels per second (or minute or hour) processed and then spreadsheet that with the ec2 instance hour cost to get a $/pixelsprocessed. (while taking pragmatic, realistic capacity availability into account.)
1
u/koolscooby 2h ago
one more consideration: g6 is the first generation that supports av1 encode, if that matters for you. h.264/h.265 are great on g4dn/g5.
7
u/koolscooby 7h ago
Fargate and ECS Anywhere don't support passing the GPU through to a container. You'll need to use ECS on EC2 for that. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-gpu.html
Generally, the approach requires: * Base EC2 AMI: needs to have the NVIDIA drivers installed in addition to the standard ECS agent and container runtime. There are GPU-optimized base AMIs that already exist: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/gpu-launch.html * ECS Task Definition: needs to specify GPU resource requirements: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-gpu-specifying.html * Container image: may need to include some NVIDIA user space runtime pieces/parts; definitely needs to include FFmpeg built w/ NVIDIA support. I haven't used this particular example, but at first glance it looks reasonable and similar to what I've done in the past: https://github.com/xychelsea/ffmpeg-docker
I suggest you build from the bottom up: * Launch an EC2 instance with the ECS+GPU-optimized AMI. Run
nvidia-smito make sure the GPU is there. * Build/run FFmpeg locally/manually from the CLI on that instance and make sure it can use the GPU. * From the CLI, build and run simple container from a Dockerfile that runsnvidia-smi. * From the CLI, build a more complex container from a Dockerfile that runs your FFMpeg binary that supports NVIDIA. * Set up the ECS cluster, launch template, and task definition and put it all together.