Home Linux Commandline Tips How to Extract Audio from Video Files Using FFmpeg

How to Extract Audio from Video Files Using FFmpeg

If you are looking for a free and open-source Linux-based solution for handling streams and multimedia files like videos, audios, and images, then you should strongly consider what FFmpeg has to offer.

The FFmpeg tool requires that its users are familiar with the Linux command-line environment usage in terms of syntax reference, command implementation, and execution.

As for its installation of the Linux operating system distribution you are using, you need to have root/sudoer user privileges to successfully invoke the associated installation command.

Problem Statement

Supposing we have the following video file (rock.mp4) stored on our Linux OS file system.

Sample Video File
Sample Video File

Let us for a moment assume that the video file contains an audio segment that we need on another video animation project we are running on the sideline. Before we consider the solutions under the FFmpeg tool for handling multimedia and stream files, we must make sure this tool is installed on our Linux systems.

Installing FFmpeg in Linux

Depending on the Linux operating system distribution you are using, reference one of the following command to successfully have this tool installed on your Linux OS.

Install FFmpeg in RHEL

On RHEL-based distributions like RHEL, CentOS Stream, Rocky Linux, and AlmaLinux:

$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
$ sudo dnf upgrade
$ sudo subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms"
$ sudo yum update
$ sudo yum install snapd
$ sudo systemctl enable --now snapd.socket
$ sudo ln -s /var/lib/snapd/snap /snap
$ sudo snap install ffmpeg 

On Fedora Linux distribution:

$ sudo dnf makecache 
$ sudo dnf install ffmpeg-free

On Debian distributions like Ubuntu and Linux Mint:

$ sudo apt update && sudo apt upgrade -y
$ sudo apt install ffmpeg

On Arch Linux and Manjaro:

$ sudo pacman -Syu
$ sudo pacman -S ffmpeg

On OpenSUSE Leap:

$ sudo zypper refresh
$ sudo zypper install ffmpeg

On OpenSUSE Tumbleweed:

$ sudo zypper refresh
$ sudo zypper install ffmpeg-4

Using FFmpeg to Extract Audio from Video Files

The final extracted audio needs a container format. For instance, let us go with mp4 format for this tutorial guide.

Before we start extracting the input video file’s audio tracks, we should list the audio streams associated with the video file using the ffprobe tool. This tool is installed together with FFmpeg.

$ ffprobe rock.mp4
List Audio Stream of Video File
List Audio Stream of Video File

We have identified aac as a viable audio stream format. Now, our output audio file will have a name like rock.aac.

To extract all audio stream from video file, use the following command.

$ ffmpeg -i rock.mp4 -map 0:a -acodec copy rock.aac
  • -i points to the input video file.
  • -map 0:a picks available audio streams.
  • -acodec copy copies the picked audio streams (without re-encoding).
Extract Audio from Video File
Extract Audio from Video File

To extract partial audio stream (based on time). Here, we need to be specific with the start time (-ss) of the video file to the end time (-t) of the video file to get an audio fragment/fraction of the video file based on a specific playable duration.

$ ffmpeg -i rock.mp4 -map 0:a -ss 00:03:00 -t 00:00:30.0 -acodec copy audio_fraction.aac
Extract Partial Audio from Video File
Extract Partial Audio from Video File

You might also like to read the following articles:

We can now fully or partially extract audio streams from video files using FFmpeg in Linux.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.