Compiling FFMPEG x265 not found using pkg-config

28k Views Asked by At

I'm trying to compile FFMPEG with x265 on Win10. I am using the latest full MinGW build from xhmikosr found at:

http://xhmikosr.1f0.de/tools/msys/

FFMEPG without x265 compiles without problems and compiling x265 standalone works without problems too. However when i --enable-libx265 in ffmpeg i get the following error:

ERROR: x265 not found using pkg-config

and this from the config.log:

require_pkg_config libx265 x265 x265.h x265_api_get
check_pkg_config libx265 x265 x265.h x265_api_get
test_pkg_config libx265 x265 x265.h x265_api_get
false --exists --print-errors x265
ERROR: x265 not found using pkg-config

my config paths seem to be all set correct.

$ echo $PKG_CONFIG_PATH
C:\MYSYS\local\x86_64-w64-mingw32\lib\pkgconfig

and when i look for the libraries x265 is there:

$ pkg-config --list-all
...
x265          x265 - H.265/HEVC video encoder
...

and here the debug log:

$ pkg-config --debug
...
File 'x265.pc' appears to be a .pc file
Will find package 'x265' in file 'C:/MYSYS/local/x86_64-w64-mingw32/lib/pkgconfig\x265.pc'
...

Why does pkg-config still not find the x265 libraries when i try to compile?

10

There are 10 best solutions below

0
On

After much trial and error, I believe I have found a solution and the root cause under Ubuntu 16.04. This solution may work for other variants of Ubuntu as well.


If you run into the Package Config error described in this thread, try installing the default (repository based) libraries first, and then install your custom version with your ffmpeg build script.

Run these commands as needed prior to running your custom script to compile ffmpeg and your dependent libraries (e.g. x265) from source:

apt install -y libx265-dev

If another library fails, try the same technique and then run your script again to see if it works. For example, some people report compiling ffmpeg from source complains about gnutls. The solution for Ubuntu 16.04 is to first install it via apt and then run your script.

apt install -y gnutls-dev

If you're hung up at compiling the x264 libraries (for H.264 support), simply run this before running your script:

apt install -y libx264-dev

As long as your new script overwrites the old files and does not purge them, this method will work.

Background/History

The source of the problem dates back to at least 2017, and despite numerous claims it does not appear to have actually been fixed. One can find references in various forums and websites of frustrated users unable to get their compile to work correctly regardless of the version of the ffmpeg build, such as here.

It's a difficult problem to solve partly because the VLC Developer instructions for installing x265 library support are broken. Furthermore, the archive of information explaining this problem and how to solve it is no longer available, due to BitBucket's decision to sunset Mercurial support earlier this year. Most archived forum posts explaining the problem and how to solve it are gone. There are a few clues still to be found on GitHub, but they are incomplete snippets of information on the topic; none offer a complete perspective.

Installing ffmpeg from scratch is bound to cause headaches for nearly anyone. NONE of the scripts I found online (dozens) worked correctly as described. Most of the problems with them are incorrect/outdated links. Solutions with GitHub links appear to be the most consistently reliable. Others should be avoided (e.g. hg, which is no longer supported as mentioned above).

3
On

I believe I found the solution. The issue appears to be that current guide is pulling from master (which may be what a developer wants) but in my case I actually needed stable. Instead of using the provided command in the current guide:

sudo apt-get install libnuma-dev && \
cd ~/ffmpeg_sources && \
git -C x265_git pull 2> /dev/null || git clone --depth 1 https://bitbucket.org/multicoreware/x265_git && \
cd x265_git/build/linux && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off ../../source && \
PATH="$HOME/bin:$PATH" make && \
make install

Use this command:

sudo apt-get install libnuma-dev && \
cd ~/ffmpeg_sources && \
git -C x265_git pull 2> /dev/null || git clone --depth 1 https://bitbucket.org/multicoreware/x265_git -b stable && \
cd x265_git/build/linux && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off ../../source && \
PATH="$HOME/bin:$PATH" make && \
make install
1
On

I've also come across a case where the x265.pc is not generated, I know this wasn't the issue in original problem but thought worth mentioning.

This occurs if you don't have git installed, in my case I was building inside a container with pre-fetched sources on a corporate network.

This issue is documented at https://bitbucket.org/multicoreware/x265_git/issues/572/pc-file-is-not-generated

It can be worked around either by installing git or fudging it with something as simple as

touch git
chmod a+x git
export PATH="$PWD:PATH"
1
On

I can't comment as I have too low reputation. I don't know what it's for :(

Anyway, I had the same problem and I had to do two of tricks mentioned above in solutions:

--extra-libs="-lpthread"  
--pkg-config-flags="--static"  

Add both of those switches and victory is yours.

2
On
1
On

In my experience, I configure ffmpeg with x265 in CentOS, it also got error message as

ERROR: x265 not found using pkg-config

After I try this:

$ export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"

I configure and compile ffmpeg successfully with x265. You can try this.

0
On

It's need more library. Please install "libnuma".

2
On

x265.pc sometimes doesn't located in "/usr/local/lib/pkgconfig" and instead it is located in "/usr/lib/arm-linux-gnueabihf/pkgconfig/", so, you needs to include it in the export also .

export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig/:/usr/local/lib/pkgconfig/
0
On

You can try

--pkg-config="pkg-config --static"

2
On

I follow to guide from wiki x265

git clone https://bitbucket.org/multicoreware/x265_git
cd x265_git/build/linux
./make-Makefiles.bash
make

And works fine in Red Hat Enterprise Linux 8