Extracting audio from a video file is a common task for content creators, podcast producers, and multimedia enthusiasts. Whether you're looking to repurpose the audio from a video interview, create a podcast from a video series, or simply want to enjoy the soundtrack of a movie, FFmpeg provides powerful tools to extract audio from video files quickly and efficiently.
Why you may want to extract audio from video file
There are several reasons why you might want to extract audio from a video file:
- Podcast creation: Convert video interviews or presentations into audio-only podcasts.
- AI processing: You may want to take the audio file as an input for an AI model to do some processing like tagging, summarization or content moderation.
- Music extraction: Isolate soundtracks or background music from videos.
- Accessibility: Create audio versions of video content for visually impaired audiences.
- File size reduction: When only the audio is needed, extracting it can significantly reduce file size.
- Audio editing: Separate audio for independent editing before recombining with video.
Let's explore how to use FFmpeg to extract audio from video files in various formats.
Basic audio extraction
The simplest way to extract audio from a video file is to use FFmpeg's audio copying feature using the copy flag. This is very fast because it doesn't transcode the audio at all, retaining the quality of the original track:
ffmpeg -i input_video.mp4 \
-vn -acodec copy \
output.m4aBreakdown of the command:
- -i input_video.mp4: Specifies the input video file
- -vn: Disables video output
- -acodec copy: Copies the audio codec without re-encoding
- output.m4a: Name of the output audio file (format determined by codec)
This command will extract the audio in its original format. If the video contains AAC audio, the output will be an M4A file.
If you've made it this far, you might be interested in the Mux Video API to extract audio from a video file.
Learn more about Mux VideoExtracting audio in specific formats
You may want to extract the audio in a specific format, regardless of the source. Here are some common scenarios:
Extracting audio as MP3
ffmpeg -i input_video.mp4 \
-vn -acodec libmp3lame -q:a 4 \
output.mp3In this command:
- -acodec libmp3lame: Specifies the MP3 encoder
- -q:a 4: Sets the audio quality (0-9, lower is better)
Extracting audio as WAV
ffmpeg -i input_video.mp4 \
-vn -acodec pcm_s16le \
output.wavHere, pcm_s16le specifies Pulse Code Modulation which is a fancy word for uncompressed audio. s16le stands for Signed 16 bit Little Endian. This is the most common format for raw audio. Another popular option is pcm_s24le which is similar but only with 24 bit audio. WAV is the container format.
Extracting audio as FLAC
ffmpeg -i input_video.mp4 \
-vn -acodec flac \
output.flacFLAC is a lossless format, preserving audio quality while providing some compression.
Extracting a specific audio stream
Before extracting any tracks, you might want to inspect the video file to see how many tracks there are and to figure out which one you want to grab. ffprobe is a tool that is installed with FFmpeg and can be used to inspect a file like this:
ffprobe input-file.mp4Which will list out all of the streams available in the video, it will look something like this:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input-video.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41isomavc1
creation_time : 2015-08-07T09:13:02.000000Z
Duration: 00:00:30.53, start: 0.000000, bitrate: 411 kb/s
Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 480x270 [SAR 1:1 DAR 16:9], 301 kb/s, 30 fps, 30 tbr, 30 tbn (default)
Metadata:
creation_time : 2015-08-07T09:13:02.000000Z
handler_name : L-SMASH Video Handler
vendor_id : [0][0][0][0]
encoder : AVC Coding
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 112 kb/s (default)
Metadata:
creation_time : 2015-08-07T09:13:02.000000Z
handler_name : L-SMASH Audio Handler
vendor_id : [0][0][0][0]Stream #0:1 here is a reference to the stream number. The leading 0 is the input ID, which will always be 0 if we only have one input file. The audio track in this file is stream 1, which is the second stream as 0 is the video in this example.
Once you you know which track you want, you can extract it like this:
ffmpeg -i input_video.mp4 \
-map 0:a:1 -vn \
output.m4aThe -map 0:a:1 option selects the second audio stream (streams are zero-indexed).
Trimming audio during extraction
You can extract only a portion of the audio:
ffmpeg -i input_video.mp4 \
-vn -ss 00:01:30 -t 00:00:30 \
output.m4aThis extracts 30 seconds of audio starting at 1 minute 30 seconds into the video.
Changing audio properties during extraction
You can modify audio properties like sample rate and bit rate:
ffmpeg -i input_video.mp4 \
-vn -ar 44100 -ac 2 -ab 192k \
output.mp3This command sets the audio to 44.1 kHz sample rate, mixes to 2 channels, and 192 kbps bit rate.
Choosing the right audio format
Different audio formats have different benefits and drawbacks:
Why choose MP3:
Benefits:
- Widely compatible
- Good compression (smaller file size)
Drawbacks:
- Lossy compression (some quality loss)
Why choose WAV:
Benefits:
- Uncompressed audio
- Highest Quality and Lossless
- Widely supported in audio production
Drawbacks:
- Large file size and no compression
Why choose AAC:
Benefits:
- Better quality than MP3 at similar bit rates
- Good compatibility with mobile devices
Drawbacks:
- Less widely supported than MP3
Why choose FLAC:
Benefits:
- Lossless compression (no quality loss)
- Smaller file size than WAV
Drawbacks:
- Less widely supported than lossy formats
Tips for effective audio extraction
- Choose the right format: Consider your intended use. MP3 for general purposes, WAV for editing, FLAC for archiving.
- Mind the quality settings: Higher quality settings result in larger files. Find the balance that suits your needs.
- Check your source: The output quality can't exceed the input quality. Extracting high-quality audio from a low-quality video won't improve the audio.
- Preserve metadata: Use the -map_metadata 0 option to keep relevant metadata from the video file.
- Normalize audio: If extracting from multiple sources, consider normalizing the audio levels for consistency.
- Batch processing: For multiple files, consider writing a script to automate the extraction process.
- Verify the output: Always check the extracted audio to ensure it meets your quality standards and contains the expected content.
Remember that the quality of your audio output is dependent on the quality of the audio in the source file. Always start with the highest quality available for the best results. As you become more comfortable with FFmpeg's audio extraction capabilities, you can experiment with more advanced options to fine-tune your output and streamline your workflow.
Extracting audio from video files with Mux
If you have videos hosted with the Mux Video API you can extract audio when static renditions are enabled on the assets. Static renditions give you access to files in mp4 format and an audio-only version of the video. See the guide for enabling static MP4 renditions.
Audio extraction FAQs
Should I use -acodec copy or re-encode when extracting audio?
Use -acodec copy when you want the exact audio from the video without quality loss or processing time—it's instant because no encoding happens. Re-encode (using -acodec libmp3lame or similar) when you need a different format, want to change bitrate/sample rate, or need to normalize audio levels. If the source audio is already in your desired format (like AAC from an MP4), always use copy for speed and quality preservation.
How do I know what audio codec is in my video file?
Run ffprobe input.mp4 to inspect the file. Look for the audio stream entry which shows the codec (AAC, MP3, AC3, etc.), sample rate, channels, and bitrate. You can also use ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 input.mp4 for just the codec name.
What bitrate should I use for extracted audio?
For MP3: 128 kbps for acceptable quality, 192 kbps for good quality, 320 kbps for highest quality. For AAC: 128 kbps often matches MP3 at 192 kbps due to better compression. For podcasts or voice content, 64-96 kbps AAC or 96-128 kbps MP3 is often sufficient. Don't exceed the source bitrate—extracting at 320 kbps from 128 kbps source audio won't improve quality.
Can I extract multiple audio tracks from a video with multiple languages?
Yes. First, use ffprobe to identify available audio streams and their indices. Then use -map to select specific streams: ffmpeg -i input.mp4 -map 0:a:0 english.mp3 -map 0:a:1 spanish.mp3 extracts the first audio track to one file and second to another. You can extract all audio tracks simultaneously in a single FFmpeg command.
Why is my extracted audio out of sync with the original video timing?
This rarely happens with simple extraction but can occur when using -ss to trim or when the source has variable frame rate issues. Using -acodec copy preserves exact timing. If re-encoding, ensure you're not accidentally changing sample rates or using conflicting timing options. For trimmed extractions, verify that your -ss and -t values match the video portions you want.
What's the difference between AAC and M4A?
AAC is an audio codec (the compression format), while M4A is a container format (file wrapper) that typically contains AAC audio. When you extract audio with -acodec copy from an MP4 with AAC audio, use .m4a or .aac extension—both work, but M4A is more commonly supported by players. They contain the same audio data.
How do I batch extract audio from multiple video files?
Write a shell script that loops through video files: for file in *.mp4; do ffmpeg -i "$file" -vn -acodec copy "${file%.mp4}.m4a"; done extracts audio from all MP4 files in a directory. For production environments processing many files, consider video APIs that provide audio extraction at scale without managing FFmpeg infrastructure yourself.
Can I extract audio while also keeping the video file?
Yes, extraction doesn't modify the original video—it creates a new audio file. The source video remains unchanged. If you want both the original video and a separate audio file, simply extract the audio to a different filename. For workflows requiring both, some video APIs provide direct access to audio tracks without requiring manual extraction.