Other features associated with FFmpeg are:

  • It supports several common and uncommon image, audio, and video formats.
  • It supports media and interfaces such as compact discs, Advanced Linux Sound Architecture (ALSA), OpenAL (input only), Windows DirectShow e.t.c
  • It supports filters that include; Resampling, Pass/Stop filters, Equalizer, Dynamics, Distortion, Filtering e.t.c

The libraries shipped with FFmpeg are:

  • Libavutil: utility library to aid portable multimedia programming
  • Libavfilter: used for enhancing and editing filters through a Gstreamer-like filter graph.
  • Libavdevice: provides a generic framework for grabbing from and rendering to many common multimedia input/output devices
  • Libavcodec: an audio/video codec library
  • Libavformat (Lavf): an audio/video container mux
  • Libswscale: performs highly optimized image scaling and colorspace and pixel format conversion operations.
  • Libswresample: performs highly optimized audio resampling, re-matrixing, and sample format conversion operations.

Let’s plunge in and learn how to install and use FFmpeg on Rocky Linux 9 / AlmaLinux 9.

1. Add the RPM Fusion Repository

By default, the FFmpeg is not provided in the Rocky Linux 9 / AlmaLinux 9 repositories. We need to add an extra RPM Fusion repository.

First, enable the EPEL repository and PowerTools(CRB)

sudo dnf install epel-release
sudo dnf config-manager --set-enabled crb

Now add the RPM Fusion repo on Rocky Linux 9 / AlmaLinux 9:

sudo dnf install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm -y
sudo dnf install --nogpgcheck https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm -y

2. Install FFmpeg on Rocky Linux 9 / AlmaLinux 9

Now, FFmpeg can be installed on Rocky Linux 9 / AlmaLinux 9 by executing the command:

sudo dnf install ffmpeg ffmpeg-devel

Dependency Tree:

Dependencies resolved.
================================================================================
 Package           Arch   Version                  Repository              Size
================================================================================
Installing:
 ffmpeg            x86_64 5.0.1-2.el9              rpmfusion-free-updates 1.6 M
 ffmpeg-devel      x86_64 5.0.1-2.el9              rpmfusion-free-updates 758 k
Installing dependencies:
 SDL2              x86_64 2.0.20-2.el9             appstream              606 k
 ffmpeg-libs       x86_64 5.0.1-2.el9              rpmfusion-free-updates 7.6 M
 intel-mediasdk    x86_64 21.3.5-1.el9             epel                   2.6 M
 libaom            x86_64 3.2.0-4.el9              epel                   1.6 M
 libass            x86_64 0.15.2-1.el9             epel                   111 k
 libavdevice       x86_64 5.0.1-2.el9              rpmfusion-free-updates  72 k
 libbluray         x86_64 1.3.1-1.el9              epel                   170 k
 libdav1d          x86_64 0.9.2-1.el9              epel                   473 k
 libdecor          x86_64 0.1.0-3.el9              appstream               40 k
 libjxl            x86_64 0.6.1-8.el9              epel                   899 k
 libmodplug        x86_64 1:0.8.9.0-13.el9         epel                   171 k
 libmysofa         x86_64 1.2.1-1.el9              epel                    42 k
 libopenmpt        x86_64 0.6.4-1.el9              epel                   638 k
 libudfread        x86_64 1.1.2-2.el9              epel                    33 k
 libva             x86_64 2.11.0-4.el9             appstream              102 k
 libvdpau          x86_64 1.4-6.el9                appstream               16 k
 libvmaf           x86_64 2.3.0-2.el9              epel                   177 k
 ocl-icd           x86_64 2.2.13-4.el9             appstream               51 k
 openal-soft       x86_64 1.19.1-16.el9            appstream              533 k
 opencore-amr      x86_64 0.1.5-14.el9             rpmfusion-free-updates 173 k
 soxr              x86_64 0.1.3-11.el9             epel                    82 k
 srt-libs          x86_64 1.4.4-1.el9              epel                   291 k
 svt-av1-libs      x86_64 0.8.7-2.el9              epel                   1.5 M
 vapoursynth-libs  x86_64 57-1.el9                 epel                   503 k
 vid.stab          x86_64 1.1.0-14.20201110gitf9166e9.el9
                                                   epel                    49 k
 vo-amrwbenc       x86_64 0.1.3-16.el9             rpmfusion-free-updates  76 k
 x264-libs         x86_64 0.163-5.20210613git5db6aa6.el9
                                                   rpmfusion-free-updates 682 k
 x265-libs         x86_64 3.5-3.el9                rpmfusion-free-updates 1.2 M
 xvidcore          x86_64 1.3.7-7.el9              rpmfusion-free-updates 254 k
 zimg              x86_64 3.0.3-1.el9              epel                   275 k
 zvbi              x86_64 0.2.35-15.el9            epel                   413 k
Installing weak dependencies:
 jxl-pixbuf-loader x86_64 0.6.1-8.el9              epel                    53 k
 vmaf-models       noarch 2.3.0-2.el9              epel                   227 k

Transaction Summary
================================================================================
Install  35 Packages

Total download size: 24 M
Installed size: 104 M
Is this ok [y/N]: y

Once the installation is successful, check the installed version.

$ ffmpeg -version
ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11 (GCC)
.......

You can also get detailed information with the command:

