Script sort MP4 (and other) videos by orientation to portrait and landscape folders – IMPOSSIBLE?

Hey everyone,

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 "$f"`

width=`mdls -raw -name kMDItemPixelWidth "$f"`

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"

```

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)]' "$f")

if [[ r < 1.0 ]]

then

echo "Portrait detected."

mv "$f" ./portraits/

elif [[ r > 1.0 ]]

then

echo "Landscape detected."

mv "$f" ./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

submitted by /u/speedheathenULTRA
[link] [comments]

Read more here: https://www.reddit.com/r/linux/comments/jy6621/script_sort_mp4_and_other_videos_by_orientation/

Content Attribution

This content was originally published by /u/speedheathenULTRA at Linux, GNU/Linux, free software..., and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: