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: