Extract Audio From Video Using FFmpeg on Linux

This guide provides a straightforward walkthrough on how to extract high-quality audio from a video file using FFmpeg on a Linux system. You will learn the essential commands to strip audio without re-encoding for a fast, lossless extraction, as well as how to convert the audio into popular formats like MP3 or WAV. Whether you need to process a single file or batch-process an entire directory, these practical examples will help you get the job done efficiently from your command line.

Understanding the Basic Command Structure

FFmpeg is a powerful command-line tool that handles audio and video manipulation seamlessly. To extract audio, you need to understand the core syntax of an FFmpeg command. The basic template looks like this:

ffmpeg -i input_video.mp4 -vn output_audio.mp3

Here is what each part of that command means:

Method 1: Extract Audio Without Re-encoding (Fastest & Lossless)

If you want to keep the original audio quality and finish the process instantly, you should copy the audio stream directly without re-encoding it. To do this, you first need to identify the audio codec used inside the video container.

You can check the stream details using this command: ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 input_video.mp4

Once you know the codec (for example, AAC), extract it using the -c:a copy flag:

ffmpeg -i input_video.mp4 -vn -c:a copy output_audio.aac

Using -c:a copy bypasses the decoding and encoding phases. This saves CPU cycles, preserves the exact original quality of the audio track, and completes the extraction in a matter of seconds.

Method 2: Extract and Convert to MP3

If you require maximum compatibility across different devices and media players, converting the extracted audio to MP3 is your best option. Because MP3 is a lossy format, you should specify the bitrate to ensure good sound quality.

Run the following command to convert the video’s audio to a high-quality 320 kbps MP3:

ffmpeg -i input_video.mp4 -vn -c:a libmp3lame -b:a 320k output_audio.mp3

Method 3: Extract to Uncompressed WAV Format

For video editing or audio post-production, you might prefer an uncompressed, lossless format like WAV.

Use this command to extract the audio stream into a standard 16-bit PCM WAV file:

ffmpeg -i input_video.mp4 -vn -c:a pcm_s16le output_audio.wav

Advanced: How to Batch Process Multiple Videos

If you have a folder full of video files and want to extract the audio from all of them at once, you can combine FFmpeg with a simple Linux for loop in your terminal.

Navigate to the directory containing your videos and run the following script to convert all .mp4 files into .mp3 files:

for file in *.mp4; do
    ffmpeg -i "$file" -vn -c:a libmp3lame -b:a 256k "${file%.mp4}.mp3"
done

This shell loop takes every file ending in .mp4, strips the video stream, encodes the audio to a solid 256 kbps MP3, and saves it under the original filename but with an .mp3 extension.