-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmakeframes
executable file
·91 lines (82 loc) · 3.38 KB
/
makeframes
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
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# makeframes
VERSION="1.0"
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
DEPENDENCIES=(ffmpeg ffprobe)
_initialize_make
EXTENSION="tiff"
# local variables
IMAGECOUNT=10
_usage(){
echo
echo "$(basename "${0}") ${VERSION}"
echo "This application will create a series of still images from a video file or package input with the following options."
echo "Dependencies: ${DEPENDENCIES[@]}"
echo "Usage: $(basename ${0}) [ -d /path/to/deliver/to/ ] fileorpackage1 [ fileorpackage2 ...]"
echo " -d directory ( directory to deliver the resulting file to )"
echo " -n (dry-run mode, show the commands that would be run but don't do anything)"
echo " -h display this help"
echo
exit
}
[ "${#}" = 0 ] && _usage
user_input="${*}"
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":d:e:E:nh" OPT ; do
case "${OPT}" in
d) DELIVERDIR="${OPTARG}" && _check_deliverdir ;;
e) EMAILADDRESS_DELIVERY="${OPTARG}" && check_emailaddress "${EMAILADDRESS_DELIVERY}" ;;
E) EMAILADDRESS_OUTCOME="${OPTARG}" && check_emailaddress "${EMAILADDRESS_OUTCOME}" ;;
n) DRYRUN=true;;
h) _usage ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
:) echo "Option -${OPTARG} requires an argument" ; _writeerrorlog "makeframes" "The option selected required an argument and none was provided. The script had to exit." ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "${*}" != "" ] ; do
INPUT="${1}"
shift
[ -d "${INPUT}" ] && { OUTPUTDIR="${INPUT}/objects/access/images" && LOGDIR="${INPUT}/metadata/logs" ;};
[ -f "${INPUT}" ] && { OUTPUTDIR=$(dirname "${INPUT}")"/access/images" && LOGDIR="$(dirname "${INPUT}")/access/logs" ;};
[ ! "$OUTPUTDIR" ] && { OUTPUTDIR="${INPUT}/objects/access/images" && LOGDIR="${INPUT}/metadata/logs" ;};
_unset_variables
_find_input "${INPUT}"
MEDIAID=$(basename "${INPUT}" | cut -d. -f1)
_report_to_db
# encoding options
_get_codectagstring "${SOURCEFILE}"
INPUTOPTIONS+=(-vsync 0)
INPUTOPTIONS+=(-nostdin)
if [[ "${CODEC_TAG_STRING}" == "mjp2" ]] ; then
INPUTOPTIONS+=(-vcodec libopenjpeg)
fi
_add_video_filter "yadif"
_add_video_filter "thumbnail=100"
MIDDLEOPTIONS+=(-frames:v 1)
MIDDLEOPTIONS+=(-pix_fmt rgba)
_filter_to_middle_option
_log -b
DURATION=$(ffprobe 2>/dev/null "${SOURCEFILE}" -show_format | grep duration | cut -d= -f2)
_run_critical mkdir -p "${OUTPUTDIR}"
_prep_ffmpeg_log -q
for (( IMAGENUMBER=1; IMAGENUMBER<=${IMAGECOUNT}; IMAGENUMBER++)) ; do
START=$(echo "( ${DURATION} / ( ${IMAGECOUNT} + 1 )) * ${IMAGENUMBER}" | bc)
SUFFIX="_${IMAGENUMBER}"
_set_up_output
_report -d "Making frame ${IMAGENUMBER} of ${IMAGECOUNT} - dur:${DURATION} start:${START} - ${OUTPUT}"
if [ "${CONCATSOURCE}" != "" ] ; then
FFMPEGINPUT="${CONCATSOURCE}"
fi
_run_critical_event ffmpeg -y ${INPUTOPTIONS[@]} -v warning -ss "$START" "${FFMPEGINPUT[@]}" "${MIDDLEOPTIONS[@]}" "${OUTPUT}"
done
echo
if [ -d "${DELIVERDIR}" ] ; then
_report -dt "Delivering output"
_run mkdir -p "${DELIVERDIR}/${MEDIAID}_images/"
_run cp -av "${OUTPUTDIR}/" "${DELIVERDIR}/${MEDIAID}_images/"
fi
_log -e
done