Skip to content

Instantly share code, notes, and snippets.

@dzogrim
Created July 26, 2026 16:59
Show Gist options
  • Select an option

  • Save dzogrim/e0b648804da7ffa52e3e3f454c970fbf to your computer and use it in GitHub Desktop.

Select an option

Save dzogrim/e0b648804da7ffa52e3e3f454c970fbf to your computer and use it in GitHub Desktop.
findHD_videos.sh - published from local Scripts source of truth
#!/usr/bin/env bash
# ==============================================================================
# Script : findHD_videos.sh
# Description : Recursively scans the current directory for supported media
# files, inspects their video properties with MPlayer, and creates
# symbolic links for files that meet the configured HD criteria.
#
# Videos wider than the minimum resolution are classified into
# two output directories:
# - primary HD candidates meeting both width and frame-rate
# thresholds;
# - lower-frame-rate candidates meeting only the width threshold.
#
# Requirements:
# - Bash
# - GNU find with POSIX regular-expression support
# - MPlayer
# - realpath
#
# Usage:
# Run the script from the root directory containing the media files to scan:
#
# ./findHD_videos.sh
#
# Notes:
# - The scan is recursive.
# - Existing links require interactive confirmation because ln uses -i.
# - Output directories and quality thresholds are configured in the script.
# ==============================================================================
# Use this CLI tool to make aliases of found HD videos in the directory and sub-directories.
# Tested on OS X 10.11.6 (Darwin 15.6.0) with MacPorts 2.3.4.
#
# Copyleft (C) 2016 dzogrim
# dzogrim < dzogrim [@] dzogrim [.] pw >
# shellcheck disable=SC2034
VERSION="0.1.0 (2016-07-16)" # initial
# Configuration
NAME=$(basename $0)
# Path to retrieve links high and low rate "HD" videos
outputLinks1="${HOME}/Downloads/Video/Aliases1"
outputLinks2="${HOME}/Downloads/Video/Aliases2"
# Set filename extensions to analyse
supportedFormats="(.*\.(flv|m4v|mkv|mov|mp3|mp4|mpg|mpe|mpeg|mts|avi|divx|rm|rmvb|swf|wm|wmv|3g2|3gp|3gpp|k3g|amc|asf))"
# Quality requirements
minWIDTH=1100
minFPS=24
# Make sure the output exists
[[ ! -d "${outputLinks1}" ]] && mkdir -p "${outputLinks1}"
[[ ! -d "${outputLinks2}" ]] && mkdir -p "${outputLinks2}"
# Find all video files
find . -mindepth 1 -type f -regextype posix-awk -iregex ${supportedFormats} | while read theVideoFile
do
# Get the video widht (or height, or both...)
thisVideoFile="$( mplayer -vo null -ao null -identify -frames 0 "${theVideoFile}" 2>/dev/null | grep -e 'ID_VIDEO_' | grep -i -e WIDTH )"
# Filter for high video widht
if [[ $( echo ${thisVideoFile} | awk 'BEGIN { FS="=" } {print $2}' ) -gt $minWIDTH ]]
then
# Try to detect fake HD videos
if [[ $( mplayer -vo null -ao null -identify -frames 0 "${theVideoFile}" 2>/dev/null | grep ID_VIDEO_FPS | awk 'BEGIN { FS="=" ; OFS="." } {printf "%2d", $2}' ) -gt $minFPS ]]
then
# Creating symbolic link to the video in first output dir
thisPathToFile=$( realpath "${theVideoFile}" )
ln -i -s "${thisPathToFile}" "${outputLinks1}"
else
# Creating symbolic link to the video in second output dir
thisPathToFile=$( realpath "${theVideoFile}" )
ln -i -s "${thisPathToFile}" "${outputLinks2}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment