-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp42gif.zsh
More file actions
executable file
·57 lines (45 loc) · 1.28 KB
/
mp42gif.zsh
File metadata and controls
executable file
·57 lines (45 loc) · 1.28 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
#!/bin/zsh
# Start a private Zsh history session so this script's commands are not recorded
if builtin fc -p 2>/dev/null; then
# Ensure we restore the previous history when the script exits
trap 'builtin fc -P 2>/dev/null' EXIT
fi
if [[ $# -eq 0 ]]; then
echo "Usage: $0 input.mp4"
exit 1
fi
input="$1"
if [[ ! -f "$input" ]]; then
echo "❌ File not found: $input"
exit 2
fi
# Имя выходного файла по дате/времени
timestamp=$(date "+%Y%m%d_%H%M%S")
output="./${timestamp}.gif"
tmpdir="/tmp/mp42gif_${timestamp}"
mkdir -p "$tmpdir"
echo "🔧 Extracting frames from $input..."
ffmpeg -hide_banner -loglevel error \
-i "$input" \
-vf "fps=15,scale=iw:-1:flags=lanczos" \
-c:v png -pix_fmt rgba "$tmpdir/frame_%04d.png"
if [[ $? -ne 0 ]]; then
echo "❌ Frame extraction failed."
rm -rf "$tmpdir"
exit 3
fi
echo "🎨 Creating GIF..."
gifski --fps 15 --quality 100 --width 800 -o "$output" "$tmpdir"/frame_*.png
if [[ $? -ne 0 ]]; then
echo "❌ GIF creation failed."
rm -rf "$tmpdir"
exit 4
fi
echo "🧹 Cleaning up..."
rm -rf "$tmpdir"
echo "🗑 Sending original file to system Trash..."
trash "$input" || {
echo "⚠️ 'trash' command not found. Install it with: brew install trash"
exit 5
}
echo "✅ Done! Output saved to: $output"