0

I'm attempting to filter and sort all videos in a local folder based on their orientation. I can't find anything in AppleScript, macOS file search, or video metadata that will make this easy. My guess is that I'll have to grab the video's height and width, and then generate a folder for each distinct combination. I'll then have to eyeball which sizes are portrait and landscape.

My goal:

  1. Export all original videos from iCloud Photos (~400GB) and store them locally
  2. Filter and sort them by portrait or landscape orientation
  3. Remove videos that meet further specified criteria (under 15 seconds, duplicates, etc).
  • If these are iPhone videos, then you can use ExifTool by Phil Harvey to get the value of the Rotation property, 0 being landscape and 90 being portrait. In Terminal, e.g. /path/to/exiftool /path/to/IMG_1234.MOV | awk '/Rotation/{print $3}' will return its value. You can use this command example to work it into a script that will act accordingly as wanted. – user3439894 Apr 9 at 5:33
  • It's possible with a bash script, using mdls -raw -name kMDItemPixelHeight (and kMDItemPixelWidth) which you can compare to determine which is greater. – CJK Apr 13 at 11:21
  • @CJK Thank you. That's just what I needed. Added my script as an answer below. – Greg Barbosa Apr 14 at 21:06
  • @user3439894 For whatever reason ExifTool wasn't pulling orientation data at all for me. I'll continue to test with ExifTool because it does seem powerful for other uses. – Greg Barbosa Apr 14 at 21:07
1

After testing @CJK's answer, here's what I came up:

#!/bin/bash
shopt -s nullglob

for f in *.{mp4,MP4,mov,MOV,m4v,M4V}
    do 
        height=`mdls -raw -name  kMDItemPixelHeight "$f"`
        width=`mdls -raw -name  kMDItemPixelWidth "$f"`
        folder=`mkdir -p "$height"x"$width"`
        mv "$f" "$height"x"$width"

        printf "File: $f\n"     
        printf "> Dimensions: $height x $width \n\n"
    done

printf "All done! \n"

This will grab the height and width of each video type in a specific folder, and then sort it into its appropriate folder. With a bit more scripting, you could then sort the folders into portrait/landscape folders by comparing height vs. width.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .