-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebp2mp4.zsh
More file actions
executable file
·54 lines (42 loc) · 1.15 KB
/
webp2mp4.zsh
File metadata and controls
executable file
·54 lines (42 loc) · 1.15 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
#!/bin/zsh
# WebP to MP4 converter with timestamp naming and auto-cleanup
# Converts animated WebP to video format
set -euo pipefail
if [[ $# -eq 0 ]]; then
echo "Usage: webp2mp4.zsh input.webp"
exit 1
fi
input="$1"
# Validate input is a .webp file
if [[ "${input:e}" != "webp" ]]; then
echo "❌ Input must be a .webp file"
exit 2
fi
# Check if file exists
if [[ ! -f "$input" ]]; then
echo "❌ File not found: $input"
exit 3
fi
# Check if ffmpeg is installed
if ! command -v ffmpeg &> /dev/null; then
echo "❌ ffmpeg not found. Install with: brew install ffmpeg"
exit 4
fi
# Generate output filename: basename_YYYY-MM-DD_HH-MM-SS.mp4
timestamp=$(date "+%Y-%m-%d_%H-%M-%S")
basename="${input:t:r}"
output="${input:h}/${basename}_${timestamp}.mp4"
echo "🎬 Converting WebP to MP4..."
# Convert WebP to MP4 using ffmpeg
ffmpeg -hide_banner -loglevel error -i "$input" \
-c:v libx264 -pix_fmt yuv420p -preset fast -crf 23 \
-movflags +faststart \
"$output" || {
echo "❌ Conversion failed"
exit 5
}
# Move original to Trash
echo "🗑 Moving original to Trash..."
mv "$input" ~/.Trash/
echo "✅ Done: $output"
ls -lh "$output"