Created
July 31, 2023 18:01
-
-
Save huevos-y-bacon/9b9b03b91f2ef7c4088b21b65df79b70 to your computer and use it in GitHub Desktop.
CONVERT ALL MP3 FILES IN CURRENT DIRECTORY TO MP4 FILES WITH IMAGE AS BACKGROUND
This file contains 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
#!/usr/bin/env bash | |
# CONVERT ALL MP3 FILES IN CURRENT DIRECTORY TO MP4 FILES WITH IMAGE AS BACKGROUND. | |
# See https://www.bannerbear.com/blog/how-to-convert-audio-to-video-for-youtube-upload-using-ffmpeg/#convert-mp3-to-mp4-with-an-image | |
# (Tested on MacOS) | |
ext=mp3 | |
image=image.jpg | |
mkdir -p mp4 log | |
curr_dir=$(basename "$PWD") | |
echo "Converting all \"*.${ext}\" files to \"*.mp4\" ..." | |
echo "(Output prefix: \"${curr_dir} - \")" | |
echo | |
for f in *."${ext}"; do | |
name=$(basename "${f}" .mp3) | |
output="mp4/${curr_dir} - ${name}.mp4" | |
log="log/${curr_dir} - ${name}.log" | |
echo "Processing \"${f}\" ..." | |
ffmpeg -loop 1 \ | |
-i "${image}" \ | |
-i "${f}" \ | |
-c:v libx264 \ | |
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" \ | |
-shortest "${output}" \ | |
> "${log}" 2>&1 & # parallel | |
done | |
echo | |
echo "Waiting for all jobs to finish ..." | |
wait | |
echo | |
echo "Done!" | |
echo | |
echo "Output files are in \"mp4/\" directory:" | |
ls -b mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment