microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.37k stars 6.46k forks source link

[ffmpeg] Slow build process with low CPU utilization #42281

Closed greed-106 closed 1 week ago

greed-106 commented 1 week ago

Describe the bug When installing ffmpeg with vcpkg, the build process is extremely slow, taking up to 1.6 hours to complete. Additionally, CPU utilization remains very low during the build (consistently below 30%).

Environment

Reproduction Steps

  1. Install ffmpeg using the command:

    .\vcpkg.exe install ffmpeg
  2. Observe that the build process is extremely slow, taking over an hour to complete, and CPU utilization remains consistently below 30%.

Expected Behavior The build should leverage more CPU cores and complete significantly faster, especially on high-performance hardware.

Additional Context

Logs Below is the complete log from the build process:

PS D:\ymj\code\cpp\vcpkg> .\vcpkg.exe install ffmpeg
Computing installation plan...
The following packages will be built and installed:
    ffmpeg[avcodec,avdevice,avfilter,avformat,core,swresample,swscale]:x64-windows@7.1#1
Detecting compiler hash for triplet x64-windows...
-- Automatically setting %HTTP(S)_PROXY% environment variables to "127.0.0.1:7890".
Compiler found: D:/VisualStudio/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe
Restored 0 package(s) from C:\Users\ymj\AppData\Local\vcpkg\archives in 174 us. Use --debug to see more details.
Installing 1/1 ffmpeg[avcodec,avdevice,avfilter,avformat,core,swresample,swscale]:x64-windows@7.1#1...
Building ffmpeg[avcodec,avdevice,avfilter,avformat,core,swresample,swscale]:x64-windows@7.1#1...
-- Using cached ffmpeg-ffmpeg-n7.1.tar.gz.
-- Cleaning sources at D:/ymj/code/cpp/vcpkg/buildtrees/ffmpeg/src/n7.1-d40f62baf3.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source D:/ymj/code/cpp/vcpkg/downloads/ffmpeg-ffmpeg-n7.1.tar.gz
-- Applying patch 0001-create-lib-libraries.patch
-- Applying patch 0002-fix-msvc-link.patch
-- Applying patch 0003-fix-windowsinclude.patch
-- Applying patch 0004-dependencies.patch
-- Applying patch 0005-fix-nasm.patch
-- Applying patch 0007-fix-lib-naming.patch
-- Applying patch 0013-define-WINVER.patch
-- Applying patch 0020-fix-aarch64-libswscale.patch
-- Applying patch 0024-fix-osx-host-c11.patch
-- Applying patch 0040-ffmpeg-add-av_stream_get_first_dts-for-chromium.patch
-- Applying patch 0041-add-const-for-opengl-definition.patch
-- Applying patch 0043-fix-miss-head.patch
-- Using source at D:/ymj/code/cpp/vcpkg/buildtrees/ffmpeg/src/n7.1-d40f62baf3.clean
-- Found external ninja('1.12.1').
-- Getting CMake variables for x64-windows
-- Using cached msys2-automake-wrapper-20240607-1-any.pkg.tar.zst.
...
-- Fixing pkgconfig file: D:/ymj/code/cpp/vcpkg/packages/ffmpeg_x64-windows/debug/lib/pkgconfig/libswscale.pc
-- Dependencies (release):
-- Dependencies (debug):
-- Installing: D:/ymj/code/cpp/vcpkg/packages/ffmpeg_x64-windows/share/ffmpeg/usage
-- Installing: D:/ymj/code/cpp/vcpkg/packages/ffmpeg_x64-windows/share/ffmpeg/copyright
-- Performing post-build validation
Stored binaries in 1 destinations in 3.5 s.
Elapsed time to handle ffmpeg:x64-windows: 1.6 h
ffmpeg:x64-windows package ABI: 5bae88431e5dfc894accc3cd6c3f2e25b029f99a02c116498c89acd3985bfe7c
Total install time: 1.6 h
To use ffmpeg add the following to your CMake project:

    find_package(FFMPEG REQUIRED)
    target_include_directories(main PRIVATE ${FFMPEG_INCLUDE_DIRS})
    target_link_directories(main PRIVATE ${FFMPEG_LIBRARY_DIRS})
    target_link_libraries(main PRIVATE ${FFMPEG_LIBRARIES})

PS D:\ymj\code\cpp\vcpkg>

Suggestions

  1. Could the low CPU utilization be due to inefficient parallelization during the build process?
  2. Is there a way to manually increase the parallelization level or optimize the build process?

Thank you for your assistance!

dg0yt commented 1 week ago
  1. The build uses parallel jobs via make -j${JOBS}. The actual value is found in the build.sh script which is generated at build time. (However, this port doesn't use the regular vcpkg_build_make).

  2. There should not be much need for tuning. Check the logs if something goes wrong. Check the environment to not limit VCPKG_MAX_CONCURRENCY. Check that antivirus operations don't cause interference.

FTR vcpkg CI has:

Installing 324/2396 ffmpeg[aom,ass,avcodec,avdevice,avfilter,avformat,avisynthplus,avresample,bzip2,core,dav1d,drawtext,dvdvideo,fdk-aac,ffmpeg,fontconfig,freetype,fribidi,gpl,iconv,ilbc,lzma,modplug,mp3lame,nonfree,nvcodec,opencl,opengl,openh264,openjpeg,openmpt,openssl,opus,postproc,qsv,sdl2,snappy,soxr,speex,srt,ssh,swresample,swscale,tesseract,theora,version3,vorbis,vpx,webp,x264,x265,xml2,zlib]:x64-windows@7.1#1...
....
Elapsed time to handle ffmpeg:x64-windows: 23 min
greed-106 commented 1 week ago

Thank you all for your help and suggestions! The issue has been resolved.

I was able to restore the normal build speed by using the dControl software to disable the Antimalware Service Executable process on my system. I hope this solution can help others facing similar issues.

Thanks again for the support from the community!