Download this video and put it in the same folder as the bash script (should be named chroma.mp4) https://mega.nz/file/iQFCGJ6a#kczm4JBL61ouguzvDX5HHY-9oPhBn261ymto7uiBsfI
Created
November 24, 2023 11:39
-
-
Save EsteveSegura/8abbfab9b28aad481bdedb477d752c2b to your computer and use it in GitHub Desktop.
Chayane approve - meme creator
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
#!/bin/bash | |
# Check if the script is executed as root | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root." >&2 | |
exit 1 | |
fi | |
# Check for required software: ImageMagick and ffmpeg | |
check_software() { | |
local software=$1 | |
if ! command -v "$software" >/dev/null 2>&1; then | |
echo "$software is not installed." | |
exit 2 | |
else | |
echo "$software is installed." | |
fi | |
} | |
check_software convert | |
check_software ffmpeg | |
# Initialize flip flag | |
perform_flip=false | |
# Parse command line arguments | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
-flip) perform_flip=true ;; | |
*) url="${1}" ;; # Assume the first non-flag argument is the URL | |
esac | |
shift | |
done | |
# Verify if the URL is provided | |
if [ -z "${url}" ]; then | |
echo "Usage: $0 [-flip] <URL>" | |
exit 3 | |
fi | |
# Define variables | |
destination_path="./" | |
timestamp=$(date +"%Y%m%d%H%M%S") | |
filename="${timestamp}_$(basename "$url")" | |
# Download the image | |
echo "Downloading the image..." | |
if wget "$url" -O "${destination_path}${filename}" > /dev/null 2>&1; then | |
echo "Image downloaded: ${destination_path}${filename}." | |
else | |
echo "Error in downloading: $url" | |
exit 4 | |
fi | |
# Resize the image to a maximum width of 500px | |
echo "Resizing the image..." | |
convert "${destination_path}${filename}" -resize "500x>" "${destination_path}${filename}" | |
# Check if flip is required | |
if [ "${perform_flip}" = true ]; then | |
echo "Flipping the image..." | |
convert "${destination_path}${filename}" -flop "${destination_path}${filename}" | |
fi | |
# Generate the video with chroma keying | |
echo "Processing video..." | |
ffmpeg -i chroma.mp4 -i "${destination_path}${filename}" \ | |
-filter_complex "[0:v]chromakey=color=#00fc3b:similarity=0.12:blend=0.2[ckout];[1:v][ckout]overlay=(W-w)/2:(H-h)/2:format=auto,scale=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p[v]" \ | |
-map "[v]" -map 0:a? -c:v libx264 -crf 23 "${destination_path}${filename}.mp4" > /dev/null 2>&1 | |
# Display the path of the generated file | |
echo "File ready at: ${destination_path}${filename}.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment