-
Notifications
You must be signed in to change notification settings - Fork 27
/
makeframemd5
executable file
·79 lines (74 loc) · 2.48 KB
/
makeframemd5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
_usage(){
echo
echo "$(basename "${0}")"
echo "Produces framemd5s for video files in a target directory."
echo "Usage: $(basename "${0}") [ -h ] package1 [ package2 ... ]"
echo " -h (show usage)"
exit
}
[ "${#}" = 0 ] && _usage
OPTIND=1
while getopts ":rh" OPT ; do
case "${OPT}" in
r) refile="Y" ;;
h) _usage ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
esac
done
shift $(( ${OPTIND} - 1 ))
_set_up_framemd5(){
_log -b
if [[ -d "${PACKAGE_PATH}/${OUTPUTDIR}" ]] ; then
_report -wt "WARNING ${PACKAGE_PATH}/${OUTPUTDIR} already exists, not making framemd5."
continue
fi
_mkdir2 "${PACKAGE_PATH}/${OUTPUTDIR}"
}
OUTPUTDIR="./metadata/frameMD5s"
while [ "${*}" != "" ] ; do
PACKAGE_PATH="${1}"
shift
_set_up_framemd5
cd "${PACKAGE_PATH}"
FILELIST=$(_maketemp)
find "./objects" -type f "${OBJECTS_FIND_EXCLUSIONS[@]}" > "${FILELIST}"
(IFS=$'\n'
for FILE in $(cat "${FILELIST}") ; do
VIDEOTEST=$(file -Ib "${FILE}" | grep 'video')
if [ -n "${VIDEOTEST}" ] ; then
FILENAMEROOT=$(basename "${FILE}")
PARENTDIR=$(dirname "${FILE}")
FILEOUTPUT="${OUTPUTDIR}/${PARENTDIR}"
if [ ! -d "${FILEOUTPUT}" ] ; then
_run mkdir -p "${FILEOUTPUT}"
fi
ffmpeg -i "${FILE}" -f framemd5 -an "${FILEOUTPUT}/${FILENAMEROOT}.framemd5"
else
_report -d "No video track found in target. Skipping."
fi
else
_set_up_framemd5
cd "${PACKAGE_PATH}"
FILELIST=$(_maketemp)
find "./objects" -type f "${OBJECTS_FIND_EXCLUSIONS[@]}" > "${FILELIST}"
(IFS=$'\n'
for FILE in $(cat "${FILELIST}") ; do
VIDEOTEST=$(file -Ib "${FILE}" | grep 'video')
if [ -n "${VIDEOTEST}" ] ; then
FILENAMEROOT=$(basename "${FILE}")
PARENTDIR=$(dirname "${FILE}")
FILEOUTPUT="${OUTPUTDIR}/${PARENTDIR}"
if [ ! -d "${FILEOUTPUT}" ] ; then
_run mkdir -p "${FILEOUTPUT}"
fi
ffmpeg -i "${FILE}" -f framemd5 -an "${FILEOUTPUT}/${FILENAMEROOT}.framemd5"
else
_report -d "No video track found in target. Skipping."
fi
done)
rm "${FILELIST}"
fi
done