Skip to content

Instantly share code, notes, and snippets.

@divisiondeariza
Last active March 8, 2019 00:30
Show Gist options
  • Save divisiondeariza/182629f32e3a3de9800c06fd6a4418e6 to your computer and use it in GitHub Desktop.
Save divisiondeariza/182629f32e3a3de9800c06fd6a4418e6 to your computer and use it in GitHub Desktop.
Well, a little script to make facebook friendly my videos. :)
#!/bin/bash
# Usage:
# bash squarify.sh -i INPUTFILE -t "text" output.mp4
#
# Options
# -i: input file
# -t text to overlay
while echo $1 | grep -q ^-; do
# Evaluating a user entered string!
# Red flags!!! Don't do this
eval $( echo $1 | sed 's/^-//' )="'$2'"
shift 2
done
OUTPUT="$1"
WIDTH=`ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 $i`
HEIGHT=`ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=s=x:p=0 $i`
IMAGE=$(convert -fill dodgerblue -background black -font Roboto-Condensed-Bold -pointsize 72 \
-size "$WIDTH"x -gravity Center \
caption:"$t" -bordercolor black -border 40x40 \
png:- | base64 )
IMG_HEIGTH=`base64 --decode <<< $IMAGE | ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=s=x:p=0 pipe:0`
base64 --decode <<< $IMAGE | ffmpeg -i $i -i pipe:0 -filter_complex "[0:v]scale=-1:iw,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[blurred];[blurred][0:v]overlay=(W-w)/2:(H-h + $IMG_HEIGTH)/2,crop=ih:ih[vid];[vid][1:v]overlay=(W-w)/2:(0)/4" $OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment