forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeframes
executable file
·64 lines (56 loc) · 2.19 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
#!/bin/bash
# makeframes
version="1.0"
unset dependencies
dependencies=(ffmpeg)
scriptdir=$(dirname "$0")
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
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) fileorpackage1 [ fileorpackage2 ...]"
echo " -h display this help"
echo
exit
}
[ "$#" = 0 ] && usage
check_dependencies "${dependencies[@]}"
# local variables
IMAGECOUNT=10
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":h" opt; do
case "$opt" in
h) usage;;
*) echo "Invalid option: -$OPTARG" ; exit 1 ;;
:) 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)
log -b
[ -s "$outputdir" ] && { report -wt "WARNING $outputdir already exists, skipping transcode" ; [ "$#" = 1 ] && exit 86 || { shift ; continue ;} ;};
BASE=$(basename "$sourcefile")
DURATION=$(ffprobe 2>/dev/null $sourcefile -show_format | grep duration | cut -d= -f2)
mkdir -p "$outputdir"
for IMAGENUMBER in $(seq 1 "$IMAGECOUNT") ; do
START=$(echo "( $DURATION / ( $IMAGECOUNT + 1 )) * $IMAGENUMBER" | bc)
report -d "Making frame $IMAGENUMBER of $IMAGECOUNT $outputdir/${BASE%.*}_${IMAGENUMBER}.tiff"
ffmpeg -y -v warning -ss "$START" -i $sourcefile -vf yadif,thumbnail=100 -frames:v 1 "$outputdir/${mediaid}_${IMAGENUMBER}.tiff"
done
shift
done
log -e