$ rpm -qi ffmpeg
Name        : ffmpeg
Version     : 5.0.1
Release     : 2.el9
Architecture: x86_64
Install Date: Sun 07 Aug 2022 11:24:47 AM CEST
Group       : Unspecified
Size        : 2217452
License     : GPLv3+
Signature   : RSA/SHA256, Wed 06 Apr 2022 02:34:41 PM CEST, Key ID 7403ea33296458f3
Source RPM  : ffmpeg-5.0.1-2.el9.src.rpm
Build Date  : Tue 05 Apr 2022 04:03:57 PM CEST
Build Host  : buildvm-02.online.rpmfusion.net
Packager    : RPM Fusion
Vendor      : RPM Fusion
URL         : http://ffmpeg.org/
Summary     : Digital VCR and streaming server
Description :
FFmpeg is a complete and free Internet live audio and video
broadcasting solution for Linux/Unix. It also includes a digital
VCR. It can encode in real time in many formats including MPEG1 audio
and video, MPEG4, h263, ac3, asf, avi, real, mjpeg, and flash.

3. Use FFmpeg on Rocky Linux 9 / AlmaLinux 9

Once installed, as shown above, you can now use FFmpeg to perform a variety of functions. In this guide, we will cover the basic FFmpeg use.

A. Getting Video Information

To get the video information with FFmpeg, use -i flag.

ffmpeg -i example-video.mp4 -hide_banner

The -hide_banner option is used to hide any unnecessary information about the video.

For example:

B. Basic Video/Audio conversion

When converting files using FFmpeg, you need to specify the input and output files. Normally, the input file format is automatically detected and the output guessed depending on the provided extension.

  • Convert Video files

You can convert videos from one format to the other. For example, converting an MP4 video file to MOV format, use the command with the syntax:

ffmpeg -i input-video.mp4 output-video.mov

For example:

Once executed, you will have an output file with the desired extension/format.

  • Convert audio files

You can also use FFmpeg to convert audio files from one format to the other. The command has the input file format and the output file format. For example:

ffmpeg -i input.mp3 output.ogg

C. Conversion using codec

The above conversions can also be performed using a specific codec. The codec to be used is specified with the -c flag. For example:

  • Convert Videos

Converting a video file from mp4 to WebM with the libvpx video codec and libvorbis audio codec;

ffmpeg -i input.mp4 -c:v libvpx -c:a libvorbis output.webm
  • Convert audio

Another example is converting an mp3 audio file to Ogg with libopus;

ffmpeg -i input.mp3 -c:a libopus output.ogg
  • Extract Audio from Video

You can also extract an audio file from a video using codecs:

ffmpeg -i video.mp4 -c:a libmp3lame -q:a 0 -map a output_file.mp3

For example:

D. Video Size Processing

At times, you may need a specific video size in order to upload/use it. Instead of downloading any other trimming tool, you can use FFmpeg to achieve this. All you need to do is run the command with the below parameters:

  • -ss: sets the start time of the clip
  • -to: specifies the end time
  • -c: specifies the codec to be used
  • -t: can be used to set the duration of the clip

From the above parameters, you can generate a command to trim a video.F For example

ffmpeg -i example-video.mp4 -ss 00:02:25 -to 00:03:50 -c copy output-trim.mp4

E. Advanced Video Editing with FFmpeg

Aside from conversion and trimming, FFmpeg can be used to edit videos as desired.

Scaling Videos

To scale a video with FFmpeg, use the command with the syntax:

ffmpeg -i example-video.mp4 -vf scale=1920:1080 output-scale.mp4

In the above command:

  • -vf: specifies the video filter used on the video
  • scale: sets the scale sizes needed on the output video.

Combine multiple videos

You can use FFmpeg to combine a list of videos with the same codec. All you need to do is create a .txt file with the list of videos to be combined and use the command below to combine them;

ffmpeg -f concat -i my-video-list.txt -c copy sum-output.mp4

In the above command, the concat parameter combines the files.

Rotate Videos

To rotate a video with FFmpeg, use the command with the syntax:

ffmpeg -i example-video.mp4 -vf "transpose=2" output-rotate.mp4

Where:

  • transpose=0: flips vertically(default)
  • transpose=1: rotates the video 90 degrees clockwise
  • transpose=2: rotates the video 90 degrees counterclockwise
  • transpose=3: Flips the video vertically

For example, to rotate the video 180 degrees clockwise, you need to specify the transpose parameter twice:

ffmpeg -i example-video.mp4 -vf "transpose=2,transpose=2" output-rotate.mp4

Create Animated GIFs

You can also convert a video into Animated GIFs. For example:

ffmpeg -i example-video.mp4 output-gif.gif

You may need to customize the GIF using various parameters such as scaling e.t.c:

ffmpeg -ss 00:01:15 -i example-video.mp4 -to 10 -r 10 -vf scale=250:-1 output-gif.gif

Extract Frames From a Video

It is also possible to extract frames from a video using FFmpeg. The below command can be used to extract JPEG frames every second from the desired input video:

ffmpeg -i example-video.mp4 -r 1 image-%02d.jpeg

The output file will have two digits, for example, 01.jpeg, 02.jpeg e.t.c. It is also possible to have other formats such as PNGBMP e.t.c

Final Thoughts

From this guide, you are now convinced that FFmpeg is a nifty tool that requires no deep knowledge/professionalism to use. There are many other use cases and examples not captured in this guide. Explore them on your own.  

Kindly check out our web hosting service hoganhost.com.ng