Skip to content

Instantly share code, notes, and snippets.

@dupontgu
Created September 30, 2024 21:45
Show Gist options
  • Save dupontgu/322b54f90bfcc0152ac7ca5ce313d38f to your computer and use it in GitHub Desktop.
Save dupontgu/322b54f90bfcc0152ac7ca5ce313d38f to your computer and use it in GitHub Desktop.
Shell script to embed a landscape video inside a blurred, portrait version of itself.
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <input_video>"
exit 1
fi
input_file="$1"
if [ -z "$2" ]; then
output_file="final_output.mp4"
else
output_file="$2"
fi
VIDEO_WIDTH=1080
VIDEO_HEIGHT=1920
BLUR_SIGMA=20
blurred_bg="background.mp4"
# Chat-GPT (4o) helped get started with these:
# Step 1: Create the blurred, zoomed, and cropped background video
ffmpeg -i "$input_file" -vf "scale=${VIDEO_WIDTH}:${VIDEO_HEIGHT}:force_original_aspect_ratio=increase,crop=${VIDEO_WIDTH}:${VIDEO_HEIGHT},gblur=sigma=${BLUR_SIGMA}" -c:a copy "$blurred_bg"
# Step 2: Resize the original video and overlay it onto the blurred background
ffmpeg -i "$blurred_bg" -i "$input_file" -filter_complex "[1:v]scale=${VIDEO_WIDTH}:-1,format=rgba,colorchannelmixer=aa=1.0[fg];[0:v][fg]overlay=0:(main_h-overlay_h)/2" -c:a copy "$output_file"
rm "$blurred_bg"
echo "Output saved as $output_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment