Skip to content

Instantly share code, notes, and snippets.

@avaidyam
Created November 21, 2023 20:20
Show Gist options
  • Save avaidyam/09f72f1e0d3d302c7e1ce44025c4757b to your computer and use it in GitHub Desktop.
Save avaidyam/09f72f1e0d3d302c7e1ce44025c4757b to your computer and use it in GitHub Desktop.
#!/bin/bash
mkdir -p "$1_8mb"
cd $1
for x in *.mp4; do
newname=${x/mp4/8mb.mp4}
# if [[ "../$1_8mb/$newname" exists then skip ]]
/opt/homebrew/bin/ffmpeg -i "$x" -c:a copy -c:v libx264 -crf 35 -vf scale=1280:720 "../$1_8mb/$newname"
/opt/homebrew/bin/exiftool "-AllDates<Filename" "-FileCreateDate<Filename" "-FileModifyDate<Filename" -overwrite_original_in_place "../$1_8mb/$newname"
done
for x in *.png; do
filename=$(basename "${x%png}jpg")
datetime_part=$(echo "$filename" | grep -oE '[0-9]{1,2}_[0-9]{1,2}_[0-9]{4} [0-9]{1,2}_[0-9]{1,2}_[0-9]{1,2} [AP]M')
reformatted_date=$(date -j -f "%m_%d_%Y %I_%M_%S %p" "$datetime_part" "+%Y-%m-%d %H_%M_%S")
new_filename=$(echo "$filename" | sed "s/$datetime_part/$reformatted_date/")
sips -s format jpeg -s formatOptions low "${x}" --out "${x%png}jpg"
mv "${x%png}jpg" "../$1_8mb/$new_filename"
/opt/homebrew/bin/exiftool "-AllDates<Filename" "-FileCreateDate<Filename" "-FileModifyDate<Filename" -d "%m_%e_%Y %l_%M_%S %p" -api strictdate=0 -overwrite_original_in_place "../$1_8mb/$new_filename"
done
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment