5

How to find recursive (with ffprobe) all low quality videos (example 240p and 480p)? I prefer a command line solution.

Before there was iPhone and clones, I recorded already videos. They seem to have in commen to be 240p and 480p. I now wish to find them and manually delete most. Do you recommend other meta data than resolution for finding very old videos?

Sybil
  • 2,107

1 Answers1

1

Here it is. The following script runs surprisingly fast, it process 363 files located in 138 directories for about 14 seconds.

#!/bin/bash

[[ -z ${1+x} ]] && qlty="480" || qlty="$1" [[ -z ${2+x} ]] && extn="mp4" || type="$2" [[ -z ${3+x} ]] && baseDir="" || baseDir="${3}/"

shopt -s globstar

for file in ${baseDir}*/${extn}; do ffprobe -v error -select_streams v:0 -show_entries stream=width,height
-of csv=s=x:p=0 "$file" 2>/dev/null |
awk -F'x' '$2 <= q {printf "%10s\t%s\n", $0, file}' file="$file" q="$qlty" # For exact match of the quality change <= to == done

Copy the above script and paste it as content of an executable file that belongs to your $PATH, then use it as shell command. Let's assume the name of the file is find-lq-videos.sh, you have root privileges and nano is your favorite editor, so you can use the following commands to do that.

sudo touch /usr/local/bin/find-lq-videos.sh
sudo chmod +x /usr/local/bin/find-lq-videos.sh
sudo nano /usr/local/bin/find-lq-videos.sh

Then go inside the parent directory where the videos are and type find-lq-videos.sh. By default it will search for mp4 files with width lower or equal to 480. Here is an example output:

spas@desk:/mnt/Videos/Doc.and.Conspiracy$ find-lq-videos.sh
   720x400   The.Brussels.Business.2012/The.Brussels.Business (2012).mp4
   854x480   HyperNormalisation.2016/HyperNormalisation (2016).mp4

The script accepts three parameters. Here is how to search mkv <= 320:

spas@desk:/mnt/Videos/Doc.and.Conspiracy$ find-lq-videos.sh 320 mkv
   720x304   Inside.Job.2010/Inside.Job.2010.BG.EN.sub.mkv

The third parameter is the base path if it is not the current directory. Here is how to search for all files accepted by ffprobe within another directory:

spas@desk:~$ find-lq-videos.sh 320 '*' /mnt/Videos/Science
   285x300   /mnt/Videos/Science/Free.Energy.The.Race.to.Zero.Point.1997.Cover.jpg
   326x240   /mnt/Videos/Science/Free.Energy.The.Race.to.Zero.Point.1997.sub.mkv
   320x240   /mnt/Videos/Science/Sugar.The.Bitter.Truth.2009.sub.mkv

References:

pa4080
  • 29,831
  • Thanks. The script is working, but I get this error ./find_lowquality_vids.sh: line 9: shopt: globstar: invalid shell option name – Sybil Feb 15 '22 at 06:12
  • 1
    Hello, @Josefine, shopt -s globstar enables this fancy thing ** which does the multilevel recursion in Bash. This is a standard option for the nowadays Bash's versions. In Bash you can find all available options and their status by the command shopt. So if you are primary using a shell which is not Bash, the shebang at the first line of the script #!/bin/bash become much important. In addition you could try change the shebang with #!/usr/bin/env bash - reference. – pa4080 Feb 16 '22 at 15:39