Search code examples
multithreadingvideoffmpeg

How can I figure out the optimized number of parallel running encoding jobs with the x264 encoder library


I'm batch converting hundreds of videos to mp4 and trying to optimize my method.

I have written a node script, which spawns FFMPEG processes to convert the videos.

From my understanding both FFMPEG and the libx264 encoder are already optimized for multithreaded support. I'm using the default threading option in the encoder.

I'm trying to find the optimal number of FFMPEG spawned processes I should make. There seems to be a balance between having too many and slowing down the encoding of all jobs vs too few process going through the job queue too slowly.

I'm also wondering if dedicating a specific number of threads to each encode job would help rather than using the default setting?

For my setup I'm on a dated 12-core Mac Pro with 24-threads, though this question is about finding the optimal balance in general.


Solution

  • When encoding video threading always comes at the cost of quality. libx264 is very good at threading, but it is not immune from this effect. In my testing, around 4 threads you can start to see a visual difference at low bitrates. Normally, this is ok, and is a worthwhile trade-off to speed up encoding.

    But you are not doing that. You are encoding many videos on a single processor. So optimally you would use 1 thread per encode, and as many parallel encodes as there are cores.

    This will not speed up encoding, this will take the same amount of time, But result in higher quality video when done.