Created
December 21, 2022 23:42
-
-
Save axeldelafosse/5e67b9bf50c4c85f582fc7616d1d72ac to your computer and use it in GitHub Desktop.
Convert an audio file to a video file, ready to upload on YouTube. WAVE, AIFF and FLAC to MP4 using a loop of the cover art in H.264 and audio in ALAC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SUPPORTED_FILES=('.wav' '.wave' '.aif' '.aiff' '.flac') | |
INPUT_PATH=$1 | |
BASE_PATH=${INPUT_PATH##*/} | |
FILE_EXTENSION= | |
FILE_NAME= | |
setup_file() { | |
FILE_EXTENSION=$1 | |
FILE_NAME=${BASE_PATH%"$FILE_EXTENSION"} | |
} | |
case "$INPUT_PATH" in | |
*.wave) | |
setup_file .wave | |
;; | |
*.wav) | |
setup_file .wav | |
;; | |
*.aiff) | |
setup_file .aiff | |
;; | |
*.aif) | |
setup_file .aif | |
;; | |
*.flac) | |
setup_file .flac | |
;; | |
*) | |
echo "Invalid input file format. File should be one of:" ${SUPPORTED_FILES[@]} | |
exit 1 | |
;; | |
esac | |
# Create the directory | |
mkdir -p "$FILE_NAME" | |
# Get the cover | |
ffmpeg -i "$INPUT_PATH" -an -vcodec copy "$FILE_NAME/cover.jpg" -y | |
# Extract metadata | |
# ffmpeg -i "$INPUT_PATH" -f ffmetadata "$FILE_NAME/metadata.txt" -y | |
mutagen-inspect "$INPUT_PATH" > "$FILE_NAME/metadata.txt" | |
# Create the video | |
ffmpeg -loop 1 -framerate 1 -i "$FILE_NAME/cover.jpg" -i "$INPUT_PATH" -c:v libx264 -preset veryslow -tune stillimage -crf 0 -r 10 -vf "scale=-1:1080:flags=lanczos" -c:a alac -movflags +faststart -shortest -fflags +shortest -max_interleave_delta 100M "$FILE_NAME/$FILE_NAME.mp4" -y | |
# Move the original file to the directory | |
mv "$INPUT_PATH" "$FILE_NAME/$FILE_NAME$FILE_EXTENSION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment