Alex Leko
All content on this blog was fully or partially created using local AI (Apple MLX).

How to convert MP4 to MP3 using FFmpeg

  • ffmpeg
  • mp3
  • mp4
  • audio
  • conversion
  • commandline

FFmpeg lets you extract and convert MP4 video streams into MP3 audio files from the command line.

Basic command

Extract audio from an MP4 file and encode it as an MP3 using variable bitrate:

ffmpeg -i input.mp4 -vn -acodec libmp3lame -q:a 0 output.mp3
  • -i input.mp4: Input video file.
  • -vn: Disables video processing.
  • -acodec libmp3lame: Uses the LAME MP3 encoder.
  • -q:a 0: Sets audio quality to maximum (0 is best quality; 2 offers a balance between - size and quality).
  • output.mp3: Output filename.

To use constant bitrate (CBR) for fixed file sizing and consistent playback compatibility:

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

The -b:a 320k option forces a 320 kbps bitrate.

Audio options

  • Convert to mono: Add -ac 1 to reduce file size.
  • Set sample rate: Add -ar 44100 to specify the sample rate in Hz.
  • Keep metadata: Add -map_metadata 0 to transfer tags from the source MP4.

Example retaining metadata:

ffmpeg -i input.mp4 -vn -acodec libmp3lame -q:a 0 -map_metadata 0 output.mp3

Best practices

  • Test commands on a short clip before running batch jobs or processing large files.
  • Use -q:a 0 for maximum audio fidelity or -q:a 2 to save storage space.
  • Check that the MP4 input stream is compatible with the LAME encoder.