Skip to content

Instantly share code, notes, and snippets.

@zmilonas
Created April 29, 2018 18:35
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 zmilonas/deb0d14dba88424bcaa6971cb851927a to your computer and use it in GitHub Desktop.
Save zmilonas/deb0d14dba88424bcaa6971cb851927a to your computer and use it in GitHub Desktop.
Turn a bunch of folders with clips form 1 second everyday app into a proper video with dates. This script is specifically for co.touchlab.android.onesecondeveryday app (off by one in date's month, directory structure)
#!/bin/sh
# This was specially created for 1 Second Everyday Android App output
# This takes individual 'second' clips from files, applies date on them and outputs the merged video
# For this to run properly you need to have ffmpeg --with-libfreetype installed
# run this script in a main directory in which the subdirectories are like ./20180302/clip.mp4
# Created on 29/04/2018 by Zachary Milonas
RESTORE=$(echo '\033[0m')
GREEN=$(echo '\033[00;32m')
LBLUE=$(echo '\033[01;34m')
ask() # https://unix.stackexchange.com/a/110681
{
eval $1="$2"
if [ -z "${!1}" ]; then
read -p "$3" $1
fi
}
if type -p ffmpeg >/dev/null 2>&1 ; then
if ! ffmpeg -h 2>&1 >/dev/null | grep -q "enable-libfreetype"; then
echo "In order to run this you need ffmpeg built with libfretype"
echo "You have to rebuild ffmpeg with --enable-libfreetype"
if type -p brew >/dev/null 2>&1; then
echo "You can use homebrew for example: ${LBLUE}brew reinstall ffmpeg --with-freetype${RESTORE}"
fi
exit 0
fi
else
echo "You need to install ffmpeg (with --enable-libfreetype) in order to use this script"
exit 0
fi
ask FILE_PREFIX "$1" "Year (file prefix): "
ask FONTFILE "$2" "Font file (/path/to/file): "
MONTHS=("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")
FONTCOLOR="white"
FONTSIZE="70"
LOGLEVEL="fatal" # https://superuser.com/a/438280
OUTPUT="1SE_${1}.mp4"
mkdir -p tmp
echo "" > list.txt
for F in ${1}*/*.mp4; do
Y=${F:0:4}
M=${F:4:2}
D=${F:6:2}
OUTPUT_FILENAME="tmp/text_${F}"
DATE="$D ${MONTHS[$M]} $Y"
echo "${GREEN}Processing: ${RESTORE}$F - ${LBLUE}${DATE}${RESTORE}"
ffmpeg -i $F -y -loglevel ${LOGLEVEL} -hide_banner $F -vf drawtext="fontfile=${FONTFILE}: \
text='${DATE}': fontcolor=${FONTCOLOR}: fontsize=${FONTSIZE}: x=90: y=h-180" -codec:a copy ${OUTPUT_FILENAME}
echo "file '${OUTPUT_FILENAME}'" >> list.txt;
done
echo "${GREEN}Generating ouput file${RESTORE}"
ffmpeg -loglevel ${LOGLEVEL} -f concat -i list.txt -c copy ${OUTPUT}
# cleanup
rm -rf tmp/ list.txt
echo "${GREEN}Video done! find it at $(pwd)/${OUTPUT}${RESTORE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment