Skip to content

Instantly share code, notes, and snippets.

@pixelchai
Created August 31, 2019 00:22
Show Gist options
  • Save pixelchai/5c6c2796f4814ba8534668411a9a40dc to your computer and use it in GitHub Desktop.
Save pixelchai/5c6c2796f4814ba8534668411a9a40dc to your computer and use it in GitHub Desktop.
Creates timelapse from video, and padds resultant video appropriately such that its aspect ratio is equal to the input drawing - for Instagram
#!/bin/sh
img=$1
vid=$2
fps=${3:-25}
out=${4:-timelapse.mp4}
echo "insta-timelapse:"
if [ $# -lt 2 ]; then
echo "USAGE: ./insta-timelapse img_path vid_path [target_fps=$fps] [out_path=$out]"
exit
fi
echo "img: $img"
echo "vid: $vid"
echo "fps: $fps"
echo "out: $out"
dim=($(identify -format "%w\n%h" $img))
if [ ${dim[0]} -lt ${dim[1]} ]; then
ffmpeg -r $fps -i "$vid" -an -vf "setpts=PTS/$fps,pad=iw:iw*\(${dim[1]}/${dim[0]}\):(ow-iw)/2:(oh-ih)/2:color=white" $out
elif [ ${dim[0]} -gt ${dim[1]} ]; then
ffmpeg -r $fps -i "$vid" -an -vf "setpts=PTS/$fps,pad=ih*\(${dim[0]}/${dim[1]}\):ih:(ow-iw)/2:(oh-ih)/2:color=white" $out
else
ffmpeg -r $fps -i "$vid" -an -vf "setpts=PTS/$fps" $out
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment