Created
September 1, 2023 08:11
-
-
Save cubuspl42/349b3638998d2b1d4a3a0d8fb2d3d8f3 to your computer and use it in GitHub Desktop.
A script for compressing videos
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 input file is provided | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <input_file>" | |
exit 1 | |
fi | |
# Get input file | |
input_file="$1" | |
# Get the basename without extension | |
input_basename="$(basename "${input_file%.*}")" | |
# Define output file | |
output_file="${input_basename}-compressed.mp4" | |
# Get original resolution and calculate the new resolution | |
original_width=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=nw=1:nk=1 "${input_file}") | |
original_height=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=nw=1:nk=1 "${input_file}") | |
new_width=$(( ${original_width} / 2 )) | |
new_height=$(( ${original_height} / 2 )) | |
# Compress video using H.264 codec and resize resolution | |
ffmpeg -i "${input_file}" -vf "scale=${new_width}:${new_height}" -c:v libx264 -preset slow -crf 23 -pix_fmt yuv420p "${output_file}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment