<p>In case anyone runs into this issue again, I thought I'd post my solution here.</p>
<ul>
<li>Compile openjpeg using following cmake settings.</li>
</ul>
<blockquote>
<p>cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS:bool=off -DBUILD_STATIC_LIBS:bool=on -DCMAKE_INSTALL_PREFIX=&quot;$HOME/ffmpeg_build&quot; -DCMAKE_C_FLAGS=-DOPJ_STATIC -DBUILD_THIRDPARTY:BOOL=ON</p>
</blockquote>
<ul>
<li>Configure ffmpeg to statically link libopenjpeg. The configuration command I used is:</li>
</ul>
<blockquote>
<p>PATH=&quot;$HOME/bin:$PATH&quot; PKG_CONFIG_PATH=&quot;$HOME/ffmpeg_build/lib/pkgconfig&quot; ./configure     --prefix=&quot;$HOME/ffmpeg_build&quot;   --pkg-config-flags=&quot;--static&quot;      --extra-cflags=&quot;-I$HOME/ffmpeg_build/include&quot; --extra-ldflags=&quot;-L$HOME/ffmpeg_build/lib&quot;     --extra-libs=-lpthread     --extra-libs=-lm --bindir=&quot;$HOME/bin&quot;     --enable-libfdk_aac        --enable-libfreetype        --enable-libmp3lame        --enable-libopus        --enable-libvpx       --enable-libx264   --enable-nonfree     --enable-openssl        --enable-demuxer=spdif        --enable-decoder=dolby_e        --enable-decoder=ac3     --enable-gpl     --enable-decoder=eac3     --enable-indev=alsa     --enable-outdev=alsa     --enable-libsrt     --enable-nonfree     --enable-openssl     --enable-static --disable-shared     --enable-libopenjpeg</p>
</blockquote>
<p>Here is the command I used to encode a raw yuv file with openjpeg:</p>
<blockquote>
<p>./ffmpeg -y -c:v rawvideo -s:v 1920x1080 -pix_fmt yuv422p -i ~/Documents/1080p50_video_raw.yuv -i ~/Documents/1080p50_2ch_audio.wav -map 0:0 -map 1:0 -c:v libopenjpeg -c:a libfdk_aac -ac 2 -ar 48000 -b:a 128k -async 1 ~/Documents/1080p50_2ch_jp2_aac.mp4</p>
</blockquote>

