High Quality Video Compressor
Video Converter for macOS in TERMINAL
This script automatically compresses videos in .mp4, .mov, .avi, or .mkv format while preserving visual quality and reducing file size efficiently.
It automatically selects the best available encoder on your Mac:libx265 – maximum compression efficiencyhevc_videotoolbox – faster hardware accelerationh264_videotoolbox – fallback compatibility mode
Outputs optimized .mp4 files into a converted_target folder.
Suitable for storage, uploads, sharing, and video archiving.
Integration
◉ Step 1 Install in TERMINAL – ffmpeg and bc via Homebrew (once):
To install it, just paste in terminal this code- brew install ffmpeg bc
◉ Step 2 Create a folder on your Desktop (e.g. convert-videos) and drop your videos inside.
◉ Step 3 Open TextEdit → Set format to Plain Text
→ Copy ONE of the SCRIPTS BELOW and Paste it in the TextEdit
→ Save it with name: encode_x265.sh
→ Make sure the file is placed inside the convert-videos folder on your Desktop.
◉ Step 4 Make it executable, and Run it in Terminal: chmod +x ~/Desktop/convert-videos/encode_x265.sh
cd ~/Desktop/convert-videos && chmod +x encode_x265.sh && ./encode_x265.sh
Script 1
High / Low Quality Video Compressor
#!/bin/bash
set -euo pipefail
shopt -s nullglob
mkdir -p converted_target
# Best balance between quality/size:
# 22 = better quality, larger file
# 24 = very good balance
# 26 = smaller file, but more loss
CRF=24
# Audio
AUDIO_KBPS=128
# Select the best available encoder
if ffmpeg -hide_banner -encoders 2>/dev/null | grep -q 'libx265'; then
VIDEO_MODE="libx265"
elif ffmpeg -hide_banner -encoders 2>/dev/null | grep -q 'hevc_videotoolbox'; then
VIDEO_MODE="hevc_videotoolbox"
else
VIDEO_MODE="h264_videotoolbox"
fi
echo "Using video encoder: $VIDEO_MODE"
for f in *.{mp4,mov,avi,mkv,MP4,MOV,AVI,MKV}; do
[ -f "$f" ] || continue
echo "--------------------------------------------------"
echo "Processing: $f"
out="converted_target/${f%.*}_converted.mp4"
case "$VIDEO_MODE" in
libx265)
ffmpeg -y -hide_banner -loglevel error -stats \
-i "$f" \
-c:v libx265 \
-crf "$CRF" \
-preset fast \
-pix_fmt yuv420p \
-tag:v hvc1 \
-c:a aac \
-b:a "${AUDIO_KBPS}k" \
-ar 48000 \
-ac 2 \
-movflags +faststart \
"$out"
;;
hevc_videotoolbox)
ffmpeg -y -hide_banner -loglevel error -stats \
-i "$f" \
-c:v hevc_videotoolbox \
-q:v 65 \
-pix_fmt yuv420p \
-tag:v hvc1 \
-c:a aac \
-b:a "${AUDIO_KBPS}k" \
-ar 48000 \
-ac 2 \
-movflags +faststart \
"$out"
;;
h264_videotoolbox)
ffmpeg -y -hide_banner -loglevel error -stats \
-i "$f" \
-c:v h264_videotoolbox \
-b:v 2500k \
-maxrate 3500k \
-bufsize 7000k \
-pix_fmt yuv420p \
-c:a aac \
-b:a "${AUDIO_KBPS}k" \
-ar 48000 \
-ac 2 \
-movflags +faststart \
"$out"
;;
esac
echo "Saved: $out"
done
echo "Done."
Script 2
Batch Video Compressor (50MB Target)
#!/bin/bash
mkdir -p converted_target
for f in *.{mp4,mov,avi,mkv}; do
[ -f "$f" ] || continue
dur=$(ffprobe -v error -select_streams v:0 -show_entries format=duration \
-of default=noprint_wrappers=1:nokey=1 "$f")
kbps=$(echo "(30*8192)/$dur - 64" | bc)
ffmpeg -y -i "$f" \
-vf "scale=640:-2:force_original_aspect_ratio=decrease,setsar=1:1" \
-c:v libx265 -b:v "${kbps}k" -preset fast \
-c:a aac -b:a 64k -ar 44100 -ac 1 \
converted_target/"${f%.*}_converted.mp4"
done
NEED Higher or Lower Quality?
(for Script 1)
Look inside the script for: CRF=24
You can change the value:CRF=22 = better quality, larger filesCRF=24 = recommended balanceCRF=26 = smaller files, more compression
(for Script 1 & 2)
Look inside the script for:-preset fast
Available options:slow = best compression efficiency, slower processingmedium = balanced speed and sizefast = faster conversion, slightly larger files
