Skip to content

Instantly share code, notes, and snippets.

@urklc
Created December 4, 2023 07:18
Show Gist options
  • Save urklc/d7eed2367a240a034204061a023b94a7 to your computer and use it in GitHub Desktop.
Save urklc/d7eed2367a240a034204061a023b94a7 to your computer and use it in GitHub Desktop.
scale_video_sh
#!/bin/bash
scaleFactor=0.5
for file in *.mp4; do
# Extract original dimensions
width=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "${file}")
height=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 "${file}")
# Calculate new dimensions
newWidth=$(echo "$width * $scaleFactor" | bc)
newHeight=$(echo "$height * $scaleFactor" | bc)
# Resize video
ffmpeg -i "${file}" -vf "scale=${newWidth}:${newHeight}" "resized_${file}"
rm "${file}"
mv "resized_${file}" "${file}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment