Forzar a ffmpeg a utilizar el 100% de la CPU

Forzar a ffmpeg a utilizar el 100% de la CPU

Estoy usando ffmpeg para extraer fotogramas de un vídeo, pero el proceso es muy lento. Al observar el uso de la CPU, veo que ffmpeg usa solo el 50% de mi CPU. También intenté agregar -threads 4, pero parece que no tiene ningún efecto. Necesito maximizar la velocidad de este proceso. ¿Cómo puedo hacerlo?

Actualización: Así que realicé una prueba, primero intenté convertir un video solo y obtuve este resultado:

ffmpeg version N-71959-g9253cc4 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
  libavutil      54. 23.101 / 54. 23.101
  libavcodec     56. 37.102 / 56. 37.102
  libavformat    56. 32.100 / 56. 32.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.33.100
  Duration: 00:30:23.13, start: 0.000000, bitrate: 573 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 501 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 32 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(und): Data: none (rtp  / 0x20707472), 26 kb/s (default)
    Metadata:
      creation_time   : 2014-08-27 16:05:35
      handler_name    : GPAC ISO Hint Handler
    Stream #0:3(und): Data: none (rtp  / 0x20707472), 7 kb/s (default)
    Metadata:
      creation_time   : 2014-08-27 16:05:53
      handler_name    : GPAC ISO Hint Handler
