forked from labithiotis/ffmpeg-watch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·57 lines (48 loc) · 1.06 KB
/
run.sh
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
#!/bin/bash
set -e
WATCH=${WATCH:-/watch}
OUTPUT=${OUTPUT:-/output}
STORAGE=${STORAGE:-/storage}
run() {
cd "$WATCH" || exit
FILES=$(find . -type f -not -path '*/\.*' | egrep '.*')
cd ..
echo "$FILES" | while read -r FILE
do
process "$FILE"
done;
}
process() {
file=$1
filepath=${file:2}
input="$WATCH"/"$filepath"
destination="$STORAGE"/"${filepath%.*}".wav
cd "$STORAGE" && mkdir -p "$(dirname "$filepath")" && cd ..
echo $(date +"%Y-%m-%d-%T")
echo "Found $file"
trap 'exit' INT
ffmpeg \
-hide_banner \
-y \
-loglevel warning \
-i "$input" \
-ar 8000 \
-ac 1 \
-c:a pcm_mulaw \
"$destination"
# Goes so fast no need to do this
# killall ffmpeg >/dev/null
echo "Finished encoding $filepath"
echo $(date +"%Y-%m-%d-%T")
path=${filepath%/*}
mv "$destination" "$OUTPUT"/"$path"
rm -rf "$WATCH"/"$path"
}
processes=$(ps aux | grep -i "ffmpeg" | awk '{print $11}')
for i in $processes; do
if [ "$i" == "ffmpeg" ] ;then
echo 'Waiting for current econding to complete...'
exit 0
fi
done
run