Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just got my new server with two intel e5-2695 but I was shocked to see that ffmpeg or ubuntu doesn't utilize all cores.

top while ffmpeg was running

top - 23:35:25 up  2:41,  2 users,  load average: 5.35, 4.37, 3.12
Tasks: 333 total,   2 running, 331 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.0 us,  1.0 sy, 35.6 ni, 63.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.7 sy, 35.5 ni, 63.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :  0.0 us,  0.7 sy, 33.4 ni, 65.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.0 us,  0.0 sy, 32.7 ni, 67.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu4  :  0.0 us,  0.3 sy, 32.3 ni, 67.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu5  :  0.0 us,  0.3 sy, 33.0 ni, 66.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu6  :  0.0 us,  0.0 sy, 32.6 ni, 67.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu7  :  0.0 us,  0.3 sy, 32.7 ni, 67.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu8  :  0.0 us,  0.7 sy, 32.6 ni, 66.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu9  :  0.0 us,  0.3 sy, 33.9 ni, 65.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu10 :  0.0 us,  0.0 sy, 35.0 ni, 65.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu11 :  0.0 us,  0.7 sy, 30.0 ni, 69.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu12 : 21.1 us,  0.0 sy,  0.0 ni, 78.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu13 :  0.7 us,  0.0 sy,  4.3 ni, 95.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu14 :  0.3 us,  0.0 sy,  5.0 ni, 94.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu15 : 24.9 us,  0.0 sy,  0.0 ni, 75.1 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu16 :  0.3 us,  0.0 sy,  3.7 ni, 96.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu17 :  0.7 us,  0.3 sy,  4.9 ni, 94.1 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu18 :  1.0 us,  0.0 sy,  4.6 ni, 94.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu19 :  0.7 us,  0.0 sy,  4.7 ni, 94.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu20 : 11.1 us,  0.0 sy,  0.0 ni, 88.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu21 :  1.3 us,  0.0 sy,  4.6 ni, 94.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu22 :  2.0 us,  0.3 sy,  4.3 ni, 93.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu23 : 96.7 us,  1.0 sy,  0.0 ni,  2.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu24 :  0.0 us,  0.0 sy,  0.7 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu25 :  0.0 us,  0.0 sy,  3.0 ni, 97.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu26 :  0.0 us,  0.0 sy,  1.3 ni, 98.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu27 :  0.0 us,  0.0 sy,  4.0 ni, 96.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu28 :  0.0 us,  0.0 sy,  1.7 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu29 :  0.0 us,  0.0 sy,  1.7 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu30 :  0.0 us,  0.0 sy,  1.7 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu31 :  0.0 us,  0.0 sy,  1.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu32 :  0.0 us,  0.0 sy,  0.7 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu33 :  0.0 us,  0.0 sy,  1.7 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu34 :  0.0 us,  0.0 sy,  2.0 ni, 98.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu35 :  0.0 us,  0.0 sy,  1.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu36 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

What i've tried:

    * tried sending ffmpeg with -threads 0
    * tried sending ffmpeg with -threads 500
    * compiled ffmpeg with --enable-pthreads
    * setting -sws_flags fast_bilinear
    * run with nice -20

You can see from this sceenshot that only the first thread is fully utilized and only the first few threads are in running state, the rest are in sleep state enter image description here

the command

ffmpeg -i hdvd.mkv -map 0:0 -map 0:1 -threads 0 
  -s 1836x1080 -map 0:0 -map 0:1 -vf -vcodec libx264 -acodec aac -strict experimental -movflags faststart hdvd_1080p.mp4 
  -s 1224x720 -map 0:0 -map 0:1 -vf -vcodec libx264 -acodec aac -strict experimental -movflags faststart hdvd_720p.mp4 
  -s 816x480 -map 0:0 -map 0:1 -vf -vcodec libx264 -acodec aac -strict experimental -movflags faststart hdvd_480p.mp4 
  -s 612x360 -map 0:0 -map 0:1 -vf -vcodec libx264 -acodec aac -strict experimental -movflags faststart hdvd_360p.mp4 
  -s 408x240 -map 0:0 -map 0:1 -vf -vcodec libx264 -acodec aac -strict experimental -movflags faststart hdvd_240p.mp4 
  -s 244x144 -map 0:0 -map 0:1 -vcodec libx264 -acodec aac -strict experimental -movflags faststart hdvd_144p.mp4

ffmpeg info:

ffmpeg version N-57989-g76a47d6 Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov  9 2013 14:28:54 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3 --enable-pthreads
share|improve this question
    
Please do not crosspost the same question on several Stack Exchange sites. –  LordNeckbeard Nov 4 '13 at 0:00
    
Can you please post the complete ffmpeg command you are using. –  szatmary Nov 4 '13 at 0:19
    
And ask a question. Otherwise I could guess if the question is if you were really shocked or just a little bit shocked about it. –  Hennes Nov 4 '13 at 0:20
    
@szatmary edited. –  user2783132 Nov 4 '13 at 1:24
    
Interesting, that is a 12 core CPU, which you have 2 of. Thats 24 cores, plus hyperthreading. You should see 48 cores... –  Keltari Nov 11 '13 at 3:02

1 Answer 1

x264 is very heavily threaded. It should be able to use 100% of the CPU if you can feed frames to it fast enough. So something else is bottle-necking. In your case it is most likely the scaler. Scaling is actually a very difficult problem, and is single threaded in ffmpeg. To test this theory, you can try a fast scaler like -sws_flags fast_bilinear. Running a separate command per output may help as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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