How can I filter and sort videos by orientation (portrait or landscape)? 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:


Export all original videos from iCloud Photos (~400GB) and store them locally
Filter and sort them by portrait or landscape orientation
Remove videos that meet further specified criteria (under 15 seconds, duplicates, etc).
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 &quot;$f&quot;`
        width=`mdls -raw -name  kMDItemPixelWidth &quot;$f&quot;`
        mkdir -p &quot;${height}x${width}&quot;
        mv &quot;$f&quot; &quot;${height}x${width}&quot;/
        
        printf &quot;File: $f\n&quot;     
        printf &quot;&gt; Dimensions: $height x $width \n\n&quot;
    done

printf &quot;All done! \n&quot;

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.