How To

Convert Video to MP3 on Linux with FFmpeg

FFmpeg is the Linux swiss army knife for audio and video conversion. Ripping the audio track out of a video file into a playable MP3 is a one-line command once you know the right flags. This guide covers the install on Rocky Linux 10 (which needs RPM Fusion) and Ubuntu 24.04, then walks through the actual extraction for MP4, MKV, and WebM sources.

Original content from computingforgeeks.com - post 1066

The workflow is the same for every source format because FFmpeg demuxes the container first and then re-encodes the audio stream. The only thing that changes is the input filename.

Tested April 2026 with FFmpeg 7.1.2 on Rocky Linux 10.1 (via RPM Fusion), libmp3lame backend, GCC 14 build

Step 1: Install FFmpeg

Ubuntu 24.04 and Debian 13 ship FFmpeg in their default repositories, so a single apt call is enough:

sudo apt update
sudo apt install -y ffmpeg

Rocky Linux 10, AlmaLinux 10, and RHEL 10 do not carry FFmpeg in the base repos because of patent concerns around several codecs. RPM Fusion provides a complete build that includes libmp3lame. Install the RPM Fusion release metapackage first, then FFmpeg:

sudo dnf install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-10.noarch.rpm
sudo dnf install -y ffmpeg

RPM Fusion free is safe to enable alongside the official Rocky repos. It layers cleanly and only provides packages that the base repos deliberately skip. Confirm the install and the version:

ffmpeg -version | head -3

The version line confirms FFmpeg 7.x and the GCC build tag:

ffmpeg version 7.1.2 Copyright (c) 2000-2025 the FFmpeg developers
built with gcc 14 (GCC)

FFmpeg 7.x ships the current libmp3lame, libfdk-aac, libx264, libx265, and libvpx encoders along with full AV1 (libaom, libsvtav1, librav1e) and VVC support. Nothing about MP3 extraction requires the bleeding edge, but it’s nice to know you’re not stuck on an ancient 3.x branch.

Step 2: Inspect the source file

Before converting, use ffprobe (ships with FFmpeg) to confirm the file actually has an audio stream you can extract:

ffprobe -hide_banner input.mp4

The output lists each stream with its codec, sample rate, and bitrate. If there’s an AAC audio stream, you can re-encode it into MP3. If there’s only a video stream with no audio, there’s nothing to extract.

Step 3: Extract audio to MP3 from an MP4

The basic command is four flags: -i for the input file, -vn to drop the video stream, -c:a libmp3lame to pick the MP3 encoder, and -q:a for the variable-bitrate quality level (0 is best, 9 is worst, 2 is a good default):

ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3

The last few lines of the output report the final audio track size, duration, and effective bitrate:

[out#0/mp3 @ 0x556befba7c00] video:0KiB audio:24KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 1.313740%
size=      25KiB time=00:00:05.01 bitrate=  40.5kbits/s speed= 324x

The speed value at the end tells you how many seconds of audio got encoded per wall-clock second. 324x means the extraction was running 324 times faster than real-time on the test host. A file command against the result confirms it’s a valid MP3:

file output.mp3

The MPEG layer III descriptor confirms a valid MP3 bitstream:

output.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 56 kbps, 44.1 kHz, Monaural

Step 4: Use a fixed bitrate

For a specific target bitrate instead of the variable-bitrate quality scale, use -b:a:

ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 320k output-320.mp3

320 kbps is the highest meaningful MP3 bitrate. 192 or 256 is a good middle ground for music. For spoken audio, podcasts, or lectures, 128 kbps or even 96 kbps is plenty and cuts the file size in half.

Step 5: MKV and WebM sources work the same way

The container format of the input is irrelevant to ffmpeg. MKV from Handbrake and WebM from browser screen captures use the same command with a different filename:

ffmpeg -i input.mkv -vn -c:a libmp3lame -q:a 4 output.mp3
ffmpeg -i input.webm -vn -c:a libmp3lame -q:a 4 output.mp3

FFmpeg reads the internal codec automatically and re-encodes it to MP3 regardless of whether the source was AAC, Opus, FLAC, or Vorbis. WebM commonly contains Opus audio, which actually sounds better than MP3 at the same bitrate, so consider extracting to .opus or .m4a (AAC) instead when the output is for private use and compatibility with MP3 isn’t a hard requirement.

Step 6: Batch convert an entire folder

A shell loop handles the case where you have a folder full of MP4 lectures and want MP3s for a long drive:

mkdir -p mp3-output
for f in *.mp4 *.mkv *.webm; do
  [ -e "$f" ] || continue
  out="mp3-output/${f%.*}.mp3"
  ffmpeg -hide_banner -loglevel error -i "$f" -vn -c:a libmp3lame -q:a 2 "$out"
  echo "$f -> $out"
done

The -hide_banner and -loglevel error flags keep FFmpeg quiet so the loop’s output is readable. [ -e "$f" ] || continue skips missing glob patterns when there are no files of that type in the directory.

Going further

FFmpeg can do much more than format conversion: crop, trim, watermark, re-mux without re-encoding (-c copy is the trick), and generate thumbnails. For the full feature matrix, the official man ffmpeg is the authoritative reference and it’s installed alongside the binary. If you need a sshfs mount or rsync pipeline to feed videos onto the box before conversion, both tools pair naturally with a scripted ffmpeg batch job.

For a lean Rocky 10 server that also runs FFmpeg, follow our post-install tips first so the base system is in shape. If the FFmpeg install is for a media collection, you’ll probably also want Plex Media Server on Rocky 10 or a general-purpose media pipeline. The qemu-img tool is the same idea applied to VM disk images instead of audio files.

Related Articles

Debian How To Install Xen Orchestra on Ubuntu / Debian Monitoring Install LibreNMS on Rocky Linux 10 / AlmaLinux 10 AlmaLinux Install Podman and Buildah on Rocky Linux 10 / AlmaLinux 10 Ubuntu How To Install MS SQL Server on Ubuntu 24.04

3 thoughts on “Convert Video to MP3 on Linux with FFmpeg”

  1. Works great thank you. Is there a way to have it convert a folder with sub folders? I have a Plex server setup and all movie files are in its own sub folder and it would be handy to convert sub folders instead of moving each movie into 1 folder then moving back. Thank you

    Reply

Leave a Comment

Press ESC to close