Add images_to_video
This commit is contained in:
parent
2301af6e2d
commit
8adea8f37d
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
ffmpeg-python
|
||||
music21
|
22
src/images_to_video.md
Normal file
22
src/images_to_video.md
Normal file
@ -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
|
||||
```
|
19
src/images_to_video.sh
Normal file
19
src/images_to_video.sh
Normal file
@ -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
|
@ -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)
|
||||
|
||||
if SCORE.split(".")[-1] == "mscz":
|
||||
# Create midi file
|
||||
subprocess.call([MSCORE, SCORE, "-o", f"{OUT}/{basename(SCORE)}.mid"])
|
||||
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)
|
||||
|
||||
|
@ -1,24 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
IN=recordings/le_roi.mkv
|
||||
usage () {
|
||||
echo "Usage: $0 <file.webm|mp4|...>"
|
||||
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"
|
||||
|
Loading…
Reference in New Issue
Block a user