3

I'm trying to determine how effective an M1 Mac would be for transcoding video using FFmpeg (specifically resizing and adjusting bitrate). I can do single transcodes using a command like this:

ffmpeg -I in.mp4 -nostdin -c:v h264_videotoolbox -c:a copy -vf scale=1280:720 -b:v 8000k out.mp4

Now, when I run this, I can see the process in Activity Monitor, but it shows significant CPU use but 0% GPU use, although it's certainly using some form of hardware acceleration (using libx264 instead of h264_videotoolbox is much slower).

When I try running multiple processes concurrently, the timings suggest little evidence of parallel execution:

Test Timing
convert single test file 6.8s
convert file 5 times sequentially 33.6s
convert file 5 times in parallel 31.5s

Since the M1 chip is supposed to have 7 or 8 GPUs inside it, I expected to see quite good parallelism, so are there options which I'm missing which would:

  1. ensure that the transcoding is actually running on the GPU?
  2. allow parallel execution across the multiple GPUs?
1
  • 1
    Video encoding is not necessarily a part of the GPU (there's only one, by the way, with multiple cores). And even when it is, it runs on dedicated parts of the chip and not the shader cores.
    – Daniel B
    Aug 29, 2021 at 17:15

2 Answers 2

2

Here is what I found on the topic:

For starters, here's a pretty good answer right here on superuser.com relating to how you can increase your ffmpeg threading/speed:

[1] https://superuser.com/a/792609/1211883

Apple M1 7-Core GPU

Next, here is probably the best resources I found on the topic for you and your M1 Mac at least:

[2] https://superuser.com/a/1324326/1211883 ⭐️⭐️⭐️⭐️

[3] https://trac.ffmpeg.org/wiki/HWAccelIntro#VideoToolbox ⭐️⭐️⭐️⭐️⭐️

[4] https://doesitarm.com/tv/running-ffmpeg-on-mac-with-apple-silicon-m1-i-woz7p7zmz2s/ ⭐️⭐️⭐️⭐️

[5] https://github.com/cdgriffith/FastFlix/issues/196 ⭐️⭐️⭐️

To summarize,

On macOPS there’s videotoolbox.

Check this out for the encoder options:

ffmpeg -hide_banner -h encoder=hevc_videotoolbox

Essentially you've got to use the encoder=hevc_videotoolbox hardware encoder.

Nvidia GPU

And here are probably the best resources I found relating to nvidia gpus, just incase someone has one of those instead:

[6] https://developer.nvidia.com/blog/nvidia-ffmpeg-transcoding-guide/

It states that:

"Activating support for hardware acceleration when building [ffmpeg] from source requires some extra steps:"

Which you'll probably want to do what it says there and add support for hardware acceleration onto your ffmpeg installation.

Then under the "Multi-GPU" heading within [6] it states the following:

Multi-GPU Encoding and decoding work must be explicitly assigned to a GPU when using multiple GPUs in one system. GPUs are identified by their index number; by default all work is performed on the GPU with index 0. Use the following command to obtain a list of all NVIDIA GPUs in the system and their corresponding ID numbers:

ffmpeg -vsync 0 -i input.mp4 -c:v h264_nvenc -gpu list -f null –

Once you know the index, the -hwaccel_device index flag can be used to set the active GPU for decoding and encoding. In the example below the work will be executed on the gpu with index 1.

ffmpeg -vsync 0 -hwaccel cuvid -hwaccel_device 1 -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4

Other Helpful Resources

Lastly, the ffmpeg docs themselves probably wouldn't hurt to check out:

[7] https://ffmpeg.org/ffmpeg.html

Again, this resource is awesome showing all the different ffmpeg platform availabilities and ffmpeg gpu options by platform:

[8] https://trac.ffmpeg.org/wiki/HWAccelIntro

I'm trying to level up so I can actually vote on some posts going forward, so I hope this helps!

But yea, trying to transcode video in a timely manner is always fun; 🤞😉 I do wish you the best of luck in all your endeavors!! 😂

0
0

I disagree with this answer. FFmpeg is already built to use all the cores in your machine by default.

See https://video.stackexchange.com/questions/15996/ffmpeg-encoding-and-core-usage

If you have multiple instances of ffmpeg running, they may be disk bound and there will be additional task switching overhead. If you do find that all cores are not being used, its because of the filters you are using - not all filters can be implemented with concurrency and parallelism.

1
  • This should be a comment. It's not about using "all the cores" but rather using a specific hardware encoding capability. Jan 20 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.