[swscaler @ 0000000002e63360] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'C:\TEMP\1-%d.jpg':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.32.100
    Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 1 fps, 1 tbn, 1 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc56.37.102 mjpeg
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame=   15 fps=0.0 q=1.6 size=N/A time=00:00:15.00 bitrate=N/A dup=0 drop=384    
frame=   28 fps= 28 q=1.6 size=N/A time=00:00:28.00 bitrate=N/A dup=0 drop=763    
frame=   42 fps= 28 q=1.6 size=N/A time=00:00:42.00 bitrate=N/A dup=0 drop=1172    
frame=   55 fps= 27 q=1.6 size=N/A time=00:00:55.00 bitrate=N/A dup=0 drop=1529    
frame=   67 fps= 27 q=1.6 size=N/A time=00:01:07.00 bitrate=N/A dup=0 drop=1896    
frame=   80 fps= 27 q=1.6 size=N/A time=00:01:20.00 bitrate=N/A dup=0 drop=2267    
frame=   93 fps= 27 q=1.6 size=N/A time=00:01:33.00 bitrate=N/A dup=0 drop=2651    
frame=  106 fps= 26 q=1.6 size=N/A time=00:01:46.00 bitrate=N/A dup=0 drop=3025    
frame=  119 fps= 26 q=1.6 size=N/A time=00:01:59.00 bitrate=N/A dup=0 drop=3386    
frame=  131 fps= 26 q=1.6 size=N/A time=00:02:11.00 bitrate=N/A dup=0 drop=3757    
frame=  144 fps= 26 q=1.6 size=N/A time=00:02:24.00 bitrate=N/A dup=0 drop=4124    
frame=  157 fps= 26 q=1.6 size=N/A time=00:02:37.00 bitrate=N/A dup=0 drop=4487    
frame=  169 fps= 26 q=1.6 size=N/A time=00:02:49.00 bitrate=N/A dup=0 drop=4852    
frame=  182 fps= 26 q=1.6 size=N/A time=00:03:02.00 bitrate=N/A dup=0 drop=5226    
frame=  195 fps= 26 q=1.6 size=N/A time=00:03:15.00 bitrate=N/A dup=0 drop=5593    
frame=  209 fps= 26 q=1.6 size=N/A time=00:03:29.00 bitrate=N/A dup=0 drop=5990    
frame=  222 fps= 26 q=1.6 size=N/A time=00:03:42.00 bitrate=N/A dup=0 drop=6367    
frame=  235 fps= 26 q=1.6 size=N/A time=00:03:55.00 bitrate=N/A dup=0 drop=6753    
frame=  248 fps= 26 q=1.6 size=N/A time=00:04:08.00 bitrate=N/A dup=0 drop=7131    
frame=  261 fps= 26 q=1.6 size=N/A time=00:04:21.00 bitrate=N/A dup=0 drop=7497    
frame=  274 fps= 26 q=1.6 size=N/A time=00:04:34.00 bitrate=N/A dup=0 drop=7873    
frame=  287 fps= 26 q=1.6 size=N/A time=00:04:47.00 bitrate=N/A dup=0 drop=8255    
frame=  300 fps= 26 q=1.6 size=N/A time=00:05:00.00 bitrate=N/A dup=0 drop=8644    
frame=  314 fps= 26 q=1.6 size=N/A time=00:05:14.00 bitrate=N/A dup=0 drop=9036    
frame=  328 fps= 26 q=1.6 size=N/A time=00:05:28.00 bitrate=N/A dup=0 drop=9438    
frame=  340 fps= 26 q=1.6 size=N/A time=00:05:40.00 bitrate=N/A dup=0 drop=9813    
frame=  354 fps= 26 q=1.6 size=N/A time=00:05:54.00 bitrate=N/A dup=0 drop=10205    
frame=  367 fps= 26 q=1.6 size=N/A time=00:06:07.00 bitrate=N/A dup=0 drop=10585    
frame=  380 fps= 26 q=1.6 size=N/A time=00:06:20.00 bitrate=N/A dup=0 drop=10961    
frame=  394 fps= 26 q=1.6 size=N/A time=00:06:34.00 bitrate=N/A dup=0 drop=11360    
frame=  406 fps= 26 q=1.6 size=N/A time=00:06:46.00 bitrate=N/A dup=0 drop=11712    
frame=  420 fps= 26 q=1.6 size=N/A time=00:07:00.00 bitrate=N/A dup=0 drop=12103    
frame=  434 fps= 26 q=1.6 size=N/A time=00:07:14.00 bitrate=N/A dup=0 drop=12509    
frame=  447 fps= 26 q=1.6 size=N/A time=00:07:27.00 bitrate=N/A dup=0 drop=12888    
frame=  460 fps= 26 q=1.6 size=N/A time=00:07:40.00 bitrate=N/A dup=0 drop=13267    
frame=  473 fps= 26 q=1.6 size=N/A time=00:07:53.00 bitrate=N/A dup=0 drop=13640    
frame=  486 fps= 26 q=1.6 size=N/A time=00:08:06.00 bitrate=N/A dup=0 drop=14036    
frame=  500 fps= 26 q=1.6 size=N/A time=00:08:20.00 bitrate=N/A dup=0 drop=14421    
frame=  513 fps= 26 q=1.6 size=N/A time=00:08:33.00 bitrate=N/A dup=0 drop=14808    
frame=  526 fps= 26 q=1.6 size=N/A time=00:08:46.00 bitrate=N/A dup=0 drop=15197    
frame=  540 fps= 26 q=1.6 size=N/A time=00:09:00.00 bitrate=N/A dup=0 drop=15579    
frame=  552 fps= 26 q=1.6 size=N/A time=00:09:12.00 bitrate=N/A dup=0 drop=15948    
frame=  565 fps= 26 q=1.6 size=N/A time=00:09:25.00 bitrate=N/A dup=0 drop=16321    
frame=  579 fps= 26 q=1.6 size=N/A time=00:09:39.00 bitrate=N/A dup=0 drop=16725    
frame=  592 fps= 26 q=1.6 size=N/A time=00:09:52.00 bitrate=N/A dup=0 drop=17097    
frame=  605 fps= 26 q=1.6 size=N/A time=00:10:05.00 bitrate=N/A dup=0 drop=17462    
frame=  618 fps= 26 q=1.6 size=N/A time=00:10:18.00 bitrate=N/A dup=0 drop=17851    
frame=  631 fps= 26 q=1.6 size=N/A time=00:10:31.00 bitrate=N/A dup=0 drop=18225    
frame=  644 fps= 26 q=1.6 size=N/A time=00:10:44.00 bitrate=N/A dup=0 drop=18607    
frame=  657 fps= 26 q=1.6 size=N/A time=00:10:57.00 bitrate=N/A dup=0 drop=18969    
frame=  669 fps= 26 q=1.6 size=N/A time=00:11:09.00 bitrate=N/A dup=0 drop=19333    
frame=  681 fps= 26 q=1.6 size=N/A time=00:11:21.00 bitrate=N/A dup=0 drop=19681    
frame=  693 fps= 26 q=1.6 size=N/A time=00:11:33.00 bitrate=N/A dup=0 drop=20026    
frame=  706 fps= 26 q=1.6 size=N/A time=00:11:46.00 bitrate=N/A dup=0 drop=20402    
frame=  716 fps= 26 q=1.6 size=N/A time=00:11:56.00 bitrate=N/A dup=0 drop=20691    
frame=  726 fps= 26 q=1.6 size=N/A time=00:12:06.00 bitrate=N/A dup=0 drop=20985    
frame=  738 fps= 26 q=1.6 size=N/A time=00:12:18.00 bitrate=N/A dup=0 drop=21317    
frame=  751 fps= 26 q=1.6 size=N/A time=00:12:31.00 bitrate=N/A dup=0 drop=21692    
frame=  763 fps= 26 q=1.6 size=N/A time=00:12:43.00 bitrate=N/A dup=0 drop=22049    
frame=  775 fps= 26 q=1.6 size=N/A time=00:12:55.00 bitrate=N/A dup=0 drop=22403    
frame=  788 fps= 26 q=1.6 size=N/A time=00:13:08.00 bitrate=N/A dup=0 drop=22764    
frame=  801 fps= 26 q=1.6 size=N/A time=00:13:21.00 bitrate=N/A dup=0 drop=23149    
frame=  814 fps= 26 q=1.6 size=N/A time=00:13:34.00 bitrate=N/A dup=0 drop=23540    
frame=  828 fps= 26 q=1.6 size=N/A time=00:13:48.00 bitrate=N/A dup=0 drop=23937    
frame=  841 fps= 26 q=1.6 size=N/A time=00:14:01.00 bitrate=N/A dup=0 drop=24315    
frame=  854 fps= 26 q=1.6 size=N/A time=00:14:14.00 bitrate=N/A dup=0 drop=24694    
frame=  867 fps= 26 q=1.6 size=N/A time=00:14:27.00 bitrate=N/A dup=0 drop=25071    
frame=  881 fps= 26 q=1.6 size=N/A time=00:14:41.00 bitrate=N/A dup=0 drop=25458    
frame=  894 fps= 26 q=1.6 size=N/A time=00:14:54.00 bitrate=N/A dup=0 drop=25844    
frame=  908 fps= 26 q=1.6 size=N/A time=00:15:08.00 bitrate=N/A dup=0 drop=26240    
frame=  923 fps= 26 q=1.6 size=N/A time=00:15:23.00 bitrate=N/A dup=0 drop=26675    
frame=  935 fps= 26 q=1.6 size=N/A time=00:15:35.00 bitrate=N/A dup=0 drop=27038    
frame=  949 fps= 26 q=1.6 size=N/A time=00:15:49.00 bitrate=N/A dup=0 drop=27431    
frame=  961 fps= 26 q=1.6 size=N/A time=00:16:01.00 bitrate=N/A dup=0 drop=27776    
frame=  973 fps= 26 q=1.6 size=N/A time=00:16:13.00 bitrate=N/A dup=0 drop=28125    
frame=  985 fps= 26 q=1.6 size=N/A time=00:16:25.00 bitrate=N/A dup=0 drop=28477    
frame=  998 fps= 26 q=1.6 size=N/A time=00:16:38.00 bitrate=N/A dup=0 drop=28848    
frame= 1010 fps= 26 q=1.6 size=N/A time=00:16:50.00 bitrate=N/A dup=0 drop=29211    
frame= 1023 fps= 26 q=1.6 size=N/A time=00:17:03.00 bitrate=N/A dup=0 drop=29572    
frame= 1035 fps= 26 q=1.6 size=N/A time=00:17:15.00 bitrate=N/A dup=0 drop=29932    
frame= 1047 fps= 26 q=1.6 size=N/A time=00:17:27.00 bitrate=N/A dup=0 drop=30294    
frame= 1060 fps= 26 q=1.6 size=N/A time=00:17:40.00 bitrate=N/A dup=0 drop=30644    
frame= 1072 fps= 26 q=1.6 size=N/A time=00:17:52.00 bitrate=N/A dup=0 drop=31004    
frame= 1085 fps= 26 q=1.6 size=N/A time=00:18:05.00 bitrate=N/A dup=0 drop=31368    
frame= 1097 fps= 26 q=1.6 size=N/A time=00:18:17.00 bitrate=N/A dup=0 drop=31742    
frame= 1110 fps= 26 q=1.6 size=N/A time=00:18:30.00 bitrate=N/A dup=0 drop=32101    
frame= 1123 fps= 26 q=1.6 size=N/A time=00:18:43.00 bitrate=N/A dup=0 drop=32493    
frame= 1137 fps= 26 q=1.6 size=N/A time=00:18:57.00 bitrate=N/A dup=0 drop=32874    
frame= 1150 fps= 26 q=1.6 size=N/A time=00:19:10.00 bitrate=N/A dup=0 drop=33251    
frame= 1162 fps= 26 q=1.6 size=N/A time=00:19:22.00 bitrate=N/A dup=0 drop=33626    
frame= 1175 fps= 26 q=1.6 size=N/A time=00:19:35.00 bitrate=N/A dup=0 drop=33990    
frame= 1188 fps= 26 q=1.6 size=N/A time=00:19:48.00 bitrate=N/A dup=0 drop=34362    
frame= 1201 fps= 26 q=1.6 size=N/A time=00:20:01.00 bitrate=N/A dup=0 drop=34739    
frame= 1214 fps= 26 q=1.6 size=N/A time=00:20:14.00 bitrate=N/A dup=0 drop=35127    
frame= 1228 fps= 26 q=1.6 size=N/A time=00:20:28.00 bitrate=N/A dup=0 drop=35521    
frame= 1242 fps= 26 q=1.6 size=N/A time=00:20:42.00 bitrate=N/A dup=0 drop=35916    
frame= 1254 fps= 26 q=1.6 size=N/A time=00:20:54.00 bitrate=N/A dup=0 drop=36281    
frame= 1267 fps= 26 q=1.6 size=N/A time=00:21:07.00 bitrate=N/A dup=0 drop=36661    
frame= 1280 fps= 26 q=1.6 size=N/A time=00:21:20.00 bitrate=N/A dup=0 drop=37017    
frame= 1293 fps= 26 q=1.6 size=N/A time=00:21:33.00 bitrate=N/A dup=0 drop=37394    
frame= 1306 fps= 26 q=1.6 size=N/A time=00:21:46.00 bitrate=N/A dup=0 drop=37786    
frame= 1318 fps= 26 q=1.6 size=N/A time=00:21:58.00 bitrate=N/A dup=0 drop=38142    
frame= 1332 fps= 26 q=1.6 size=N/A time=00:22:12.00 bitrate=N/A dup=0 drop=38526    
frame= 1346 fps= 26 q=1.6 size=N/A time=00:22:26.00 bitrate=N/A dup=0 drop=38929    
frame= 1358 fps= 26 q=1.6 size=N/A time=00:22:38.00 bitrate=N/A dup=0 drop=39303    
frame= 1371 fps= 26 q=1.6 size=N/A time=00:22:51.00 bitrate=N/A dup=0 drop=39676    
frame= 1384 fps= 26 q=1.6 size=N/A time=00:23:04.00 bitrate=N/A dup=0 drop=40046    
frame= 1398 fps= 26 q=1.6 size=N/A time=00:23:18.00 bitrate=N/A dup=0 drop=40438    
frame= 1411 fps= 26 q=1.6 size=N/A time=00:23:31.00 bitrate=N/A dup=0 drop=40818    
frame= 1424 fps= 26 q=1.6 size=N/A time=00:23:44.00 bitrate=N/A dup=0 drop=41202    
frame= 1437 fps= 26 q=1.6 size=N/A time=00:23:57.00 bitrate=N/A dup=0 drop=41589    
frame= 1451 fps= 26 q=1.6 size=N/A time=00:24:11.00 bitrate=N/A dup=0 drop=41971    
frame= 1463 fps= 26 q=1.6 size=N/A time=00:24:23.00 bitrate=N/A dup=0 drop=42340    
frame= 1477 fps= 26 q=1.6 size=N/A time=00:24:37.00 bitrate=N/A dup=0 drop=42724    
frame= 1490 fps= 26 q=1.6 size=N/A time=00:24:50.00 bitrate=N/A dup=0 drop=43129    
frame= 1503 fps= 26 q=1.6 size=N/A time=00:25:03.00 bitrate=N/A dup=0 drop=43500    
frame= 1516 fps= 26 q=1.6 size=N/A time=00:25:16.00 bitrate=N/A dup=0 drop=43869    
frame= 1530 fps= 26 q=1.6 size=N/A time=00:25:30.00 bitrate=N/A dup=0 drop=44260    
frame= 1543 fps= 26 q=1.6 size=N/A time=00:25:43.00 bitrate=N/A dup=0 drop=44646    
frame= 1556 fps= 26 q=1.6 size=N/A time=00:25:56.00 bitrate=N/A dup=0 drop=45033    
frame= 1569 fps= 26 q=1.6 size=N/A time=00:26:09.00 bitrate=N/A dup=0 drop=45393    
frame= 1582 fps= 26 q=1.6 size=N/A time=00:26:22.00 bitrate=N/A dup=0 drop=45766    
frame= 1594 fps= 26 q=1.6 size=N/A time=00:26:34.00 bitrate=N/A dup=0 drop=46139    
frame= 1607 fps= 26 q=1.6 size=N/A time=00:26:47.00 bitrate=N/A dup=0 drop=46498    
frame= 1620 fps= 26 q=1.6 size=N/A time=00:27:00.00 bitrate=N/A dup=0 drop=46874    
frame= 1633 fps= 26 q=1.6 size=N/A time=00:27:13.00 bitrate=N/A dup=0 drop=47247    
frame= 1645 fps= 26 q=1.6 size=N/A time=00:27:25.00 bitrate=N/A dup=0 drop=47609    
frame= 1659 fps= 26 q=1.6 size=N/A time=00:27:39.00 bitrate=N/A dup=0 drop=48000    
frame= 1671 fps= 26 q=1.6 size=N/A time=00:27:51.00 bitrate=N/A dup=0 drop=48362    
frame= 1684 fps= 26 q=1.6 size=N/A time=00:28:04.00 bitrate=N/A dup=0 drop=48748    
frame= 1697 fps= 26 q=1.6 size=N/A time=00:28:17.00 bitrate=N/A dup=0 drop=49103    
frame= 1710 fps= 26 q=1.6 size=N/A time=00:28:30.00 bitrate=N/A dup=0 drop=49474    
frame= 1723 fps= 26 q=1.6 size=N/A time=00:28:43.00 bitrate=N/A dup=0 drop=49858    
frame= 1736 fps= 26 q=1.6 size=N/A time=00:28:56.00 bitrate=N/A dup=0 drop=50249    
frame= 1749 fps= 26 q=1.6 size=N/A time=00:29:09.00 bitrate=N/A dup=0 drop=50612    
frame= 1762 fps= 26 q=1.6 size=N/A time=00:29:22.00 bitrate=N/A dup=0 drop=50981    
frame= 1774 fps= 26 q=1.6 size=N/A time=00:29:34.00 bitrate=N/A dup=0 drop=51349    
frame= 1787 fps= 26 q=1.6 size=N/A time=00:29:47.00 bitrate=N/A dup=0 drop=51727    
frame= 1800 fps= 26 q=1.6 size=N/A time=00:30:00.00 bitrate=N/A dup=0 drop=52098    
frame= 1813 fps= 26 q=1.6 size=N/A time=00:30:13.00 bitrate=N/A dup=0 drop=52486    
frame= 1824 fps= 26 q=1.6 Lsize=N/A time=00:30:24.00 bitrate=N/A dup=0 drop=52798    
video:40987kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Todo el proceso tomó 71 segundos con una velocidad de fotogramas de 26 y un uso de CPU del 50 %.

