Skip to content

Instantly share code, notes, and snippets.

@jontelang

jontelang/aa.sh Secret

Created October 14, 2022 05:10
Show Gist options
  • Save jontelang/767d8b3b9074a8dda55767ffb1b96947 to your computer and use it in GitHub Desktop.
Save jontelang/767d8b3b9074a8dda55767ffb1b96947 to your computer and use it in GitHub Desktop.
#!/bin/bash
inputfolder="/Users/???/Library/Mobile Documents/com~apple~CloudDocs/Images/SomeEvent/"
outputfolder=/Users/???/Desktop/OUT2
echo "Results" > "$outputfolder/results.txt"
total_before=$(echo "0" | bc)
total_after=$(echo "0" | bc)
for fullpath_filename in "$inputfolder"/*.MOV; do
echo ""
echo "-----"
echo "Input file: $fullpath_filename"
echo -e "Size: "
numfmt --to=iec-i --suffix=B --format="%.1f" $(stat -f%z "$fullpath_filename")
fps=$(mediainfo "$fullpath_filename" "--inform=Video;%FrameRate%")
echo "FPS: $fps"
skipIfFileIsMoreFPSThanThisValue="44.33" # Dont process eg. 60 fps because hadnbrake preset is for 30s
if (( $(echo "$fps > $skipIfFileIsMoreFPSThanThisValue" | bc -l) )); then
echo "FPS of input is more than $skipIfFileIsMoreFPSThanThisValue - skip"
else
echo "FPS is less than $skipIfFileIsMoreFPSThanThisValue - proceed"
filename=$(basename "$fullpath_filename" .MOV)
newfile_filename="$outputfolder/$filename.mp4"
echo "Output: $newfile_filename"
outPreMetadataPath=$(echo "$outputfolder/$filename-before-metadata.txt")
echo "Saving pre metadata to $outPreMetadataPath"
exiftool "$fullpath_filename" > $outPreMetadataPath
echo "Process with handbrakeCLI"
echo "+++++++++"
HandBrakeCLI -i "$fullpath_filename" -o "$newfile_filename" # --preset="Fast 1080p30"
echo "+++++++++"
echo "Copy old EXIF data to new file"
exiftool -all= -tagsfromfile "$fullpath_filename" -ext mp4 -all:all -FileCreateDate --matrixstructure --rotation "$newfile_filename"
outPostMetadataPath=$(echo "$outputfolder/$filename-after-metadata.txt")
echo "Saving post metadata to $outPostMetadataPath"
exiftool "$newfile_filename" > $outPostMetadataPath
echo "Size results"
echo " " >> "$outputfolder/results.txt"
echo $filename >> "$outputfolder/results.txt"
size_before=$(stat -f%z "$fullpath_filename")
size_after=$(stat -f%z "$newfile_filename")
numfmt --to=iec-i --suffix=B --format="Size before: %.1f" $size_before >> "$outputfolder/results.txt"
numfmt --to=iec-i --suffix=B --format="Size after: %.1f" $size_after >> "$outputfolder/results.txt"
size_saved=$(echo "$size_before - $size_after" | bc)
numfmt --to=iec-i --suffix=B --format="Saved: %.1f" $size_saved >> "$outputfolder/results.txt"
total_before=$(echo "$total_before + $size_before" | bc)
total_after=$(echo "$total_after + $size_after" | bc)
numfmt --to=iec-i --suffix=B --format="Total saved: %.1f" $(echo "$total_before - $total_after" | bc) >> "$outputfolder/results.txt"
#
#
#
metadataKeys="Video;%FrameRate%
Video;%Width%
Video;%Height%
General;%com.apple.quicktime.creationdate%
General;%com.apple.quicktime.make%
General;%com.apple.quicktime.model%
General;%com.apple.quicktime.software%
General;%File_Created_Date%
General;%Recorded_Date%
General;%Recorded_Location%"
for metadataKey in $metadataKeys; do
value_before=$(mediainfo "$fullpath_filename" "--inform=$metadataKey")
value_after=$(mediainfo "$newfile_filename" "--inform=$metadataKey")
value_text=$(echo " $metadataKey: [$value_before] to [$value_after]")
if [[ ! "$value_before" =~ "$value_after" ]]; then
value_text=$(echo "$value_text (❌)")
else
value_text=$(echo "$value_text (✅)")
fi
echo $value_text >> "$outputfolder/results.txt"
done
# Debug pls stop
# exit 1;
fi
echo "-----"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment