17

I'm trying to use ffmkv, which requires a version of ffmpeg that supports zscale.

Their README says this is the default under 18.04, but my version under 20.04 is 4.2.4-1ubuntu0.1, which doesn't seem to include zscale support.

If I run apt-get install ffmpeg, it says ffmpeg is already the newest version (7:4.2.4-1ubuntu0.1). but it's clear from ffmpeg.org that the current stable release is 4.3.2-0.

I tried adding ppa:jonathonf/ffmpeg-4 to pick up the latest, but that fails to update ("doesn't have a Release file").

What's the safest way to update it? Ideally, there's a PPA that will work, that my googling hasn't surfaced. Or, should I be downloading that ffmpeg_4.3.2-0+deb11u2ubuntu1_amd64.deb file and installing it with dpkg?

I'm always paranoid about side-channel installing anything, especially when it involves anything to do with Video. What's the best "won't break future system APT updates" way to install the current stable ffmpeg?

user2671688
  • 353
  • 1
  • 3
  • 9

5 Answers5

12

There are other PPAs with newer ffmpeg. The most recent is FFmpeg 4 - media tool (Xenial & newer) from Rob Savoury. To add this PPA to your system use commands below:

sudo add-apt-repository ppa:savoury1/ffmpeg4
sudo apt-get update
sudo apt-get install ffmpeg

As the result you will get the version with --enable-libzimg compile flag and ffmkv will not complain about "HDR to SDR conversion or resolution changes".

Note: you can search PPAs by yourself using special local application named Y PPA Manager, .

N0rbert
  • 99,918
  • uh-oh - after upgrading ffmpeg, I am just noticing that it broke KDEnlive - now it can't render to mp4 ("Unsupported video codec: libx264"). Do I need to install any other libraries? – user2671688 Aug 30 '21 at 22:19
  • It depends on how KDEnlive was installed. – N0rbert Aug 31 '21 at 06:20
  • It's figured out; it looks like MLT needed to be updated. I just added the kdenlive PPA and upgraded its version, and now it all seems to work – user2671688 Aug 31 '21 at 14:38
  • This version seems to corrupt all of the output files for me. For instance ffmpeg -ss 03:57 -to 07:26 -i TestSeminarFull.mp4 -codec copy TestFirstBit.mp4 creates an output file that doesn't play in vlc or otherwise. – ohnoplus Mar 10 '22 at 18:18
7

Simple solution

  1. Download an already compiled ffmpeg from johnvansickle.com. zscale support is included.
  2. Place the downloaded ffmpeg into your PATH by moving the downloaded ffmpeg into /usr/local/bin or ~/bin (re-login or run source ~/.profile if you move it into ~/bin).

This will not interfere with any system files or other packages. To uninstall simply delete the ffmpeg file.

I'm not a big fan of PPAs. They can be messy, are often overkill, and can cause problems by interfering with the package management system.

llogan
  • 11,868
  • It's not easily maintenable but it's certainly a quick & nice fix. Thanks! – stratis Nov 03 '21 at 08:26
  • I have downloaded the ffmpeg-release-amd64-static.tar.xz, extracted the build into a new folder ffmpeg and uploaded the folder to /usr/local/bin/ffmpeg. Now when trying to start ffmpeg with /usr/local/bin/ffmpeg/ffmpeg I get Permission denied. If I try sudo /usr/local/bin/ffmpeg/ffmpeg I get command not found. How to run ffmpeg? – Avatar Dec 10 '21 at 07:03
  • 1
    Got it running Just needed to change the permission of the executable file ffmpeg to 744. – Avatar Dec 10 '21 at 07:05
  • If you use ffmpeg with PHP and shell_exec(ffmpeg ...) then you need to use file permissions 777. – Avatar Dec 10 '21 at 07:15
  • Of course this is not a flexible and true way of installing packages but for now it solved my problem! I've spent a couple of hours, trying to install in in Docker, and it was like the further I go, the harder it becomes. Thank you! – Frankie Drake Apr 11 '22 at 06:43
  • How safe is this though? – Fabien Snauwaert Jul 21 '22 at 18:16
  • @FabienSnauwaert these are legit static builds of ffmpeg. It's actually linked to on the ffmpeg website. So very safe. But they are missing a WHOLE LOT of stuff: like hardware acceleration, and vmaf. Albeit Vmaf isn't included int he disro builds either, as far as I know. Nor is a lot of other stuff. Best to build your own docker image and build from sources. The ones available on Docker-hub are (somewhat) broke for v6.0. – DataMinion Apr 21 '23 at 14:39
