Last active
April 19, 2024 00:56
-
-
Save EndlessEden/2818c0fdcbd1b7b4256f7a3cfcf40550 to your computer and use it in GitHub Desktop.
hdrprobe - bash script to probe a file with ffprobe and detect if file is in HDR. (Supports notify-send for toaster notifications)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ ! -z $DISPLAY ]; then | |
if [ $(notify-send -u normal -a hdrprobe -t 3000 -v | sed -e 's| |\n|g' | head -1 | grep -c 'notify-send') -gt 0 ]; then | |
NOTIFY="1" | |
else | |
NOTIFY="0" | |
fi | |
else | |
NOTIFY="0" | |
fi | |
if [ -z $F ]; then | |
if [ ! -z $@ ]; then | |
F="$(echo $@)" | |
else | |
echo "no filename or 'F-var' Specfied. Exiting." | |
exit 1 | |
fi | |
fi | |
if [ ! "$(ffprobe -version | sed -e 's| |\n|g' | head -1)" == "ffprobe" ]; then | |
if [ "$NOTIFY" == "1" ]; then | |
notify-send -u normal -a hdrprobe -t 3000 "hdrprobe: ffprobe not found" "ffprobe was not found in '$PATH'. Please install ffmpeg/ffprobe, and run this script again." | |
else | |
echo "ffprobe not found in '$PATH'. Please install ffmpeg/ffprobe, and run this script again." && exit 1 | |
fi | |
fi | |
if [ ! "$(basename --version | sed -e 's| |\n|g' | head -1)" == "basename" ]; then | |
if [ "$NOTIFY" == "1" ]; then | |
notify-send -u normal -a hdrprobe -t 3000 "hdrprobe: basename not found" "basename was not found in '$PATH'. Please install coreutils/basename, and run this script again." | |
else | |
echo "basename not found in '$PATH'. Please install coreutils/basename, and run this script again." && exit 1 | |
fi | |
fi | |
COLORS=$(ffprobe -show_streams -v error "$F" |grep -E "^color_transfer|^color_space=|^color_primaries=" |head -3) | |
for C in $COLORS; do | |
if [[ "$C" = "color_space="* ]]; then | |
COLORSPACE=${C##*=} | |
elif [[ "$C" = "color_transfer="* ]]; then | |
COLORTRANSFER=${C##*=} | |
elif [[ "$C" = "color_primaries="* ]]; then | |
COLORPRIMARIES=${C##*=} | |
fi | |
done | |
if [ $NOTIFY == "1" ]; then | |
if [ "${COLORSPACE}" = "bt2020nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2020" ]; then | |
notify-send -u normal -a hdrprobe -t 3000 "File is in HDR" "$(basename -s \"$(echo '.' $(echo \"$F\" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')\" $F) is in 'HDR(7/10)'" | |
elif [ "${COLORSPACE}" = "bt2020nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2100" ]; then | |
notify-send -u normal -a hdrprobe -t 3000 "File is in HDR10+" "$(basename -s \"$(echo '.' $(echo \"$F\" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')\" $F) is in 'HDR10+'" | |
elif [ "${COLORSPACE}" = "bt2100nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2020" ]; then | |
notify-send -u normal -a hdrprobe -t 3000 "File is in HDR10+" "$(basename -s \"$(echo '.' $(echo \"$F\" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')\" $F) is in 'HDR10+'" | |
elif [ "${COLORSPACE}" = "bt2100nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2100" ]; then | |
notify-send -u normal -a hdrprobe -t 3000 "File is in HDR10+" "$(basename -s \"$(echo '.' $(echo \"$F\" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')\" $F) is in 'HDR10+'" | |
else | |
notify-send -u normal -a hdrprobe -t 3000 "File is NOT in HDR" "$(basename -s \"$(echo '.' $(echo \"$F\" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')\" $F) is NOT in HDR" | |
fi | |
else | |
if [ "${COLORSPACE}" = "bt2020nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2020" ]; then | |
echo $(basename -s "$(echo '.' $(echo "$F" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')" $F) is in "HDR(7/10)" | |
elif [ "${COLORSPACE}" = "bt2020nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2100" ]; then | |
echo $(basename -s "$(echo '.' $(echo "$F" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')" $F) is in "HDR10+" | |
elif [ "${COLORSPACE}" = "bt2100nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2020" ]; then | |
echo $(basename -s "$(echo '.' $(echo "$F" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')" $F) is in "HDR10+" | |
elif [ "${COLORSPACE}" = "bt2100nc" ] && [ "${COLORTRANSFER}" = "smpte2084" ] && [ "${COLORPRIMARIES}" = "bt2100" ]; then | |
echo $(basename -s "$(echo '.' $(echo "$F" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')" $F) is in "HDR10+" | |
else | |
echo $(basename -s "$(echo '.' $(echo "$F" | sed 's|\.|\n|g' | tail -1) | sed 's| ||g')" $F) is NOT in HDR | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment