-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmpv-screenshots.sh
77 lines (66 loc) · 2.47 KB
/
mpv-screenshots.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
while getopts ":f:s:i:n:v" opt; do
case $opt in
f)
declare -r file="$OPTARG"
;;
s)
declare -r startFrame="$OPTARG"
;;
i)
declare -r intervalScreenshots="$OPTARG"
;;
n)
declare -r numberScreenshots="$OPTARG"
;;
v)
declare -r verbose="TRUE"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Quit if we missed -f, -s or -n
if [[ -z "$file" ]] || [[ -z "$startFrame" ]] || [[ -z "$numberScreenshots" ]] ; then
printf 'You must at the minimum set -f, -s and -n
-f <the video file>
-s <the number of the frame of the first screenshot>
-i <the interval of frames of the next screenshot>
-n <the number of screenshots you want>
-v <TRUE or FALSE>\n'
exit 1
fi
# Informations grabbing
declare -r filename="$(basename "${file}")"
declare -r lastFrame="$(mpv --term-playing-msg='frame=${estimated-frame-count}' --load-scripts=no --quiet --vo=null --ao=null --no-sub --no-cache --no-config --frames 1 "$file" | grep 'frame' | cut -d '=' -f2)"
declare -r fpsVideo="$(mpv --term-playing-msg='fps=${estimated-vf-fps}' --load-scripts=no --quiet --vo null --ao=null --no-sub --no-cache --no-config --frames 1 "$file" | grep 'fps' | cut -d '=' -f2)"
# Declare interval for each screenshot
if [[ -z "$intervalScreenshots" ]] ; then
declare -r diffFrame="$(bc -l <<< "$lastFrame - $startFrame")"
declare -r intervalFrame="$(bc -l <<< "$diffFrame / $numberScreenshots")"
else
declare -r intervalFrame="$intervalScreenshots"
fi
# Looping to take screenshots
declare currentFrame="$startFrame"
for i in $(seq 1 "$numberScreenshots") ; do
declare currentTime="$(bc -l <<< "$currentFrame / $fpsVideo")"
if [[ -n "$verbose" ]] ; then
printf 'Filename: %s\n\n' "$filename"
printf 'Current time: %.2f\n\n' "$currentTime"
printf 'Last frame: %s\n' "$lastFrame"
printf 'FPS: %s\n' "$fpsVideo"
printf 'Interval: %s\n' "$intervalFrame"
printf 'Screenshot: %02d\n\n\n' "$i"
fi
# Debug line
# mpv --really-quiet --load-scripts=no --no-audio --no-sub --frames 1 --start "$currentTime" "$file" -o "${filename%.*}_${currentTime%%0*}.png"
mpv --really-quiet --ao=null --no-sub --frames 1 --start "$currentTime" "$file" --vo image --vo-image-format png -o "$(printf '%02d_%s.png' "$i" "${filename%.*}")"
currentFrame="$(bc -l <<< "$currentFrame + $intervalFrame")"
done