CC BY-SA 4.0
2024-07-16T09:28:11.327Z
2024-07-16T09:28:11.327Z
userDtrm
<p>I'm trying to enable libopenjpeg in ffmpeg 5.1. I have compiled openjpeg from <a href="https://github.com/uclouvain/openjpeg" rel="nofollow noreferrer">OpenJPEG git repository</a>, and it is installed in the system as per the instructions in <a href="https://github.com/uclouvain/openjpeg/blob/master/INSTALL.md" rel="nofollow noreferrer">Installation Guide</a>. I can verify the installation with &quot;pkg-config&quot; using,</p>
<pre><code>pkg-config --libs --cflags &quot;libopenjp2 &gt;= 2.1.0&quot;.
</code></pre>
<p>This outputs:</p>
<pre><code>-I/ffmpeg_build/include/openjpeg-2.5 -L/ffmpeg_build/lib -lopenjp2
</code></pre>
<p>However, when trying to run ./configure to compile ffmpeg,I get the following error</p>
<blockquote>
<p>ERROR: libopenjp2 &gt;= 2.1.0 not found using pkg-config</p>
</blockquote>
<p>The ./configure command I'm using is:</p>
<pre><code>PATH=&quot;$HOME/bin:$PATH&quot; PKG_CONFIG_PATH=&quot;$HOME/ffmpeg_build/lib/pkgconfig&quot; ./configure     --prefix=&quot;$HOME/ffmpeg_build&quot;   --pkg-config-flags=&quot;--static&quot;      --extra-cflags=&quot;-I$HOME/ffmpeg_build/include&quot;  --extra-ldflags=&quot;-L$HOME/ffmpeg_build/lib -L$HOME/ffmpeg_build/lib64&quot; --extra-libs=-lpthread     --extra-libs=-lm --bindir=&quot;$HOME/bin&quot; --enable-libfdk_aac  --enable-libfreetype  --enable-libmp3lame  --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265  --enable-nonfree  --enable-openssl        --enable-demuxer=spdif        --enable-decoder=dolby_e        --enable-decoder=ac3     --enable-gpl     --enable-decoder=eac3     --enable-indev=alsa     --enable-outdev=alsa     --enable-libsrt     --enable-nonfree     --enable-openssl     --enable-shared  --enable-libopenjpeg
</code></pre>
<p>The ffbuild/config.log output which contain the error shows the following.</p>
<blockquote>
<p>gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DPIC -I/home/ffmpeg_build/include -I/home/ffmpeg_build/include/openjpeg-2.5 -std=c11 -fomit-frame-pointer -fPIC -pthread -I/home/ffmpeg_build/include -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -pthread -I/home/ffmpeg_build/include/openjpeg-2.5 -DOPJ_STATIC -L/home/ffmpeg_build/lib -DOPJ_STATIC -c -o /tmp/ffconf.ZnMEl1ya/test.o /tmp/ffconf.ZnMEl1ya/test.c
gcc -L/home/ffmpeg_build/lib -L/home/ffmpeg_build/lib64 -Wl,--as-needed -Wl,-z,noexecstack -I/home/ffmpeg_build/include/openjpeg-2.5 -DOPJ_STATIC -L/home/ffmpeg_build/lib -DOPJ_STATIC -o /tmp/ffconf.ZnMEl1ya/test /tmp/ffconf.ZnMEl1ya/test.o -lopenjp2 -lm -lm -lpthread
/usr/bin/ld: /tmp/ffconf.ZnMEl1ya/test.o: in function <code>check_opj_version': test.c:(.text+0x3): undefined reference to </code>opj_version'
/usr/bin/ld: /tmp/ffconf.ZnMEl1ya/test: hidden symbol `opj_version' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
ERROR: libopenjp2 &gt;= 2.1.0 not found using pkg-config</p>
</blockquote>
<p>I'm on Fedora 38, with Linux kernel 6.8.9. How do I get pkg-config in ffmpeg's configure to see the existence of libopenjp2?</p>

<ffmpeg><linux>
Compile ffmpeg 5.1 with libopenjpeg
userDtrm
# Compile ffmpeg 5.1 with libopenjpeg

(Asked by: username_0 on 2024-07-15)

I'm trying to enable libopenjpeg in ffmpeg 5.1. I have compiled openjpeg from OpenJPEG git repository, and it is installed in the system as per the instructions in Installation Guide. I can verify the installation with "pkg-config" using,
pkg-config --libs --cflags "libopenjp2 >= 2.1.0".

This outputs:
-I/ffmpeg_build/include/openjpeg-2.5 -L/ffmpeg_build/lib -lopenjp2

However, when trying to run ./configure to compile ffmpeg,I get the following error

ERROR: libopenjp2 >= 2.1.0 not found using pkg-config

The ./configure command I'm using is:
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure     --prefix="$HOME/ffmpeg_build"   --pkg-config-flags="--static"      --extra-cflags="-I$HOME/ffmpeg_build/include"  --extra-ldflags="-L$HOME/ffmpeg_build/lib -L$HOME/ffmpeg_build/lib64" --extra-libs=-lpthread     --extra-libs=-lm --bindir="$HOME/bin" --enable-libfdk_aac  --enable-libfreetype  --enable-libmp3lame  --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265  --enable-nonfree  --enable-openssl        --enable-demuxer=spdif        --enable-decoder=dolby_e        --enable-decoder=ac3     --enable-gpl     --enable-decoder=eac3     --enable-indev=alsa     --enable-outdev=alsa     --enable-libsrt     --enable-nonfree     --enable-openssl     --enable-shared  --enable-libopenjpeg

The ffbuild/config.log output which contain the error shows the following.

gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DPIC -I/home/ffmpeg_build/include -I/home/ffmpeg_build/include/openjpeg-2.5 -std=c11 -fomit-frame-pointer -fPIC -pthread -I/home/ffmpeg_build/include -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -pthread -I/home/ffmpeg_build/include/openjpeg-2.5 -DOPJ_STATIC -L/home/ffmpeg_build/lib -DOPJ_STATIC -c -o /tmp/ffconf.ZnMEl1ya/test.o /tmp/ffconf.ZnMEl1ya/test.c
gcc -L/home/ffmpeg_build/lib -L/home/ffmpeg_build/lib64 -Wl,--as-needed -Wl,-z,noexecstack -I/home/ffmpeg_build/include/openjpeg-2.5 -DOPJ_STATIC -L/home/ffmpeg_build/lib -DOPJ_STATIC -o /tmp/ffconf.ZnMEl1ya/test /tmp/ffconf.ZnMEl1ya/test.o -lopenjp2 -lm -lm -lpthread
/usr/bin/ld: /tmp/ffconf.ZnMEl1ya/test.o: in function check_opj_version': test.c:(.text+0x3): undefined reference to opj_version'
/usr/bin/ld: /tmp/ffconf.ZnMEl1ya/test: hidden symbol `opj_version' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
ERROR: libopenjp2 >= 2.1.0 not found using pkg-config

I'm on Fedora 38, with Linux kernel 6.8.9. How do I get pkg-config in ffmpeg's configure to see the existence of libopenjp2?

**Tags:** ffmpeg, linux


---

## 1 answers

### Answer by username_0 on 2024-07-16. Score: 0

In case anyone runs into this issue again, I thought I'd post my solution here.

* Compile openjpeg using following cmake settings.

> cmake .. -DCMAKE\_BUILD\_TYPE=Release -DBUILD\_SHARED\_LIBS:bool=off -DBUILD\_STATIC\_LIBS:bool=on -DCMAKE\_INSTALL\_PREFIX="$HOME/ffmpeg\_build" -DCMAKE\_C\_FLAGS=-DOPJ\_STATIC -DBUILD\_THIRDPARTY:BOOL=ON

* Configure ffmpeg to statically link libopenjpeg. The configuration command I used is:

> PATH="$HOME/bin:$PATH" PKG\_CONFIG\_PATH="$HOME/ffmpeg\_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg\_build" --pkg-config-flags="--static" --extra-cflags="-I$HOME/ffmpeg\_build/include" --extra-ldflags="-L$HOME/ffmpeg\_build/lib" --extra-libs=-lpthread --extra-libs=-lm --bindir="$HOME/bin" --enable-libfdk\_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-nonfree --enable-openssl --enable-demuxer=spdif --enable-decoder=dolby\_e --enable-decoder=ac3 --enable-gpl --enable-decoder=eac3 --enable-indev=alsa --enable-outdev=alsa --enable-libsrt --enable-nonfree --enable-openssl --enable-static --disable-shared --enable-libopenjpeg

Here is the command I used to encode a raw yuv file with openjpeg:

> ./ffmpeg -y -c:v rawvideo -s:v 1920x1080 -pix\_fmt yuv422p -i ~/Documents/1080p50\_video\_raw.yuv -i ~/Documents/1080p50\_2ch\_audio.wav -map 0:0 -map 1:0 -c:v libopenjpeg -c:a libfdk\_aac -ac 2 -ar 48000 -b:a 128k -async 1 ~/Documents/1080p50\_2ch\_jp2\_aac.mp4


---