Luego intenté ejecutar la misma conversión usando el mismo video pero con 2 tareas paralelas (básicamente convertirlo 2 veces y guardar imágenes con 2 nombres diferentes). La velocidad de fotogramas de cada vídeo fue de aproximadamente 17 estables para cada vídeo, el uso de CPU de 45 para cada proceso y el tiempo total fue de 105 segundos para el primero y 104 segundos para el otro. Entonces, ejecutarlos uno tras otro habría tomado 70+70=140 segundos, mientras que ejecutar 2 instancias al mismo tiempo, forzar a la CPU a funcionar al 100% tomó 105 segundos para convertir ambos videos, ahorrando 35 segundos, lo que a gran escala son importantes.

Respuesta1

Escribir muchos archivos pequeños es lento. Es por eso que la CPU no está al 100% de carga, pero su disco duro probablemente sí lo esté.

Por supuesto, esto no se refiere a escribir al 100% del rendimiento posible, sino a qué tan rápido su disco puede atender las solicitudes. Debido a que la creación de archivos implica el acceso a muchas regiones del disco que pueden estar bastante separadas, la latencia de acceso al disco es el cuello de botella aquí.

No hay nada que pueda hacer al respecto excepto cambiar a un SSD o un SSD más rápido. Es muy poco probable que RAID0 ayude con cargas vinculadas a la latencia.

información relacionada