Last active
September 23, 2017 17:26
-
-
Save andrewshulgin/a22e8dcd109adaa3c513 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
VIDEO=${1} | |
IMAGE=${2} | |
TITLE=${3} | |
TEXT=${4} | |
NAME=${5} | |
TIME_FROM_END=${6} | |
OUTPUT=${7} | |
FRAME_FONT="frame-font.ttf" | |
FRAME_COLOR="#313781" | |
CONTENT_FONT="content-font.ttf" | |
CONTENT_BG="#f0bb09" | |
CONTENT_COLOR="#ffffff" | |
UUID=$(cat /proc/sys/kernel/random/uuid) | |
RESIZED_IMAGE="/tmp/${UUID}-image.png" | |
FRAME_IMAGE="/tmp/${UUID}-frame.png" | |
CONTENT_IMAGE="/tmp/${UUID}-content.png" | |
DURATION=$(ffprobe -v quiet -print_format csv="p=0" -show_entries format=duration "${VIDEO}") | |
END_TIME=$(echo "${DURATION} - ${TIME_FROM_END}" | bc ) | |
convert "${IMAGE}" -resize 242x242 -size 242x242 xc:none +swap -gravity center -composite "${RESIZED_IMAGE}" | |
convert -background transparent -font "${FRAME_FONT}" \ | |
-size 290x64 -splice 0x28 -gravity north -fill "${FRAME_COLOR}" -pointsize 20 caption:"${TITLE}" -append \ | |
-size 242x242 xc:none -append \ | |
-size 290x76 -gravity center -pointsize 42 caption:"${NAME}" -append \ | |
"${FRAME_IMAGE}" | |
convert -size 218x212 -border 12x15 -background "${CONTENT_BG}" -bordercolor "${CONTENT_BG}" -gravity west \ | |
-font "${CONTENT_FONT}" -fill "${CONTENT_COLOR}" -pointsize 24 caption:"${TEXT}" \ | |
"${CONTENT_IMAGE}" | |
rm -f "${OUTPUT}" | |
ffmpeg -i "${VIDEO}" -loop 1 -i "${FRAME_IMAGE}" -loop 1 -i "${RESIZED_IMAGE}" -loop 1 -i "${CONTENT_IMAGE}" \ | |
-filter_complex "\ | |
[1:v]trim=duration=20[frame];\ | |
[2:v]trim=duration=20[content0];\ | |
[3:v]trim=duration=20,format=pix_fmts=yuva420p,fade=t=in:st=16:d=1:alpha=1[content1];\ | |
[content0][content1]overlay=0:0[content];\ | |
[frame][content]overlay=28:94[overlay];\ | |
[0:v][overlay]overlay=26:210:enable='between(t,0,${END_TIME})'" \ | |
-codec:v libx264 -preset slow -pix_fmt yuv420p -codec:a copy "${OUTPUT}" | |
rm "${RESIZED_IMAGE}" "${FRAME_IMAGE}" "${CONTENT_IMAGE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment