0

I am trying write CMakeLists with FFmpeg package, with compile on Windows and Linux. First downloaded from FFmpeg-Builds shared releases

I imagine the structure of the project like this:

<project root> deps/ ffmpeg/ win-x64/ incluve/ lib/ bin/ linux-x64/ incluve/ lib/ bin/ src/ CMakeLists.txt 

How to help CMake find libraries: avcodec, avformat, avutil, etc? Maybe in the folder lib/pkgconfig using PkgConfig it is possible to specify the path. But I dont know how

3

2 Answers 2

2

The following worked well for me on Linux with cmake. You will have to find the equivalents for Windows. I used ffmpeg on Windows, but without cmake (i.e. directly in a Visual Studio project).

  1. Install pkg-config, nasm:
 sudo apt-get install -y pkg-config sudo apt-get install nasm 
  1. Download ffmpeg source code:

    https://ffmpeg.org/download.html

  2. Build ffmpeg and install it:

    tar -xvf <downloaded_filename> cd /root/folder/with/ffmpeg/src ./configure make sudo make install 
  3. Add the following to your CMakeLists.txt:

    In the beginning:

     find_package(PkgConfig REQUIRED) pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavdevice libavfilter libavformat libavcodec libswresample libswscale libavutil ) set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) 

    In the linker area:

     target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::LIBAV) 
Sign up to request clarification or add additional context in comments.

2 Comments

Can I download already compiled libraries from the link in the question? Besides, I need support for compiling under Windows. Isn't it easier to use already compiled libraries?
For Linux I found it easier to build from source. For Windows I believe the pre-built libraries are easier to use. This is indeed what I did myself. But as I wrote I used them directly in the VisualStudio project (added include and library paths, and link with appropriate libs).
0

FYI: there are some unofficial cmake support eg:

https://github.com/snikulov/cmake-modules/blob/master/FindFFmpeg.cmake

but still no official support at least in cmake 3.27.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.