Step 3 Video Compressor Script

Make sure this script is in Text file in your desktop.
→ Open TextEdit → Set format to Plain Text
→ Paste the SCRIPT BELOW
→ Save it as: convert_to_50mb.sh
→ Make sure the file is placed inside the convert-videos folder on your Desktop.


#!/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