Extract Audio from Video File using FFmpeg

Extract Audio from Video File using FFmpeg

FFmpeg includes a collection of powerful tools for handling multimedia files, including separating audio streams from video containers. Extracting the audio track into a standalone file is useful when the soundtrack needs to be processed, analyzed, converted, or used independently of the video. This tutorial explains how to extract audio from a video file using FFmpeg.

FFmpeg command can extract and save the original audio stream as a separate file. When stream copying is used, the audio is not decoded and re-encoded, which preserves the original audio data.

Download a sample video for testing:

curl -sSo test.mp4 https://raw.githubusercontent.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4

Before extracting the audio, ffprobe can be used to determine the codec of the first audio stream:

ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 test.mp4

Output:

aac

The audio stream can then be extracted with the following command:

ffmpeg -v error -i test.mp4 -vn -c:a copy audio.aac

Command breakdown:

  • ffmpeg - the command used to process multimedia files.
  • -v error - limits FFmpeg output to error messages while suppressing informational and other non-error messages.
  • -i test.mp4 - specifies the video file that contains the audio stream.
  • -vn - prevents the video stream from being included in the output.
  • -c:a copy - copies the audio stream directly without re-encoding it.
  • audio.aac - specifies the output filename for the extracted audio.

Leave a Comment

Cancel reply

Your email address will not be published.