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
Probe a Flash video file to determine how its audio stream is encoded:
ffprobe -i input.flv
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.
- Extract the archive.
- Rename the directory to ffmpeg.
- Move the directory to C:\
- Edit Windows' PATH variable and add ";C:\ffmpeg\bin" to the end of it:
Start -> right-click Computer -> Advanced system settings -> Environment Variables -> PATH
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
sudo yum install ffmpeg
sudo dnf install ffmpeg
pacman -S ffmpeg-git
...or something similar for your distribution.
libav Transitional Package
If an ffmpeg package appears to be unavailable, check to see if your system uses Libav instead.
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
Determining the Audio Format
Generally speaking, extracting the audio track is a two-step process:
- Determine the audio format of the audio track.
ffmpegto 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:
You will see information about the audio stream that looks similar to this:
Stream #0.1: Audio: mp3, [...]
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
Editing and Converting/Transcoding
- Open the file (
File -> Open...).
- Optionally edit the track.
- Export the audio file (
File -> Export...).
Learn more here: Convert Audio Tracks From Video Files
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.