Skip to content

Instantly share code, notes, and snippets.

@mdirkse
Last active July 10, 2018 23:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdirkse/dc1f237a2818158a390414b28bd9b0b1 to your computer and use it in GitHub Desktop.
Save mdirkse/dc1f237a2818158a390414b28bd9b0b1 to your computer and use it in GitHub Desktop.
Generate a slideshow from jpg's with audio
#!/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