I'm using FFmpeg to convert a number of files from MP4(H264 & AC3) to MP4(H264 & AAC) using the command ffmpeg -i in.mp4 -c:v copy -c:a aac out.mp4

I have a 4 core CPU with hyper-threading that shows around 15% usage when doing the conversion. The files are located on an SSD, and disk activity is around 3MB/s, so disk does not seem to be a bottleneck.

When the encoding starts the CPU hits its maximum frequency, but I have not noticed the load on any of the cores to go over about 50%.

Does FFmpeg make poor use of multiple cores? Is there any way to make the encode faster?

  • Run several ffmpeg processes at the same time. – llogan Apr 6 '17 at 21:21

The only thing you're encoding is audio, and most audio encoding libraries in existence are single-threaded. This is most likely because audio encoding is already blazing fast as a single-threaded application (when compared to video encoding anyway), and it doesn't use too much memory so it's actually feasible to encode each file using a single thread and just start up as many separate processes as necessary to fully saturate the CPU. Factor in the fact that multi-threading also doesn't necessarily result in linear performance improvements and you probably have the reason why the developers of most audio encoders don't think multi-threading is a high priority. I know only of two audio encoders that implement multi-threading - LAME MT for MP3 and pflac for FLAC - and both are separate modifications that aren't part of the main codebases of the projects they derived from.

As for your CPU usage, with hyper-threading you have 8 logical cores and one eight of 100% is 12.5% which isn't too far from your 15% utilisation figure. I'm not really sure why you system isn't showing a 100% load on any of the cores, perhaps the OS is moving the process between cores to even out the load or something like that.

If you need to encode a large number of files you might want to consider writing a script that spins up multiple FFmpeg processes to encode multiple files at the same time. I have very little scripting/programming experience but I know of an open source tool that applies the same logic for image optimisation: picopt. So if you need a pointer on how to do it in Python you could take a look at picopt's source code.


check ffmpeg -hwaccels

from https://ffmpeg.org/ffmpeg.html

-hwaccels List all hardware acceleration methods supported in this build of ffmpeg.

-hwaccel_device[:stream_specifier] hwaccel_device (input,per-stream)
Select a device to use for hardware acceleration.

This option only makes sense when the -hwaccel option is also specified. Its exact meaning depends on the specific hardware

acceleration method chosen.

For VDPAU, this option specifies the X11 display/screen to use. If this option is not specified, the value of the DISPLAY environment

variable is used

For DXVA2, this option should contain the number of the display adapter to use. If this option is not specified, the default adapter

is used.

For QSV, this option corresponds to the values of MFX_IMPL_* . Allowed values are:

  • Those are video decoding accelerators. OP is copying the video, so no decode operation involved. – Gyan Apr 6 '17 at 14:40
  • I thought he encodes audio from ac3 to aac – Michael D. Apr 6 '17 at 14:42

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.