Share this...

8mm video cassette tape
Image courtesy of Asim18 on Wikipedia.

The great thing about using Linux is that you have a number of command line tools that can accomplish tasks and are generally faster than GUI-based alternatives.

The Linux tool for manipulating video files is ffmpeg. Its official documentation is here and one version of the man file is here

General Use

The format for an ffmpeg command is 

$ ffmpeg <input_file_options> -i <input_file> <output_file_options> <output_file>

-i is used to specify the input file. 

In general, both the input and output files are video files. To extract the audio portion, we can simply specify an audio file for the output file. 

For example, to extract audio into an .mp3 file:

$ ffmpeg -i input.mp4 output.mp3

We can also use some output options to convert to an .ogg file:/samp>

$ ffmpeg -i input.mp4 -vn -acodec libvorbis output.ogg

-vn is the option to disable the video. -acodec libvorbis forces ffmpeg to use the libvorbis codec, which is what gets us an .ogg file.

We can also use the -ar option to adjust the sampling rate. For example, if we wanted to change the audio sampling rate to 22050 Hz, we could use:

$ ffmpeg -i input.mp4 -ar 22050 output.mp3

We can adjust the sampling rate of an .ogg file as well:

$ ffmpeg -i input.mp4 -vn -acodec libvorbis -ar 22050 output.ogg

The ffmpeg command also supports file types such as avi, mkv, and mov as input files. You can even extract audio into a .wav file, which is uncompressed, unlike .mp3 and .ogg.

As you can see, it’s pretty easy to extract audio using the command line if you know just a few simple commands.


Share this...
Except for material released under a Creative Commons License: ©2021 Kenneth John Odle All Rights ReservedPermalink for this article:
https://techblog.kjodle.net/2023/09/14/extract-audio-from-video-using-ffmpeg/