Skip to content

Instantly share code, notes, and snippets.

@cmpadden
Created June 29, 2024 03:45
Show Gist options
  • Select an option

  • Save cmpadden/6fddaff1830563d18df924183b4337e7 to your computer and use it in GitHub Desktop.

Select an option

Save cmpadden/6fddaff1830563d18df924183b4337e7 to your computer and use it in GitHub Desktop.
Convert midi files to instrument backed video
#!/bin/bash
TARGET_MIDI_FILE="bk_cove.mid"
STATIC_COVER_IMAGE="${HOME}/Downloads/bk_cover_image.jpg"
# open midi file in Logic Pro
open "$TARGET_MIDI_FILE"
# use `osascript` to bounce the project, converting midi tracks to an audio file
osascript \
-e 'tell application "Logic Pro" to activate' \
-e 'tell application "System Events" to keystroke "b" using command down' \
-e 'tell application "System Events" to keystroke return' \
-e 'delay 1' \
-e 'tell application "System Events" to keystroke "'"$TARGET_MIDI_FILE"'"' \
-e 'delay 1' \
-e 'tell application "System Events" to keystroke return'
# create an `mp4` with a static cover image and an `m4a` backing track
ffmpeg \
-i "${TARGET_MIDI_FILE}.m4a" \
-loop 1 \
-i "$STATIC_COVER_IMAGE" \
-c:v libx264 \
-c:a copy \
-shortest \
-t 120 \
"${TARGET_MIDI_FILE}.mp4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment