Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert midi to mp3

I have got one midi file and i want to play that file on web page, currently i am using midi.js player for playing but it is not working on mobile browsers.

Please guide me how to play that file or else how can i play midi or convert it into mp3

Here is my code

  $data = fopen ($midi, 'rb');
 $size= filesize($midi);
 $contents = fread ($data, $size);
 fclose($data);
 $encoded= base64_encode($contents);

 $encode = "'data:audio/midi;base64,".$encoded."=='";

and finally passing base64 value to midi.js

like image 621
chitranjna Avatar asked Apr 30 '13 08:04

chitranjna


2 Answers

Guessing you're on a linux machine... The simplest way is to play it with timidity and pipe the output ffmpeg:

timidity song.mid -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k song.mp3
like image 128
phreaknerd Avatar answered Nov 05 '22 08:11

phreaknerd


If you're using Linux, use avconv instead of ffmpeg because ffmpeg is being deprecated:

timidity input.midi -Ow -o - | avconv -i - -acodec libmp3lame -b 64k output.mp3

Or lame:

timidity -Ow -o - input.midi | lame - output.mp3
like image 41
Vinicius José Latorre Avatar answered Nov 05 '22 08:11

Vinicius José Latorre