Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.

[How-to] Install ffmpeg in a jail

Joined
Mar 3, 2016
Messages
9
I don't understand why pkg-config complains that there is no x265. pkg-config print shows that .pc is there along with .so lib
Code:
pkg-config --exists --print-errors x265
 
Last edited:

Glorious1

FreeNAS Guru
Joined
Nov 23, 2014
Messages
997
@Dakai, @vinchi007

I completely redid the first post with all new instructions, using only the built-in compiler clang. Also using git and hg version systems whenever possible so you don't have to go looking at websites to see if there are new versions when you want to update the install. Just tested it all with a new jail on FreeNAS 11.1.

By the way, unlike a default install with pkg, x264 and x265 programs are available for direct use as well as their --help systems.
 
Last edited:

EsTaF

FreeNAS Experienced
Joined
Sep 20, 2013
Messages
130
If a speex decoding needed>
(ffmpeg -i 2049.flv -y -hide_banner -movflags +faststart -c:v copy -c:a aac -b:a 192k converted/test.mp4
Decoder (codec speex) not found for input stream #0:1)

pkg install speex
cd /builds/ffmpeg
gmake clean
./configure --cc=/usr/bin/clang --pkg-config-flags="--static" --enable-static --disable-shared --enable-nonfree --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-avfilter --enable-filters --disable-indevs --disable-outdevs --disable-network --enable-libfreetype --enable-libfontconfig --enable-libfribidi --enable-libspeex
gmake
gmake uninstall
gmake install
gmake clean
 
Joined
Apr 24, 2020
Messages
3
./configure --cc=/usr/bin/clang --pkg-config-flags="--static" --enable-static --disable-shared --enable-nonfree --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-avfilter --enable-filters --disable-indevs --disable-outdevs --disable-ffserver --disable-network --enable-libfreetype --enable-libfontconfig --enable-libfribidi
Following your (outstanding, phenomenal) tutorial, just got this error while trying to run this above command:

Unknown option "--disable-ffserver".
See ./configure --help for available options.

I removed this flag and all went fine.

Thanks a lot for this major contribution!


Matías.-
 

Glorious1

FreeNAS Guru
Joined
Nov 23, 2014
Messages
997
Following your (outstanding, phenomenal) tutorial, just got this error while trying to run this above command:

Unknown option "--disable-ffserver".
See ./configure --help for available options.

I removed this flag and all went fine.

Thanks a lot for this major contribution!

Matías.-
Thanks Matías. I'm surprised it worked as well as it did. Several of the libraries now have new build tools and methods, and my sequence has gradually evolved to keep up with them (including removing --disable-ffserver). I updated the first post with the new stuff. This should ensure that new builds are using the latest versions of everything.
 

HJD

Joined
Dec 23, 2018
Messages
8
Adding to this thread...for those that are interested in a tested and automated version of these instructions, I’ve created a quick script on Github: https://github.com/hjdhjd/build-ffmpeg that should work right out of the box.

Download the script in a new jail and run it. It’ll prompt if there are missing dependencies. Note: the version of ffmpeg it compiles is slightly different than this one, as I have enabled network support, as well as support for opus and SoX codecs.

@Glorious1 - most of the credit goes to you here. I just automated a few things and streamlined a bit. Thanks for a great contribution to the community!

Enjoy!
 

Glorious1

FreeNAS Guru
Joined
Nov 23, 2014
Messages
997
Adding to this thread...for those that are interested in a tested and automated version of these instructions, I’ve created a quick script on Github: https://github.com/hjdhjd/build-ffmpeg that should work right out of the box.
Wow, that's quite a professional-looking script! And fast work.
One update on compiling pkg-config, I found how to specify the target. So you could add to the autogen command:
--prefix="$TARGET" --exec-prefix="$TARGET"
Then it's a bit cleaner, everything gets built in the same place.

Also, I was wondering, since you're running a script, can you just put the commands from the edited multilib.sh directly in your script? Then you don't have to go through the editing and calling. But of course end result will be the same.
 
Last edited:

asmodeus

Newbie
Joined
Jul 26, 2016
Messages
70
Adding to this thread...for those that are interested in a tested and automated version of these instructions, I’ve created a quick script on Github: https://github.com/hjdhjd/build-ffmpeg that should work right out of the box.

Download the script in a new jail and run it. It’ll prompt if there are missing dependencies. Note: the version of ffmpeg it compiles is slightly different than this one, as I have enabled network support, as well as support for opus and SoX codecs.

@Glorious1 - most of the credit goes to you here. I just automated a few things and streamlined a bit. Thanks for a great contribution to the community!

Enjoy!
That's great! I've also (independently - great minds think alike!) created a version to help with my automatic setup based on jailman. Leaving the script here, stay tuned for the jailman part.

Code:
#!/usr/bin/env bash

# This is based on a script by Glorious1 and HJD from
# https://www.ixsystems.com/community/threads/how-to-install-ffmpeg-in-a-jail.39818/
# It was modified to build on 11.3 and run without user input by asmod3us.

set -o errexit   # Exit on most errors
set -o errtrace  # Make sure any error trap is inherited
set -o nounset   # Disallow expansion of unset variables
set -o pipefail  # Use last non-zero exit code in a pipeline

trap "ERR during ffmpeg build" ERR

CORES=$(sysctl -n hw.ncpu)

# see config.yml for packages

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export PATH=$PATH:/usr/local/share
export PKG_CONFIG_PATH=/usr/local/lib:/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig

BUILD=$(mktemp -d -t ffmpeg)
TARGET=/usr/local/ffmpeg
export PATH=$PATH:${TARGET}/bin

rm -f /usr/local/lib/libavcodec* /usr/local/lib/libx2*

mkdir -p "${BUILD}" ${TARGET}

git clone --depth 1 https://github.com/mstorsjo/fdk-aac "$BUILD"/fdk-aac/
git clone --depth 1 https://anongit.freedesktop.org/git/pkg-config "$BUILD"/pkg-config/
git clone --depth 1 http://git.videolan.org/git/x264.git "$BUILD"/x264/
hg clone http://hg.videolan.org/x265 "$BUILD"/x265/
git clone --depth 1 https://git.ffmpeg.org/ffmpeg.git "$BUILD"/ffmpeg/

cd "$BUILD"/fdk-aac
# There is no configure file anymore so have to make it with autoreconf
autoreconf -fiv && \
./configure --prefix="$TARGET" --disable-shared && \
make -j"$CORES" && \
make install

cd "$BUILD"/pkg-config
sed -i '' -e 's/m4_copy(/m4_copy_force(/' glib/m4macros/glib-gettext.m4
./autogen.sh --with-internal-glib --prefix="$TARGET" --exec-prefix="$TARGET"
make -j"$CORES" install clean

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$TARGET/lib/pkgconfig

cd "$BUILD"/x264

sed -i '' -e 's|#\!/bin/bash|#\!/usr/bin/env bash|' configure
./configure --prefix=$TARGET --enable-static --enable-pic
gmake -j"$CORES"
gmake install clean

cd "$BUILD"/x265/build/linux

# shellcheck disable=SC2016
sed -i '' -E \
-e '/cd 12bit/,/cmake/ s|^cmake|cmake -D CMAKE_C_COMPILER=/usr/bin/clang -D CMAKE_CXX_COMPILER=/usr/bin/clang++|' \
-e '/cd \.\.\/8bit/,/cmake/ s|^cmake \.\./\.\./\.\./source|cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ffmpeg/ ../../../source -DENABLE_SHARED=OFF|' \
-e 's/cmake/cmake -j'"$CORES"'/' \
-e 's/(if \[ "\$uname" = "Linux" \])/\1 | [ "$uname" = "FreeBSD" ]/' multilib.sh

./multilib.sh
cd 8bit
make -j"$CORES" install

cp -v ${TARGET}/lib/libx265* /usr/local/lib
cd "$BUILD"/ffmpeg

export CFLAGS="-I${TARGET}/include -I/usr/local/include -I/usr/include"
export LDFLAGS="-L${TARGET}/lib -L/usr/local/lib -L/usr/lib"
export PKG_CONFIG_PATH=${TARGET}/lib:$TARGET/lib/pkgconfig:${PKG_CONFIG_PATH}

./configure prefix=$TARGET --cc=/usr/bin/clang \
--extra-cflags="-I$TARGET/include" --extra-ldflags="-L$TARGET/lib" \
--extra-libs=-lpthread \
--pkg-config-flags="--static" \
--enable-static --disable-shared --enable-libfdk-aac --enable-libx264 \
--enable-libx265 --enable-libfreetype --enable-libfontconfig \
--enable-libfribidi --enable-nonfree --enable-gpl --enable-version3 \
--enable-hardcoded-tables --enable-avfilter --enable-filters --disable-outdevs \
--disable-network --enable-libopus --enable-libsoxr

gmake -j"$CORES"
gmake install


 
Last edited:

HJD

Joined
Dec 23, 2018
Messages
8
@Glorious1 - thanks! I've made a couple of updates to the script to reflect that. Feel free to provide pull requests to improve it too. Really appreciate all your hard work here.

@asmodeus - great minds indeed! Well done. Feel free to merge into mine (or merge mine into yours) to the extent it makes sense. I'm glad to see others provide resources to automate this!
 

ornias

FreeNAS Experienced
Joined
Mar 6, 2020
Messages
138
@HJD Thanks, I'm inspired by your script and will merge a few things. I'll put it on GitHub as a PR for jailman once forked-daapd builds.
Speaking of the devil (me), my first thoughts where also "I want to do something with this"....
Looking forward to your work! ^^
 

Glorious1

FreeNAS Guru
Joined
Nov 23, 2014
Messages
997
For you guys making scripts, just be aware they may need occasional maintenance. At least in the past, installation of the libraries has changed every few months or so. I guess that's why I never pursued a script. Babysitting it I can see right away if something needs troubleshooting.
 

ornias

FreeNAS Experienced
Joined
Mar 6, 2020
Messages
138
For you guys making scripts, just be aware they may need occasional maintenance. At least in the past, installation of the libraries has changed every few months or so. I guess that's why I never pursued a script. Babysitting it I can see right away if something needs troubleshooting.
Thats the nice thing of JailMan, it's designed to make jails throw-away-able. :)

I think thats also why @asmodeus wanted to port it...
 
Top