Skip to content

Instantly share code, notes, and snippets.

@olibartfast
Created June 16, 2025 09:03
Show Gist options
  • Select an option

  • Save olibartfast/1120fa3d858bbe3710931c2349a0f9b2 to your computer and use it in GitHub Desktop.

Select an option

Save olibartfast/1120fa3d858bbe3710931c2349a0f9b2 to your computer and use it in GitHub Desktop.
horizontally stacking two videos using FFmpeg's hstack filter
#!/bin/bash
# Check if at least two inputs are provided
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <video1> <video2> [output_file]"
exit 1
fi
# Assign inputs to variables
video1="$1"
video2="$2"
output="${3:-composed.mp4}" # Default to composed.mp4 if $3 is not provided
# Check if input files exist
if [ ! -f "$video1" ]; then
echo "Error: $video1 does not exist"
exit 1
fi
if [ ! -f "$video2" ]; then
echo "Error: $video2 does not exist"
exit 1
fi
# Run FFmpeg command
ffmpeg -i "$video1" -i "$video2" -filter_complex "[1:v][0:v]scale2ref=oh*mdar:h=in_h:[v1][v0];[v0][v1]hstack[vo]" -map "[vo]" "$output"
# Check if FFmpeg command was successful
if [ $? -eq 0 ]; then
echo "Videos successfully combined into $output"
else
echo "Error: FFmpeg command failed"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment