Enable extended and recursive globbing:
shopt -s extglob globstar
Then:
exiftool -q -p '$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv)
**
will recurse into subdirectories. The extended glob +(*.mp4|...)
will match at least one of the patterns inside the ()
.
You can use grep to process the output and generate a list of files not 1920x1080
:
exiftool -q -p '$Directory/$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv) |
grep -v ' 1920x1080$'
Note the change here: I'm using $Directory/$FileName $Imagesize
. We need the path to the file, not just the filename, so $Directory/$Filename
. And
Here we check if each line doesn't end with 1920x1080
($
is the end of line, -v
in grep inverts the match). Verify the output.
Now we can delete these files:
exiftool -q -p '$Directory/$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv) |
grep -v ' 1920x1080$' | sed 's: [^ ]*$::' |
xargs -d '\n' rm
sed 's: [^ ]*$::'
removes everything from the last
until the end of the line, so the AxB
resolution from the output of exiftool
is removed, keeping only the filename. Then xargs rm
takes each line as a filename and runs rm
with them as argument.
Disable the globbing options when done:
shopt -u globstar globstar
To exclude multiple resolutions, use an OR in grep
:
grep -Ev ' (1920x1080|1920x820|1280x544)$'
Here is a command with all the widely used video formats
exiftool -q -p '$Directory/$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv|*.avi|*.webm|*.vob|*.mov|*.wmv|*.amv|*.m4p|*.m4v|*.mpeg|*.mpv|*.m4v|*.3gp)
Here is a command excluding (almost) all the HD Video formats
grep -Ev ' (1920x1080|1920x1040|1920x1068|1906x952|1916x808|1920x808|1920x804|1916x812|1600x864|1436x1080|1920x820|1280x544|1920x800|1920x802|1920x816|1856x1080|1920x1072|1920x1056|1280x720|1280x536|1280x560|1280x538|1280x528|1216x544|1280x534|1280x532|1281x534|1278x714|1280x718|1280x688|1278x682|1280x690|1280x694|1280x660|1282x692|1280x692|1285x696|1278x544|1280x696|1279x718|1280x546|1281x546|960x720|1324x552|1305x552|1308x552|1536x640)$'
find
andgrep
. – muru Apr 03 '17 at 09:14exiftool
did work, but there are a few minor problems. i've updated the question accordingly, thanks for the help – Sumeet Deshmukh Apr 03 '17 at 10:55mp4
andmkv
extensions in single command? i tried what i could, i'm still trying, can you help me with that? – Sumeet Deshmukh Apr 03 '17 at 11:28