Added -o FILE to only process older files
Signed-off-by: James Ketrenos <jketreno@media.ketrenos.com>
This commit is contained in:
parent
c46d741b59
commit
a5e79dc95b
@ -9,6 +9,43 @@ fail() {
|
|||||||
exit -1
|
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,')
|
VIDEO=$(getent group video | sed -E 's,^video:[^:]*:([^:]*):.*$,\1,')
|
||||||
RENDER=$(getent group render | sed -E 's,^render:[^:]*:([^:]*):.*$,\1,')
|
RENDER=$(getent group render | sed -E 's,^render:[^:]*:([^:]*):.*$,\1,')
|
||||||
|
|
||||||
@ -245,7 +282,7 @@ function check_and_convert {
|
|||||||
container=${info[1]}
|
container=${info[1]}
|
||||||
|
|
||||||
update=0
|
update=0
|
||||||
transcode=0
|
transcode=${force}
|
||||||
if (( width > 1920 )); then
|
if (( width > 1920 )); then
|
||||||
echo "${PREFIX} Has a width of ${width} and will be scaled to 1920."
|
echo "${PREFIX} Has a width of ${width} and will be scaled to 1920."
|
||||||
height=$((((((1920*height/width))*2))/2))
|
height=$((((((1920*height/width))*2))/2))
|
||||||
@ -271,14 +308,21 @@ function check_and_convert {
|
|||||||
update=1
|
update=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( update == 0 )); then
|
if (( update == 0 )) && (( force == 0 )); then
|
||||||
echo "${PREFIX} Skipping ${IN} as it is already normalized."
|
echo "${PREFIX} Skipping ${IN} as it is already normalized."
|
||||||
return 0;
|
return 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "${PREFIX} Counting frames in ${IN}: "
|
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"
|
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"
|
||||||
|
if [[ "${FRAMES}" != "" ]]; then
|
||||||
echo -e "\n${PREFIX} ${FRAMES} frames."
|
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}")"
|
IN="$(realpath "${IN}")"
|
||||||
OUT="${IN/%.???/.mkv}"
|
OUT="${IN/%.???/.mkv}"
|
||||||
@ -347,10 +391,19 @@ function check_and_convert {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
if [[ "${FRAMES}" == "" ]]; then
|
if [[ "${FRAMES}" == "" ]]; then
|
||||||
frame=$(echo $line | sed -n 's/^frame=*\(.*\)/Frame: \1/p')
|
frame=${frame:-$(echo $line | sed -n 's/^frame=*\(.*\)/Frame: \1/p')}
|
||||||
speed=$(echo $line | sed -n 's/^speeed=*\(.*\)/Speed: \1/p')
|
speed=${speed:-$(echo $line | sed -n 's/^speeed=*\(.*\)/Speed: \1/p')}
|
||||||
fps=$(echo $line | sed -n 's/^fps=*\(.*\)/FPS: \1/p')
|
fps=${fps:-$(echo $line | sed -n 's/^fps=*\(.*\)/FPS: \1/p')}
|
||||||
|
if [[ "${frame}" != "" ]] &&
|
||||||
|
[[ "${speed}" != "" ]] &&
|
||||||
|
[[ "${fps}" != "" ]]; then
|
||||||
echo "${PREFIX} ${frame} ${speed} ${fps}"
|
echo "${PREFIX} ${frame} ${speed} ${fps}"
|
||||||
|
frame=
|
||||||
|
fps=
|
||||||
|
speed=
|
||||||
|
else
|
||||||
|
echo $line
|
||||||
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -402,11 +455,18 @@ function check_and_convert {
|
|||||||
if [ -z "$1" ]; then
|
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 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
|
find . -name '* *' -type f | while read file; do mv "${file}" "${file// /_}" || fail "Unable to rename file ${file}"; done
|
||||||
total=$(find . -type f \
|
matches="
|
||||||
-and -not -path "./backup/*" | wc -l)
|
\(
|
||||||
|
-name '*mkv'
|
||||||
|
-or -name '*mp4'
|
||||||
|
-or -name '*avi'
|
||||||
|
\)
|
||||||
|
-and -not -path './backup/*'
|
||||||
|
${older_than}
|
||||||
|
"
|
||||||
|
total=$(eval find . -type f ${matches} | wc -l)
|
||||||
current=1
|
current=1
|
||||||
find . -type f -name '*mkv' -or -name '*mp4' -or -name '*avi' \
|
eval find . -type f ${matches} | sort | while read file; do
|
||||||
-and -not -path "./backup/*" | sort | while read file; do
|
|
||||||
check_and_convert "${file}" "${current}/${total}:"
|
check_and_convert "${file}" "${current}/${total}:"
|
||||||
current=$((current+1))
|
current=$((current+1))
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user