This repository was archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgifme
More file actions
executable file
·80 lines (65 loc) · 2.42 KB
/
Copy pathgifme
File metadata and controls
executable file
·80 lines (65 loc) · 2.42 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
usage="Usage:
$(basename "$0") [-h]
$(basename "$0") <FILE> <START_TIME> <DURATION> [FPS]
Creates a gif from a video file.
command line arguments:
<FILE> - the path to the movie we're converting
<START_TIME> - the start time of the finished gif
<DURATION> - duration; the length of the video clip after the start time to convert
Time(s) can be in seconds, or it also accepts the \"hh:mm:ss[.xxx]\" format
[FPS] - (optional) specify an integer fps value. default is 10
For best output, it should be a factor of 100; e.g. 10, 20, 25, 50
e.g. gifme ~/Movies/your-favorite-movie.mp4 00:43:04 5
e.g. gifme ~/Movies/your-favorite-movie.mp4 01:04:02 10.5 25
Note if you want to convert the entire duration for a video file to
a gif, you can provide a duration much higher than the length of the video
e.g. gifme ~/Movies/a-short-video.mkv 0 9999999 10
requires 'imagemagick' and 'ffmpeg'
Modified from: https://github.com/holman/dotfiles/blob/master/bin/movieme
"
if [[ "$1" == "-h" || "$1" == "-help" || "$1" == "--help" ]]; then
echo "${usage}"
exit 0
fi
# quit if ffmpeg fails
set -e
# reset temp directory
rm -rf /tmp/gifme
mkdir -p /tmp/gifme
# check for command line arguments
if [ -z "$3" ]; then
echo -e "You didn't provide enough arguments.
Type 'gifme -h' for additional help.
\$1 - the path to the movie we're converting
\$2 - the start time of the finished gif
\$3 - duration; the length of the video clip after the start time to convert
Time(s) can be in seconds, or it also accepts the \"hh:mm:ss[.xxx]\" format
\$4 - (optional) specify an integer fps value. default is 10
For best output, it should be a factor of 100; e.g. 10, 20, 25, 50"
exit 1
fi
# process fps arg
fps=10
if [ ! -z "$4" ]; then
fps=$4
fi
convert_delay=$(( 100 / $fps ))
# generate output filename based on input file
current_time=$(date +%H.%M.%S)
output_filename=$(basename "$1")
output_filename="${output_filename%.*}" # remove extension
output_filename="${output_filename}-gifme-${current_time}.gif"
# create frames
# i - input
# f - force image format
# ss - start time
# t - time
# r - fps
ffmpeg -i "$1" -f image2 -ss $2 -t $3 -r $fps /tmp/gifme/d-%09d.png
printf "Converting %d frames to a gif...\n" $(ls -1 /tmp/gifme | wc -l)
# convert to gif
# delay - speed, determined by fps above
# loop 0 - make gif repeat itself
convert -delay $convert_delay -loop 0 /tmp/gifme/*.png "$output_filename"
echo -e "Created ${output_filename} successfully"