1
0

Added -o FILE to only process older files

Signed-off-by: James Ketrenos <jketreno@media.ketrenos.com>
This commit is contained in:
James Ketrenos 2022-04-15 12:56:41 -07:00
parent c46d741b59
commit a5e79dc95b

View File

@ -9,6 +9,43 @@ fail() {
exit -1
}
usage() {
cat << EOF
usage: normalize-video [OPTIONS] [FILES]
Options:
-h This help
-o OLDER Only process files older than OLDER. See 'find -newer'
-f Force transcode even if already meets normalized
settings.
EOF
}
force=0
older_than=
while getopts fho: opt; do
case "${opt}" in
o)
older_than="-and -not -newer ${OPTARG}"
;;
f)
force=1
;;
h)
usage
exit 0
;;
[?])
usage
exit -1
;;
esac
done
shift $(( OPTIND-1 ))
VIDEO=$(getent group video | sed -E 's,^video:[^:]*:([^:]*):.*$,\1,')
RENDER=$(getent group render | sed -E 's,^render:[^:]*:([^:]*):.*$,\1,')
@ -245,7 +282,7 @@ function check_and_convert {
container=${info[1]}
update=0
transcode=0
transcode=${force}
if (( width > 1920 )); then
echo "${PREFIX} Has a width of ${width} and will be scaled to 1920."
height=$((((((1920*height/width))*2))/2))
@ -271,15 +308,22 @@ function check_and_convert {
update=1
fi
if (( update == 0 )); then
if (( update == 0 )) && (( force == 0 )); then
echo "${PREFIX} Skipping ${IN} as it is already normalized."
return 0;
fi
echo -n "${PREFIX} Counting frames in ${IN}: "
FRAMES=$(ffprobe -v error -select_streams v:0 -show_entries stream -of default=noprint_wrappers=1 "${IN}" | sed -ne 's,^TAG:NUMBER_OF_FRAMES=,,p') || fail "Unable to count frames"
echo -e "\n${PREFIX} ${FRAMES} frames."
if [[ "${FRAMES}" != "" ]]; then
echo -e "\n${PREFIX} ${FRAMES} frames."
else
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${IN}")
fps=$(ffprobe -v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate ${IN})
FRAMES=$(printf "%.0f" $(bc <<< "${duration}*${fps}" ))
echo -e "\n${PREFIX} ${FRAMES} (from duration ${duration}) frames."
fi
IN="$(realpath "${IN}")"
OUT="${IN/%.???/.mkv}"
ORIG="${OUT}"
@ -347,10 +391,19 @@ function check_and_convert {
break
fi
if [[ "${FRAMES}" == "" ]]; then
frame=$(echo $line | sed -n 's/^frame=*\(.*\)/Frame: \1/p')
speed=$(echo $line | sed -n 's/^speeed=*\(.*\)/Speed: \1/p')
fps=$(echo $line | sed -n 's/^fps=*\(.*\)/FPS: \1/p')
echo "${PREFIX} ${frame} ${speed} ${fps}"
frame=${frame:-$(echo $line | sed -n 's/^frame=*\(.*\)/Frame: \1/p')}
speed=${speed:-$(echo $line | sed -n 's/^speeed=*\(.*\)/Speed: \1/p')}
fps=${fps:-$(echo $line | sed -n 's/^fps=*\(.*\)/FPS: \1/p')}
if [[ "${frame}" != "" ]] &&
[[ "${speed}" != "" ]] &&
[[ "${fps}" != "" ]]; then
echo "${PREFIX} ${frame} ${speed} ${fps}"
frame=
fps=
speed=
else
echo $line
fi
continue
fi
@ -402,11 +455,18 @@ function check_and_convert {
if [ -z "$1" ]; then
find . -name '* *' -type d | while read file; do mv "${file}" "${file// /_}" || fail "Unable to rename dir ${file}"; done
find . -name '* *' -type f | while read file; do mv "${file}" "${file// /_}" || fail "Unable to rename file ${file}"; done
total=$(find . -type f \
-and -not -path "./backup/*" | wc -l)
matches="
\(
-name '*mkv'
-or -name '*mp4'
-or -name '*avi'
\)
-and -not -path './backup/*'
${older_than}
"
total=$(eval find . -type f ${matches} | wc -l)
current=1
find . -type f -name '*mkv' -or -name '*mp4' -or -name '*avi' \
-and -not -path "./backup/*" | sort | while read file; do
eval find . -type f ${matches} | sort | while read file; do
check_and_convert "${file}" "${current}/${total}:"
current=$((current+1))
done