Extract Audio Tracks From Video Files

Overview | Extract | Convert

You can extract audio tracks (m4a, mp3, wav,...) from video files (mp4, mov, flv, avi,...) by installing FFmpeg software and using some commands from the command line.

An extracted audio track will have zero resampling loss because you're using FFmpeg to make a copy of the file that has the video and subtitle streams stripped out. The copy you create will only contain the audio stream data and possibly some metadata.

Extract an AAC-encoded audio track from an MP4 video file:

 ffmpeg -i input.mp4 -c:a copy -vn -sn output.m4a

This works for all common video and audio formats. If you're unsure which audio codec has been used to encode the audio in a particular video file, you can determine it using ffprobe.

Probe a Flash video file to determine how its audio stream is encoded:

 ffprobe -i input.flv

Installing FFmpeg

Skip to Determining the Audio Format if your computer already has FFmpeg installed.

Installing FFmpeg on Windows is a manual process. On Linux the package you need to install may be libav-tools (or similar) instead of ffmpeg because some distros switched from FFmpeg to Libav for a while. On macOS there are multiple installation methods.

Installing FFmpeg on Windows

FFmpeg is distributed as a .zip archive. You can download the latest version (Windows 32-bit or 64-bit Static) via the FFmpeg Builds page.

  1. Extract the archive.
  2. Rename the directory to ffmpeg.
  3. Move the directory to C:\
  4. Edit Windows' PATH variable and add ";C:\ffmpeg\bin" to the end of it:
  Start
   -> right-click Computer
   -> Advanced system settings
   -> Environment Variables
   -> PATH

or

 Control Panel
  -> System 
  -> Advanced system settings 
  -> Environment variables
  -> PATH

Installing FFmpeg on Linux

Installing FFmpeg on your distribution should be like installing any other package:

 sudo apt install ffmpeg

or

 sudo yum install ffmpeg

or

 sudo dnf install ffmpeg

or

 pacman -S ffmpeg-git

...or something similar for your distribution.

The libav Transitional Package

If an ffmpeg package appears to be unavailable, check to see if your system uses Libav instead.

For example, you would install Ubuntu 14.04's libav-tools package or Linux Mint 17's libav-tools package with

 sudo apt-get install libav-tools

If your system uses libav instead of FFmpeg you'll need to substitute command names in the examples shown on this page.

 ffmpeg -> avconv
 ffprobe -> avprobe

If you prefer to install FFmpeg instead of Libav it's available via PPA.

Installing FFmpeg on macOS

Compiled static FFmpeg binaries for MacOS are available via FFmpeg.org. You'll need to put them somewhere and adjust your system PATH. Multiple approaches are discussed on this page at Superuser.

Determining the Audio Format

Generally speaking, extracting the audio track is a two-step process:

  1. Determine the audio format of the audio track.
  2. Use ffmpeg to copy the video stream with the video and subtitles disabled (removed).

The reason you need to know the audio format is because you want your audio file's filename to have the correct extension (.mp3 for MP3, .m4a for AAC, etc.).

You can use ffprobe to find out what type of audio stream is in the video file:

 ffprobe input.flv

You will see information about the audio stream that looks similar to this:

 Stream #0.1: Audio: mp3, [...]

or

 Stream #0:1: Audio:aac (LC) (mp4a [...]

Now that you know the audio format you can name the audio file accordingly.

Copying the Audio Track

Here we're extracting an MP3 audio track from a .flv video file:

 ffmpeg -i input.flv -c:a copy -vn -sn output.mp3

These are the four options used:

 -i <filename(s)>: Specifies the file(s) for ffmpeg to read from.
 -c:a copy: Tells ffmpeg to copy the stream.
 -vn: Disables video.
 -sn: Disables subtitles.

Extracting a Portion of a Track

You can extract a portion of the audio stream by specifying a start time and duration. Here's an example where 30 seconds of audio is extracted starting at the one-minute mark:

   ffmpeg -i input.flv -c:a copy -ss 00:01:00 -t 00:00:30 -vn -sn output.mp3

 -ss: start stream
 -t: time

Editing and Converting/Transcoding

Extracting an exact copy of the audio track isn't always optimal. Sometimes you can achieve a better result using Audacity audio-editing software to make some changes. The process is simple:

  1. Open the file (File -> Open...).
  2. Optionally edit the track.
  3. Export the audio file (File -> Export...).

Learn more here: Convert Audio Tracks From Video Files

References

Arch Linux has an excellent FFmpeg wiki page worth visiting even if you don't run Arch Linux.

How to extract an audio track from an MP4 video file on Windows? - Super User
With FFmpeg, which you can download as a static build (no installation needed) for every major OS
How to convert FLV,MP4 to M4A, M4B losslessly (demux/extract AAC audio track to iPod) - Audio/video stream recording forums
Some FLV and MP4 video files use AAC audio tracks. Instead of converting FLV and MP4 to M4A, M4V you can demux or extract AAC from FLV, MP4 to avoid recompression (and quality loss).
How to Install FFmpeg on Windows - Adaptive Samples
Understandably, most people are a little lost when it comes to using command-line programs like FFmpeg. But don’t worry, I was there not too long ago, and now I’ll try explain as thoroughly as I can how to install it and start using it.
Page last modified on February 01, 2021
Powered by PmWiki