diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e608139 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +ffmpeg-python +music21 \ No newline at end of file diff --git a/src/images_to_video.md b/src/images_to_video.md new file mode 100644 index 0000000..6143741 --- /dev/null +++ b/src/images_to_video.md @@ -0,0 +1,22 @@ +Write a timestamp file like this + +```concat.txt +ffconcat version 1.0 +file 0.png +duration 97 +file 97.png +duration 81 +file 178.png +duration 64 +file 242.png +duration 54 +file 296.png +duration 67 +file 363.png +``` + +where duration is in seconds + +```bash +ffmpeg -f concat -i concat.txt -vf "fps=25,format=yuv420p" -vsync vfr output.webm +``` \ No newline at end of file diff --git a/src/images_to_video.sh b/src/images_to_video.sh new file mode 100644 index 0000000..c0f4568 --- /dev/null +++ b/src/images_to_video.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +IN=$1 +[[ $IN ]]|| IN="concat.txt" +FILES=$(cat $IN | grep file | awk '{print $2}') + +echo $FILES + +# Get the larger width and height of all the images +WIDTH=$(identify -format "%w\n" $FILES | sort -nr | head -1) +HEIGHT=$(identify -format "%h\n" $FILES | sort -nr | head -1) + +echo $WIDTH x $HEIGHT + +# Center all the images and pad them to the larger width and height +# Set the border color to the dominant color of the image +for f in $FILES; do + convert $f -gravity center -background none -extent ${WIDTH}x${HEIGHT} -bordercolor $(convert $f -format "%[pixel:p{0,0}]" info:) -border 0x0 $f +done \ No newline at end of file diff --git a/src/mscz_to_mp3.py b/src/mscz_to_mp3.py index d4ab5c4..df6ef7f 100644 --- a/src/mscz_to_mp3.py +++ b/src/mscz_to_mp3.py @@ -5,7 +5,7 @@ import os MSCORE="mscore" -REMOVE_MID_FILES=False +REMOVE_MID_FILES=True def get_elements(stream, classe): @@ -79,19 +79,26 @@ def __main__(): OUT=sys.argv[2] os.makedirs(OUT, exist_ok=True) - # Create midi file - subprocess.call([MSCORE, SCORE, "-o", f"{OUT}/{basename(SCORE)}.mid"]) + if SCORE.split(".")[-1] == "mscz": + # Create midi file + MIDI_SCORE=f"{OUT}/{basename(SCORE)}.mid" + subprocess.call([MSCORE, SCORE, "-o", MIDI_SCORE]) + elif SCORE.split(".")[-1] in ["mid", "midi"]: + MIDI_SCORE=SCORE + else: + print(f"Unknown file extension {SCORE.split('.')[-1]}") + exit(1) - midi_files = separate_instruments(f"{OUT}/{basename(SCORE)}.mid", OUT) + midi_files = separate_instruments(MIDI_SCORE, OUT) for file in midi_files: change_instrument(file, file) print("=== Creating audios ===") - #create_audios(midi_files, OUT) + create_audios(midi_files, OUT) if REMOVE_MID_FILES: - os.remove(f"{OUT}/{basename(SCORE)}.mid") + os.remove(MIDI_SCORE) for file in midi_files: os.remove(file) diff --git a/src/set_audio.sh b/src/set_audio.sh index 9e16898..2e384c6 100755 --- a/src/set_audio.sh +++ b/src/set_audio.sh @@ -1,24 +1,18 @@ #!/bin/bash -IN=recordings/le_roi.mkv +usage () { + echo "Usage: $0 " + exit 1 +} + +IN=$1 +[[ $IN ]] || usage $0 + AUDIOS=out OUT=videos -#TEMPO=90 -#ADDED_TEMPS=3 -#TEMP_DIR=$(mktemp -d) - -#OFFSET=$(bc <<< "scale=20; 60.0/$TEMPO * $ADDED_TEMPS") - -mkdir -p "$VIDEOS" +mkdir -p "$OUT" add_audio () { - #temp_file=$TEMP_DIR/$(basename $2) - #echo temp: $temp_file - #ffmpeg -i $2 \ - # -ss $OFFSET \ - # -acodec copy \ - # $temp_file - ffmpeg -y \ -i $1 \ -i $2 \ @@ -26,8 +20,6 @@ add_audio () { -map 0:v:0 \ -map 1:a:0 \ $3 - - #rm $temp_file } add_audio "$IN" "$AUDIOS/instrument_1.mp3" "$OUT/soprane.mkv"