2

This is a unique situation

I've more than 500 Movies in a partition. what I wanted to do is search movie files on the basis of Property Video Dimension, so that I could delete anything which is below 720p HD, to make space for other stuff.

Search option in nautilus can search by dates or file types but not properties. is there another application that i can use? or Command? or Nautilus-Script?

Highlighting video dimension

UPDATE

find . -name '*.mkv' -exec exiftool -fileName -imageSize {} \; 

This command works as expected but i want this command to do a little bit more. i don't know how ExifTool works so i can't modify it

can I add multiple file extensions in single command? most of the files are mkv but it includes mp4 flv. a single command scanning all these video extensions could save a lot of work

enter image description here

(see how many sub folders are there)

muru
  • 207,228

1 Answers1

2

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)$'
muru
  • 207,228