Skip to content

Extract audio from a video file with FFmpeg

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.

Link
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:

  1. Podcast creation: Convert video interviews or presentations into audio-only podcasts.
  2. 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.
  3. Music extraction: Isolate soundtracks or background music from videos.
  4. Accessibility: Create audio versions of video content for visually impaired audiences.
  5. File size reduction: When only the audio is needed, extracting it can significantly reduce file size.
  6. 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.

LinkBasic audio extraction

The simplest way to extract audio from a video file is to use FFmpeg's audio copying feature. This method is fast and maintains the original audio quality:

bash
ffmpeg -i input_video.mp4 \ -vn -acodec copy \ output.m4a

Breakdown 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.

LinkExtracting audio in specific formats

You may want to extract the audio in a specific format, regardless of the source. Here are some common scenarios:

LinkExtracting audio as MP3

bash
ffmpeg -i input_video.mp4 \ -vn -acodec libmp3lame -q:a 4 \ output.mp3

In this command:

  • -acodec libmp3lame: Specifies the MP3 encoder
  • -q:a 4: Sets the audio quality (0-9, lower is better)

LinkExtracting audio as WAV

bash
ffmpeg -i input_video.mp4 \ -vn -acodec pcm_s16le \ output.wav

Here, 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.

LinkExtracting audio as FLAC

bash
ffmpeg -i input_video.mp4 \ -vn -acodec flac \ output.flac

FLAC is a lossless format, preserving audio quality while providing some compression.

LinkAdvanced techniques

LinkExtracting a specific audio stream

If your video has multiple audio tracks, you can specify which one to extract:

bash
ffmpeg -i input_video.mp4 \ -map 0:a:1 -vn \ output.m4a

The -map 0:a:1 option selects the second audio stream (streams are zero-indexed).

LinkTrimming audio during extraction

You can extract only a portion of the audio:

bash
ffmpeg -i input_video.mp4 \ -vn -ss 00:01:30 -t 00:00:30 \ output.m4a

This extracts 30 seconds of audio starting at 1 minute 30 seconds into the video.

LinkChanging audio properties during extraction

You can modify audio properties like sample rate and bit rate:

bash
ffmpeg -i input_video.mp4 \ -vn -ar 44100 -ac 2 -ab 192k \ output.mp3

This command sets the audio to 44.1 kHz sample rate, mixes to 2 channels, and 192 kbps bit rate.

LinkChoosing the right format

Different audio formats have different benefits and drawbacks:

LinkMP3:

Benefits:

  • Widely compatible
  • Good compression (smaller file size)

Drawbacks:

  • Lossy compression (some quality loss)

LinkWAV:

Benefits:

  • Uncompressed audio
  • Highest Quality and Lossless
  • Widely supported in audio production

Drawbacks:

  • Large file size and no compression

LinkAAC:

Benefits:

  • Better quality than MP3 at similar bit rates
  • Good compatibility with mobile devices

Drawbacks:

  • Less widely supported than MP3

LinkFLAC:

Benefits:

  • Lossless compression (no quality loss)
  • Smaller file size than WAV

Drawbacks:

  • Less widely supported than lossy formats

LinkTips for effective audio extraction

  1. Choose the right format: Consider your intended use. MP3 for general purposes, WAV for editing, FLAC for archiving.
  2. Mind the quality settings: Higher quality settings result in larger files. Find the balance that suits your needs.
  3. 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.
  4. Preserve metadata: Use the -map_metadata 0 option to keep relevant metadata from the video file.
  5. Normalize audio: If extracting from multiple sources, consider normalizing the audio levels for consistency.
  6. Batch processing: For multiple files, consider writing a script to automate the extraction process.
  7. 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 output is dependent on the quality of your source video. Always start with the highest quality video 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.

LinkExtracting audio from video files with Mux

If you have videos hosted with the Mux Video API you can extract audio when static renditions is 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.

No credit card required to start using Mux.