Skip to content

Instantly share code, notes, and snippets.

@huevos-y-bacon
Created July 31, 2023 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huevos-y-bacon/9b9b03b91f2ef7c4088b21b65df79b70 to your computer and use it in GitHub Desktop.
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
#!/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