To install ffmpeg for a video site, install the distribution's ffmpeg package (which includes ffprobe), confirm that it was built with the libx264 H.264 encoder, and make sure PHP is allowed to run it through proc_open. On Ubuntu and Debian this is one apt command; on AlmaLinux and other RHEL-family systems you first enable the EPEL and RPM Fusion repositories. The whole process takes a few minutes.
What you need and why
A tube script uses two programs from the ffmpeg project:
- ffprobe reads a file's duration, resolution, codecs and frame rate so the script knows what it is working with.
- ffmpeg does the work: converting uploads to web-friendly MP4, scaling to each quality, grabbing thumbnails, cutting preview clips and adding watermarks.
For video that plays in every browser and phone, the encoder must include libx264, the standard H.264 encoder. Most distribution packages include it, but some minimal or "free-only" builds do not, so always check.
Ubuntu and Debian
The packages in the official repositories include libx264 and are kept up to date with security fixes:
sudo apt update
sudo apt install -y ffmpeg
This installs both ffmpeg and ffprobe in /usr/bin. Recent releases such as Ubuntu 22.04 and 24.04 and Debian 12 ship versions that are more than adequate for web encoding.
AlmaLinux, Rocky Linux and RHEL 8 or 9
ffmpeg is not in the base repositories because of codec licensing, so enable EPEL and RPM Fusion Free first. On version 9:
sudo dnf install -y epel-release
sudo dnf config-manager --set-enabled crb
sudo dnf install -y https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm
sudo dnf install -y ffmpeg
On version 8, replace crb with powertools and use the -8 RPM Fusion package. If dnf config-manager is missing, install dnf-plugins-core first.
Static builds as an alternative
If you cannot add repositories, a static build is a single download that runs without dependencies. Download a recent build for your CPU architecture from a reputable source linked from the official ffmpeg website, extract it, and copy ffmpeg and ffprobe into /usr/local/bin. Static builds do not update themselves, so note the version and check for updates periodically.
Check that it works
Run these commands as the same user your site runs under where possible:
ffmpeg -version
ffprobe -version
ffmpeg -hide_banner -encoders | grep libx264
which ffmpeg ffprobe
The third command should print a line mentioning libx264. If it prints nothing, your build lacks the H.264 encoder and you need a different package. The last command gives the full paths, which you may need to enter in your script's settings.
A quick real-world test is to encode a short sample file:
ffmpeg -i sample.mov -t 10 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k -movflags +faststart test.mp4
If test.mp4 plays in a browser, the encoder is working. The video encoding settings guide explains what each of those options does.
Allow PHP to run ffmpeg
PHP starts ffmpeg as a separate process, usually with proc_open. Some hosts disable it for security. Check from the command line:
php -r "var_dump(function_exists('proc_open'));"
php -i | grep disable_functions
If proc_open is listed under disable_functions, remove it from that line in php.ini. Remember that the command-line PHP and the web PHP (php-fpm or the Apache module) often use different ini files. Run php --ini for the command-line one, and check the web one with a temporary phpinfo() page that you delete afterwards. Restart php-fpm or Apache after any change.
If your host will not enable proc_open, you are probably on shared hosting that is not suitable for encoding. The hosting requirements guide explains what to look for instead.
Common problems
- "ffmpeg: not found" from the site but it works over SSH. Cron and php-fpm may have a shorter PATH. Use the full path, such as
/usr/bin/ffmpeg. - Encodes stop part way. Check disk space and memory, and look at the job log for the ffmpeg error message.
- Very slow encoding. Use a faster preset, encode fewer qualities, or add CPU cores.
- Odd colours or no sound on some phones. Make sure output uses the
yuv420ppixel format and AAC audio.
How Tube Site Script helps
Tube Site Script requires ffmpeg and ffprobe with libx264 and PHP's proc_open, and its web installer checks for them before installing, so you find a missing piece immediately rather than at your first upload. Once they are in place, the background worker encodes each video into the H.264 qualities you choose in the admin, up to 4K, and creates 10 thumbnails, a hover preview clip and timeline thumbnails. A watermark can be burned in during the same pass.
The worker runs from cron by default and can run permanently as a systemd service on busy networks, with several workers side by side. Failed jobs can be re-run from the command line with reprocess --failed. See the Tube Site Script features for the rest of the video tools.
Frequently asked questions
Does the apt version of ffmpeg include libx264?
On Ubuntu and Debian the standard ffmpeg package is built with libx264. You can confirm it with ffmpeg -encoders and look for libx264 in the list.
Why does ffmpeg work over SSH but not from my site?
PHP may have proc_open disabled, or the web and cron environments may not have ffmpeg in their PATH. Check disable_functions for the web PHP and use the full path to the binaries.
Should I use a static ffmpeg build?
A static build is a good fallback when you cannot add package repositories. The trade-off is that it does not receive security updates automatically, so you need to replace it yourself.
