Skip to content

Instantly share code, notes, and snippets.

@fardjad
Last active February 28, 2024 16:37
Show Gist options
  • Save fardjad/4f31a3eafc7fdd0fd34a to your computer and use it in GitHub Desktop.
Save fardjad/4f31a3eafc7fdd0fd34a to your computer and use it in GitHub Desktop.
[How to Convert m4a Files to mp3, Preserving Bitrate and ID3 Tags Using ffmpeg] #ffmpeg #bash

How to convert m4a files to mp3, preserving bitrate and id3 tags using ffmpeg

Prerequisites

  1. ffmpeg
  2. cygwin (on windows)

Commands

cd /path/to/m4a/files
mkdir out
for f in *.m4a; do 
    ffmpeg -i "$f" -ab `ffmpeg -i "$f" 2>&1 | grep Audio | awk -F', ' '{print $5}' | cut -d' ' -f1`k -map_metadata 0 -id3v2_version 3 -write_id3v1 1 "out/${f%%.*}.mp3"
done

References

http://blog.kdecherf.com/2012/01/14/ffmpeg-converting-m4a-files-to-mp3-with-the-same-bitrate http://jonhall.info/tips_and_tricks/id3_tags_on_windows_using_ffmpeg

@RatCheese1608
Copy link

I'm not sure if the commands used in Mac is 100% the same in linux, but perhaps with correct dependencies it is possible on Mac, and also possible in windows with some command changes.

@teridon
Copy link

teridon commented Dec 17, 2023

This command assumes there are no periods (.) in the filenames other than for the extension. Bad assumpition!
Replace:
"out/${f%%.*}.mp3"
with
"out/${f%.*m4a}.mp3"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment