FFmpeg is a free and open source collection of tools for handling multimedia files. It contains a set of shared audio and video libraries such as libavcodec, libavformat, and libavutil. With FFmpeg, you can convert between various video and audio formats, set sample rates, capture streaming audio/video and resize videos.

This tutorial walks you through installing FFmpeg on CentOS 7.

Prerequisites

In order to be able to add new repositories and install packages on your CentOS system, you must be logged in as a user with sudo privileges.

Installing FFmpeg on CentOS

FFmpeg is not available in CentOS 7 core repositories. You can choose to build the FFmpeg tools from source or to install it using yum from the Nux Dextop repository. We’ll go with the second option.

Perform the following steps to install FFmpeg on CentOS 7:

  1. The Nux repository depends on the EPEL software repository. If the EPEL repository is not enabled on your system, enable it by typing:sudo yum install epel-releaseCopy
  2. Next, import the Repository GPG key and enable the Nux repository’s by installing the rpm package:sudo rpm -v --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.rosudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpmCopy
  3. Once the repository is enabled, install FFmpeg:sudo yum install ffmpeg ffmpeg-develCopy
  4. Verify the FFmpeg installation by running the ffmpeg -version command:ffmpeg -versionCopyAt the time of writing this article, the current version of FFmpeg available in the Nux Dextop repository is 2.8.15.ffmpeg version 2.8.15 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-28) ...Copy

That’s it. FFmpeg has been installed on your CentOS machine.

FFmpeg Examples

In this section, we will look at some basic examples on how to use the ffmpeg utility.

Basic conversion

When converting audio and video files with ffmpeg you do not have to specify the input and output formats. The input file format is auto detected and the output format is guessed from the file extension.

  • Convert a video file from mp4 to webm:ffmpeg -i input.mp4 output.webmCopy
  • Convert an audio file from mp3 to ogg:ffmpeg -i input.mp3 output.oggCopy

Specifying codecs

When converting files you can specify the codecs you want to use with the -c option. The codec can be the name of any supported decoder/encoder or a special value copy which simply copies the input stream.

  • Convert a video file from mp4 to webm using the libvpx video codec and libvorbisaudio codec:ffmpeg -i input.mp4 -c:v libvpx -c:a libvorbis output.webmCopy
  • Convert an audio file from mp3 to ogg encoded with the libopus codec.ffmpeg -i input.mp3 -c:a libopus output.oggCopy

Conclusion

You have successfully installed FFmpeg on your CentOS 7. You can now visit the official FFmpeg Documentation page and learn how to use FFmpeg to convert and your video and audio files.