forked from noctuid/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakewebm
executable file
·76 lines (64 loc) · 2.11 KB
/
makewebm
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
#!/bin/bash
# Simple wrapper for creating a webm from a video using ffmpeg
# https://wiki.installgentoo.com/index.php/WebM#Converting_with_ffmpeg
# https://superuser.com/questions/556463/converting-video-to-webm-with-ffmpeg-avconv
# TODO if ever use this again
# ffmpeg -i %1 -r 30 -c:v libvpx-vp9 -pass 1 -b:v 1500K -threads 4 -speed 4 -tile-columns 6 -frame-parallel 1 -an -f webm -y NUL
# ffmpeg -i %1 -r 30 -c:v libvpx-vp9 -pass 2 -b:v 1500K -threads 4 -speed 1 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 -c:a libopus -b:a 64k -f webm -y "%~n1.webm"
# shift
# >add -f 1, -f 2 as a flag for your two passes
# ffmpeg -ss <start_time> -i <source> -an -t <length> -b:v <24/length>M -vf "scale=-1:480" <destination_path>
function print_help() {
echo "
$ makewebm /path/to/video
Creates a webm from a video.
-w <width> specify a width for the webm
(default: not scaled to any specific width)
-o <filename> specify an output name (default: output.webm)
-d <dir> specify the dir to create the frames and output webm in
(default: ~/move/gif)
-q <crf> specify the crf value from 4-63; lower is higher quality
(default: 10)
-a include audio in webm (default: false)
-h print help and exit
"
if [[ $1 == illegal_opt ]]; then
exit 1
else
exit 0
fi
}
# default values
cur_time=$(date +%Y.%m.%d_%H:%M:%S)
outfile=${cur_time}_output.webm
outdir=$HOME/move/gif
quality=10
audio=false
while getopts :w:o:d:q:ah opt
do
case $opt in
w) width=$OPTARG;;
o) outfile="$OPTARG";;
d) outdir="$OPTARG";;
q) quality="$OPTARG";;
a) audio=true;;
h) print_help;;
*) print_help illegal_opt;;
esac
done
infile=${!#}
infile=$(readlink -f "$infile")
mkdir -p "$outdir"
cd "$outdir"
# max video bit rate of 3M
ffmpeg_command="ffmpeg -i \"$infile\" -c:v libvpx -crf $quality -b:v 3M"
if [[ -n $width ]]; then
ffmpeg_command="$ffmpeg_command -vf scale=$width:-1"
fi
if $audio; then
ffmpeg_command="$ffmpeg_command -c:a libvorbis -q:a 4"
else
ffmpeg_command="$ffmpeg_command -an"
fi
ffmpeg_command="$ffmpeg_command \"$outfile\""
eval "$ffmpeg_command"