Skip to content

Instantly share code, notes, and snippets.

@jfeilbach
Created March 22, 2018 03:30
Show Gist options
  • Save jfeilbach/66c53d4975d111145e9325c28d735b43 to your computer and use it in GitHub Desktop.
Save jfeilbach/66c53d4975d111145e9325c28d735b43 to your computer and use it in GitHub Desktop.
list x265 files
#!/bin/bash
# Creates a report with all files in listed directories.
# Checks if those files are x265 compression or not.
# Outputs all files that are not.
# Created on Nov 7th 2015 by steelbox.
# Modified on Nov 26th 2016 for Github.
# Verify script usage.
if [ -z "$1" ]
then
echo "Please supply location of files to check."
echo "Usage: '$0' /location/to/files"
exit 1
fi
# Verify existence of mediainfo.
if ! command -v mediainfo
then
echo "mediainfo does not seem to be installed. Aborting."
exit 1
fi
# Verify if folder exists and well formatted for script.
if [ -d "$1" ]
then
# Check if folder ends with forward slash (must not).
valid=$(echo "$1" | rev | cut -c 1)
if [ "$valid" == "/" ]
then
loc=$(echo "$1" | rev | cut -c 2- | rev)
else
loc="$1"
fi
else
echo "Folder '$1' does not seem to exist. Please verify."
exit 1
fi
# Creating list. Filter files for videos only.
list=$(mktemp)
echo "Creating list of all files in location $loc"
find "$loc" ! -type d -print | grep -i ".*\.mp4\|.*\.mkv\|.*\.avi\|*\.m4v\|.*\.mpg" > "$list"
report="$HOME/x265_report_$(date +%y-%m-%d).txt"
echo "Report will be saved to location $report"
# Verifies if $report file exists. Aborts if so.
if [ -f "$report" ]
then
echo "File '$report' exists. Aborting."
echo "Please remove or rename file."
fi
# Read from file and get information on media. Create report.
echo "Finding out which files are not formatted in x265..."
while read -r line
do
test=$(mediainfo "$line" --Inform="Video;%Format%")
if [ "$test" != "HEVC" ] # If the media file is not x265 (HEVC).
then # Output the file into the report file.
mediainfo "$line" --Inform="General;%CompleteName%" >> "$report"
fi
done < "$list"
# End script.
if [ -f "$report" ]
then
echo "Your report is ready at: $report"
echo ""
else
echo "All files found were formatted with x265 encoding (HEVC)"
echo "No report has been created."
fi
# Delete temporary files.
rm "$list"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment