-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpicam-pipeline.sh
executable file
·62 lines (51 loc) · 1.39 KB
/
picam-pipeline.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
58
59
60
61
62
#! /bin/bash
# Exit as soon as a command fail
set -e
# Check param
if [ $# -eq 0 ]
then
echo "[error] Need time argument. Usage: ./picam-pipeline <time>"
exit 1
fi
PICAM_DIR=/home/pi/picam
SCRIPT_LOCATION="/home/pi/sharepoint-rest-upload"
echo "launch record script..."
$SCRIPT_LOCATION/picam-record.sh $1
echo "get last record..."
LAST_RECORD=`ls -t $PICAM_DIR/archive | head -1`
# Check if LAST_RECORD is empty
if [ -z "$LAST_RECORD" ]
then
echo "[error] No record found in $PICAM_DIR/archive"
exit 1
fi
# Convert the record
echo "convert the record..."
today=`date +%Y-%m-%d-%H-%M-%S`
destination="$PICAM_DIR/archive/Louange-du-$today.mp4"
ffmpeg -y -i $PICAM_DIR/archive/$LAST_RECORD -c:v copy -c:a copy -bsf:a aac_adtstoasc $destination
echo "...done!"
echo "check presence of converted file..."
if [ ! -f $destination ]; then
echo "[error] no converted file found at $destination"
exit 1
fi
n=0
wait=1
until [ $n -ge 5 ]
do
echo "launch upload script..."
python3 $SCRIPT_LOCATION/rest-upload.py $destination && break
echo "[error] failed to upload, wait $wait(s) and retry $n..."
sleep $wait
n=$[$n+1]
wait=$[$wait*10] # 1, 10, 100, 1000, 10000
done
if [[ $n -eq 5 ]]; then
echo "[error] tried $n times to upload without success"
exit 1
fi
echo "...delete files"
rm $destination $PICAM_DIR/archive/$LAST_RECORD
echo "that was a long journey..."
echo "...I am done!"