Bulk Midi to Mp3 Converter

In this post we cover crafting a one-liner to bulk convert midi’s to mp3. The reason behind why I needed this was for an event we are hosting in our meetup group. I wanted a way to play old-school midi’s over the web. The easiest way to achieve this is with mp3’s. If you want to check out the files I converted you can see them here.


Here is the command that makes the magic happen.

timidity song.mid -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k song.mp3


  • timidity song.mid -Ow -o –
    • -Ow = Generate RIFF WAVE format output
    • -o - = Send converted output to STDOUT
  • ffmpeg -i – -acodec libmp3lame -ab 64k song.mp3
    • -i - = STDIN input
    • --acodec libmp3lame = use mp3 audio codec
    • -ab 64k = sets audio bitrate.


Here is a Perl one-liner I came up with that bulk performs the operation.

ls *.mid | perl -snlE '$f = $_; system $cmd =~ s`INPUT(?{ $m = "\x{27}$f\x{27}" })|OUTPUT(?{ $m = "\x{27}" . $f =~ s~(.*\.)mid$~${1}mp3~gr . "\x{27}" })`$m`ger;' -- -cmd='timidity INPUT -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k OUTPUT'

Leave a Reply

Your email address will not be published. Required fields are marked *