0
import mido

# This file has 2.2 billion notes, and 16 GB big.
midi = mido.MidiFile("<filename>") 

# This is a new file, but will write 16 GB big data.
outputmidi = mido.MidiFile("<filename>") 

for tk in midi.tracks:
    for i in range(0, len(midi.tracks), 2): # Loop and merge track
        try:
            outputmidi.tracks.append(mido.merge_track(midi.tracks[i:i+1])) # Merge Track
        except IndexError:
            outputmidi.tracks.append(mido.merge_track(midi.tracks[i:])) # Merge last Track

outputmidi.save("...") # Save the merge result

You can find this midi on Youtube by searching for "funcky star black midi" and download it.

When I open it, my machine crashed!

How to change the defult setup to fix this problem?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • This might just be a limitation of the library you're using. Have you read the library's documentation, or submitted a bug report? – Blckknght Jun 26 '22 at 05:28
  • I just checked and indeed, the docs do say that [the whole file is deliberately being loaded into memory immediately](https://mido.readthedocs.io/en/latest/midi_files.html#opening-a-file). You may need a different library to handle such an unusually large midi file. – Blckknght Jun 26 '22 at 05:33

0 Answers0