-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMP4Duration
More file actions
executable file
·58 lines (48 loc) · 1.06 KB
/
getMP4Duration
File metadata and controls
executable file
·58 lines (48 loc) · 1.06 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
52
53
54
55
56
57
58
#!/bin/bash
which ffmpeg > /dev/null 2>&1
[ $? -ne 0 ] && echo "Cannot find ffmpeg" && exit 1
IFS="
"
if [ $# -eq 1 ]
then
DIR=$1
else
DIR="."
fi
cd $DIR
HOURS=0
MINS=0
SECS=0
for FILE in $(find . -iname '*.mp4'| sort -n)
do
[ -f $FILE ] || continue
F=$(echo $FILE | sed 's/^.\///g')
echo -n "$F "
DURATION=$(ffmpeg -i "$FILE" 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// | cut -f1 -d.)
echo $DURATION
HOUR=$(echo $DURATION | cut -f1 -d: | sed 's/^0//')
MIN=$(echo $DURATION | cut -f2 -d: | sed 's/^0//')
SEC=$(echo $DURATION | cut -f3 -d: | sed 's/^0//')
HOURS=$(( $HOURS + $HOUR ))
MINS=$(( $MINS + $MIN ))
SECS=$(( $SECS + $SEC ))
done
if [ "$HOURS:$MINS:$SEC" = "0:0:0" ]
then
echo 00:00:00
fi
if [ $SECS -gt 59 ]
then
M=$(( $SECS / 60))
SECS=$(( $SECS % 60))
MINS=$(( $MINS + $M ))
fi
if [ $MINS -gt 59 ]
then
H=$(( $MINS / 60))
MINS=$(( $MINS % 60))
HOURS=$(( $HOURS + $H ))
fi
[ $SECS -lt 10 ] && SECS="0$SECS"
[ $MINS -lt 10 ] && MINS="0$MINS"
echo TOTAL: ${HOURS}:${MINS}:${SECS}