-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffprobe-brief
executable file
·70 lines (65 loc) · 1.2 KB
/
ffprobe-brief
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
65
66
67
68
69
70
#!/bin/sh -Ceu
glob_dir() {
paths=$*
for path in $paths; do
if [ -d "$path" ]; then
find "$path" -maxdepth 1 -type f | (
if [ "$path" = . ]; then
sed 's#^./##'
else
cat
fi
)
else
echo "$path"
fi
done
}
is_video() {
filename="$1"
file -b --mime-type "$filename" | grep -q ^video
}
info() {
filename="$1"
if is_video "$filename"; then
ffprobe -hide_banner "$filename" 2>&1 | awk '
BEGIN {
split("", r);
}
($1 == "Duration:") {
sub(/,$/, "", $2);
r["duration"] = $2;
}
($1 == "Stream" && /Video:/) {
if (match($0, / ([[:digit:]]+x[[:digit:]]+) /, a)) {
r["resolution"] = a[1];
}
if (match($0, /((\.|[[:digit:]])+) fps,/, a)) {
r["fps"] = a[1];
}
exit;
}
END {
print(r["duration"], r["fps"], r["resolution"]);
}
'
fi | (
IFS=' ' read -r duration fps resolution
#command -p printf '%s %s %q\n' "${duration:--} ${resolution:--} $filename"
/usr/bin/printf '%s %s %s %q\n' \
"${duration:--} ${resolution:--} ${fps:--} $filename"
)
}
paths=$*
if [ -z "$paths" ]; then
paths=.
fi
for filename in $(glob_dir "$paths"); do
info "$filename"
done | (
if isatty stdin; then
column -t
else
cat
fi
)