Last active
July 10, 2018 23:14
-
-
Save mdirkse/dc1f237a2818158a390414b28bd9b0b1 to your computer and use it in GitHub Desktop.
Generate a slideshow from jpg's with audio
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
#!/bin/bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
DOCKER_WORKDIR="/slideshow" | |
WORKDIR="work" | |
# Parameters | |
AUDIO_FILE="music.mp3" | |
DIM="800x800" # Slideshow dimensions | |
PICS_DIR="pics" | |
# Create the work dir | |
mkdir -p "${DIR}/${WORKDIR}" | |
# Copy over all images so we don't mess with the originals | |
x=1 | |
for i in $DIR/$PICS_DIR/*jpg; do | |
counter=$(printf %03d $x) | |
cp "$i" "${DIR}/${WORKDIR}/img${counter}.jpg" | |
x=$((x+1)) | |
done | |
# Make sure no one side of an image is larger than 600px | |
docker run -ti --rm \ | |
-v "${DIR}:${DOCKER_WORKDIR}" \ | |
-w "${DOCKER_WORKDIR}" \ | |
-u "$(id -u):$(id -g)" \ | |
--net=none --log-driver none \ | |
v4tech/imagemagick \ | |
mogrify \ | |
-resize "${DIM}" \ | |
-gravity center \ | |
-extent "${DIM}" \ | |
-background "rgb(0,0,0)" \ | |
$WORKDIR/*.jpg | |
# Generate the slideshow along with the audio | |
docker run -ti --rm \ | |
-v "${DIR}:${DOCKER_WORKDIR}" \ | |
-w "${DOCKER_WORKDIR}" \ | |
-u "$(id -u):$(id -g)" \ | |
--net=none --log-driver none \ | |
jrottenberg/ffmpeg:4.0-scratch -y \ | |
-framerate 1 \ | |
-i "${WORKDIR}/img%03d.jpg" \ | |
-i "${AUDIO_FILE}" \ | |
-shortest \ | |
-c:a copy "${WORKDIR}/slideshow.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment