forked from noctuid/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffcut
executable file
·72 lines (62 loc) · 2.14 KB
/
ffcut
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
#!/bin/bash
# TODO
# - keep quality when not using copy? (has been nice so far but I notice size
# goes way down when not using copy)
# If I recall correctly, the order in which you give the -ss and -t flags change the behaviour subtly. If you declare them before -i, it seeks in the input file and starts decoding from there (which is not always accurate). If you declare it after, it decodes the file as if it was playing and then discards the content outside the boundaries.
function print_help() {
echo "
$ ffcut [options] /path/to/video_file
Creates a cut video and optionally creates a gif from it.
Meant for use with MPV.
-a <time> specify start time (default: contents of /tmp/ffcut/start)
(see the Time duration section of the ffmpeg-utils manpage for
formatting information)
-b <time> specify end time (default: contents of /tmp/ffcut/end)
-c copy the video section; fast but starts at key frame (start time
will be innacurate) (default: false)
-o <name> choose an output name for the cut video
(default: cut_<date>.<extension>)
-m make a gif of the cut video
-h print help and exit
"
if [[ $1 == illegal_opt ]]; then
exit 1
else
exit 0
fi
}
filepath="${!#}"
extension="${filepath##*.}"
output_name="cut_$(date +%Y.%m.%d_%H:%M:%S).$extension"
# in case not given full path
full_path=$(readlink -f "$filepath")
mkdir -p ~/move/gif
cd ~/move/gif || exit 1
start_time=$(< /tmp/ffcut/start)
end_time=$(< /tmp/ffcut/end)
make_gif=false
copy=false
while getopts :a:b:c:o:mh opt
do
case $opt in
a) start_time=$OPTARG;;
b) end_time=$OPTARG;;
c) copy=true;;
o) output_name=$OPTARG;;
m) make_gif=true;;
h) print_help;;
*) print_help illegal_opt;;
esac
done
# create new video cut from original
# copy is faster but must start at a key frame (so time won't be accurate)
if $copy; then
ffmpeg -i "$full_path" -ss "$start_time" -to "$end_time" -c copy "$output_name"
else
# can take a while
ffmpeg -i "$full_path" -strict -2 -ss "$start_time" -to "$end_time" "$output_name"
fi
# to go ahead and make a gif with default settings
if $make_gif; then
makegif ~/move/gif/"$output_name"
fi