2

Perhaps the best way to get a copy of FFmpeg and the zscale filter is to use, but slightly modify, the excellent FFmpeg trac compilation guide. This guide will not interfere with system libraries.

This can be accomplished in only two easy steps:

1. Install zimg:

When installing the long list of dependencies in the guide add the following to also install zimage:

   mkdir -p ~/ffmpeg_sources && \
   cd ~/ffmpeg_sources && \
   wget https://github.com/sekrit-twc/zimg/archive/refs/tags/release-3.0.2.tar.gz && \
   tar xvf release-3.0.2.tar.gz && \
   cd zimg-release-3.0.2 && \
   ./autogen.sh && \
   ./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \
   make && \
   make install

This installs a local copy of zimg that FFmpeg will pick up when it is compiled.

2. Compile FFmpeg:

Follow the full FFmpeg trac guide and when you reach the section where FFmpeg is compiled simply add the following to the ./configure string:

   --enable-libzimg

And this will be enough to enable the zscale filter.

3. Testing, testing...

FFmpeg itself can be tested for presence of the zscale filter:

andrew@ithaca:~$ ffmpeg -filters 2> /dev/null |grep zscale
 ..C zscale            V->V       Apply resizing, colorspace and bit depth conversion.
andrew@ithaca:~$ 

I tested ffmkv itself with a big upscale in size:

andrew@ithaca:~$ ffmkv --preset 'Up to 4K, original audio, 4GB per hour VBR, HDR' input.mkv output.mkv
Audio is Stream Copy VBR, filesize will be greater than estimated.
Processing pass 1 of VBR video, remaining time is remaining time for pass 1 only.
Process will sit on 100% while ffmpeg closes out functions.
ffmpeg conversion of input.mkv started on 08/30/21 7:53:05 PM
input.mkv has 1248 frames, now converting
ffmpeg: 1253 of 1248 frames at 24 fps, progress: 100% and ETA: 0h 0m 0s     
ffmpeg stopped on 08/30/21 7:54:06 PM

Processing pass 2 of VBR video, remaining time is total remaining time. Process will sit on 100% while ffmpeg closes out functions. ffmpeg conversion of input.mkv started on 08/30/21 7:54:06 PM input.mkv has 1248 frames, now converting ffmpeg: 1253 of 1248 frames at 23 fps, progress: 100% and ETA: 0h 0m 0s
ffmpeg stopped on 08/30/21 7:55:06 PM andrew@ithaca:~$

And all is well :)

andrew.46
  • 38,003
  • 27
  • 156
  • 232
2

There is a snap package for ffmpeg. The current version in the "stable" channel is 4.3.1 but does not list --enable-zimg in its build configuration as printed with -version, so it might not work. However, the "edge" channel of that snap package contains a version based on ffmpeg 4.4 with --enable-zimg. So installing would be as easy as

snap install ffmpeg --channel edge
1

Adding external PPAs is very risky and often they might cause problems with your current installation.

If you are deploying your application and you need an specific version you can use this method.

First we will download the latest gpl static build from one of the official builders BtbN. Then we will extract the file in the /usr/local/ffmpeg and create Symbolic Links to the binaries into the /usr/bin directory.

This a manual installation process. You can create an script following all the steps mentioned here:

1. Remove previous package installed using apt

sudo apt remove --purge --auto-remove -y ffmpeg

2. Create a temporal directory and move to it

mkdir -vp ~/tmp
cd ~/tmp

3. Get the filename and the version

## Define repository name
REPO_NAME='BtbN/FFmpeg-Builds'

Define the URL of the latest release

LR_URL="https://api.github.com/repos/${REPO_NAME}/releases/latest"

Get the latest version

version=$(curl -s "${LR_URL}"
| grep -m 1 ffmpeg-n
| cut -d ':' -f2
| cut -d '-' -f2
| tr -d 'n'
| { read v; echo ${v::-2}; })

Get the filename

dl_filename=$(curl -s "${LR_URL}"
| grep "name.*linux64-gpl-${version}.tar.xz"
| cut -d ':' -f2
| { read n; echo ${n:1:-2}; })

