Script sort MP4 (and other) videos by orientation to portrait and landscape folders >>> IMPOSSIBLE? I've been wrestling with a 14TB+ video library for the last months trying to dedupe and sort all of it into production ready folder structure.
For the life of me I have not been able to find (spent 3 solid days with no sleep) a script that will sort a folder of video files, using their dimensions, into Portrait and Landscape folders.
The closest I've found is this -
#!/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;

Which gets me closer by sorting them into folders based on dimensions, but it's not what I'm trying to achieve.
Alternatively I found this script for images using Imagemagick, (which I installed via Homebrew) it does read the files, though it moves them ALL into the portraits directory. I'm assuming the variables may be different to extract height and width from a video file?
#/bin/zsh
mkdir -p portraits
mkdir -p landscapes
for f in ./*.mp4
do
  r=$(identify -format '%[fx:(h/w)]' &quot;$f&quot;)
  if [[ r &lt; 1.0 ]] 
  then
      echo &quot;Portrait detected.&quot;
  mv &quot;$f&quot; ./portraits/
  elif  [[ r &gt; 1.0 ]]
  then
  echo &quot;Landscape detected.&quot;
      mv &quot;$f&quot; ./landscapes/
  fi
done

If ANYONE OUT THERE can help me with this, it's worth a PayPal to me. I know it's quick work for the right mind.
The same, if someone has another solution using folder actions or automator or ANYTHING else. I'm running Mac OS with terminal.
Much appreciated!
jason@speedheathens.com
You can use the test function provided by fish to compare the two dimensions:
#!/usr/local/bin/fish
for i in *.{mp4,MP4,mov,MOV,m4v,M4V}
  if test (mdls -raw -name kMDItemPixelHeight $i) -gt (mdls -raw -name kMDItemPixelWidth $i)
     mv $i portrait/
  else
     mv $i landscape/
  end
end

bash probably provides the same functionality, but I'm more familiar with fish.