Reputation: 131
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
Upvotes: 12
Views: 11414
Reputation: 2801
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
FFmpeg was never "deprecated"
Upvotes: 3
Reputation: 1462
First install the Timidity package, In Ubuntu just run:
sudo apt-get install -y timidity
Then run this command:
timidity input.mid -Ow -o out.mp3
You can change the format to WAV
or other formats too.
Upvotes: 1
Reputation: 384124
FluidSynth + FFmpeg
An alternative to timidity:
sudo apt install fluidsynth ffmpeg
fluidsynth -a alsa -T raw -F - /usr/share/sounds/sf2/FluidR3_GM.sf2 MIDI_sample.mid |
ffmpeg -f s32le -i - MIDI_sample.mp3
Tested on Ubuntu 20.04, FluidSynth 2.1.1-2, and this MIDI file: https://en.wikipedia.org/wiki/File:MIDI_sample.mid
Upvotes: 2
Reputation: 976
This worked for me:
timidity my_midi_file.mid -Ow -o - | lame - -b 64 my_converted_midi.mp3
running on ubuntu 18.04
Upvotes: 0
Reputation: 605
I ran into a similar issue with MIDI.js not working in a mobile browser. It turned out that I had included the ogg files but was missing the mp3s (for some reason the MIDI.js only provides ogg versions of synth_drum).
Instrument files for all 128 General MIDI sounds can be found at https://github.com/gleitz/midi-js-soundfonts.
Upvotes: 1
Reputation: 191
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
Upvotes: 18