dl_name="${dl_filename::-7}"

4. Download the file

## Download the latest tar.xz
curl -s "${LR_URL}" \
| grep "browser_download_url.*linux64-gpl-${version}.tar.xz" \
| cut -d ':' -f 2,3 \
| tr -d '"' \
| wget -qi - -O $dl_filename

5. Define package installation paths

pkg_path='/usr/local/ffmpeg'
pkg_lib_path='/usr/lib/ffmpeg'

6. Extract and install the downloaded version

sudo rm -rf $pkg_path && tar -xvf $dl_filename
sudo mv -v $dl_name $pkg_path

7. Add binary files to system binary and library directories

sudo ln -sv "${pkg_path}" "${pkg_lib_path}"
sudo ln -sv "${pkg_lib_path}/bin/ffmpeg" '/usr/bin/ffmpeg'
sudo ln -sv "${pkg_lib_path}/bin/ffplay" '/usr/bin/ffplay'
sudo ln -sv "${pkg_lib_path}/bin/ffprobe" '/usr/bin/ffprobe'

8. Test your new version.

ffmpeg -version | grep 'ffmpeg version'

Now you can create a script named ffmpeg-install-latest.sh:

#!/bin/bash

Define package name

PKG_NAME='ffmpeg'

Define system local path

LOCAL_PATH='/usr/local'

Define system library path

LIB_PATH='/usr/lib'

Define system binary path

BIN_PATH='/usr/bin'

Define user home dir

USER_HOME_DIR=$(getent passwd ${SUDO_USER:-$USER} | cut -d: -f6)

Define repository name

REPO_NAME='BtbN/FFmpeg-Builds'

Define URL releases

RELEASES_URL="https://api.github.com/repos/${REPO_NAME}/releases"

Define URL of the latest release

LR_URL="https://api.github.com/repos/${REPO_NAME}/releases/latest"

LR_URL="${RELEASES_URL}/latest"

Define temporal directory

TMP_DIR='tmp'

Move to the temporal directory

tmp_path="${USER_HOME_DIR}/${TMP_DIR}" mkdir -vp $tmp_path cd $tmp_path

Get the latest version and build

full_version=$(curl -s "${LR_URL}"
| grep -m 1 ffmpeg-n
| cut -d ':' -f2
| cut -d '-' -f2
| tr -d 'n')

version="${full_version::-2}" build="${full_version:4:1}"

echo 'Latest version: '$full_version

Get the filename

dl_filename=$(curl -s "${LR_URL}"
| grep "name.*linux64-gpl-${version}.tar.xz"
| cut -d ':' -f2
| { read n; echo ${n:1:-2}; })

dl_name="${dl_filename::-7}"

echo 'File to download: '$dl_filename

Download the latest

Base on: echo $(curl -s "${LR_URL}"" | grep "browser_download_url.ffmpeg-n4.4.1.linux64-gpl-4.4.tar.xz" | cut -d ':' -f 2,3 | tr -d '"')

curl -s "${LR_URL}"
| grep "browser_download_url.*linux64-gpl-${version}.tar.xz"
| cut -d ':' -f 2,3
| tr -d '"'
| wget -qi - -O $dl_filename

Remove previous package installed using apt

status="$(dpkg-query -W --showformat='${db:Status-Status}' ${PKG_NAME} 2>&1)" if [ $? = 0 ] || [ "${status}" = installed ]; then sudo apt remove --purge --auto-remove -y "${PKG_NAME}" fi

Define package installation paths

pkg_path="${LOCAL_PATH}/${PKG_NAME}" pkg_lib_path="${LIB_PATH}/${PKG_NAME}"

Extract and install the downloaded version

sudo rm -rf $pkg_path && tar -xvf $dl_filename sudo mv -v $dl_name $pkg_path

Add binary files to system binary and library directories

sudo ln -sv "${pkg_path}" "${pkg_lib_path}" sudo ln -sv "${pkg_lib_path}/bin/ffmpeg" "${BIN_PATH}/ffmpeg" sudo ln -sv "${pkg_lib_path}/bin/ffplay" "${BIN_PATH}/ffplay" sudo ln -sv "${pkg_lib_path}/bin/ffprobe" "${BIN_PATH}/ffprobe"

Test your new version.

ffmpeg -version | grep 'ffmpeg version'

Teocci
  • 4,665