-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecpipe_handler.sh
More file actions
executable file
·51 lines (38 loc) · 1.23 KB
/
execpipe_handler.sh
File metadata and controls
executable file
·51 lines (38 loc) · 1.23 KB
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
#!/bin/bash
# For security
INDIR=/tmp/uploads
OUTDIR=/tmp/uploads/previews
# chmod of file && dir
CHMOD=0777
create_preview() {
#echo -n "Processing"
INFILE=$INDIR/$1
OUTFILE=$OUTDIR/$1
# check file exists
if [ ! -f "$INFILE" -o -e "$OUTFILE" ]; then
echo "File $INFILE not exists. Or $OUTFILE was processed" >&2
return 1;
fi
# check dirs
# ../../../../etc/passwd
_filepath=$(cd -P -- `dirname -- $INFILE` && pwd -P)/$(basename $INFILE)
_filepath=$(echo $_filepath | sed "s#^${INDIR}[/]*##g")
INFILE="$INDIR/$_filepath"
OUTFILE="$OUTDIR/$_filepath"
if [ ! -f "$INFILE" -o -e "$OUTFILE" ]; then
echo "File $INFILE not exists. Or $OUTFILE was processed" >&2
return 1;
fi
# create preview directory
[ -d `dirname $OUTFILE` ] || mkdir -m $CHMOD -p `dirname $OUTFILE` >/dev/null 2>&1
( ffmpeg -y -i "$INFILE" -ss 0:00:30 -t 0:00:33 \
-f aiff - | sox -t aiff - \
-t aiff - fade 1 0:30 3 | ffmpeg -y -i - -ab 192k "$OUTFILE" ) >/dev/null 2>&1 && echo "Successful created preview for $1"
chmod $CHMOD $OUTFILE
}
# DEBUG:
# create_preview ../../../../etc/passwd
# create_preview R.E.M._-_Loosing_my_religion.mp3
# exit;
create_preview $@
#exit 0;