forked from mediamicroservices/mm
/
makeframes
executable file
·86 lines (78 loc) · 3.14 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
#!/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
# 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" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "${*}" != "" ] ; do
input="${1}"
[ -d "$input" ] && { outputdir="$input/objects/access/images" && logdir="$input/metadata/submissionDocumentation/logs" ;};
[ -f "$input" ] && { outputdir=$(dirname "$input")"/access/images" && logdir="$(dirname "$input")/access/logs" ;};
[ ! "$outputdir" ] && { outputdir="$input/objects/access/images" && logdir="$input/metadata/submissionDocumentation/logs" ;};
_find_input "$input"
mediaid=$(basename "${1}" | cut -d. -f1)
# clear local arrays
unset inputoptions
# encoding options
get_codectagstring "${sourcefile}"
inputoptions+=(-vsync 0)
inputoptions+=(-nostdin)
if [[ "${codec_tag_string}" == "mjp2" ]] ; then
inputoptions+=(-vcodec libopenjpeg)
fi
_log -b
DURATION=$(ffprobe 2>/dev/null "${sourcefile}" -show_format | grep duration | cut -d= -f2)
_run_critical mkdir -p "$outputdir"
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"
_prep_ffmpeg_log -q
if [ "${concatsource}" != "" ] ; then
ffmpeginput="${concatsource}"
else
ffmpeginput="${sourcefile}"
fi
_run_critical ffmpeg -y ${inputoptions[@]} -v warning -ss "$START" -i "${ffmpeginput}" -vf yadif,thumbnail=100 -frames:v 1 "$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
shift
_log -e
done