video2gif 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/video2gif/cli.rb +2 -2
- data/lib/video2gif/ffmpeg.rb +18 -37
- data/lib/video2gif/options.rb +3 -3
- data/lib/video2gif/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de00f9f371c9632397ca52a27968a790f7e68fc58580b5438dfe9a73600a072e
|
4
|
+
data.tar.gz: 159321148a290683426e35b76aa5a9f2ebe2cc1e78f122ebc07b2738e67f02c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a067a16a488490ac8d076cac3802b1f4d99428507b59f1abd72f414fdc90c7a3eea80f345a40aaa95c78faeff04016ebffe2908a15ca00b6fb5f7f365bed56d
|
7
|
+
data.tar.gz: 0fa948c4872e6ca1297e2a6c4c9b5dffdb89ff2ecd232b2c16bfea75bb085cbdc9779bceb353ef552cbc4741ed8a1c5559f7a3160b59578d5f46dd46a5ab16a1
|
data/Gemfile.lock
CHANGED
data/lib/video2gif/cli.rb
CHANGED
@@ -11,14 +11,14 @@ module Video2gif
|
|
11
11
|
logger = Logger.new(STDOUT)
|
12
12
|
options = Video2gif::Options.parse(ARGV)
|
13
13
|
|
14
|
-
if options[:
|
14
|
+
if options[:autocrop]
|
15
15
|
Open3.popen3(*Video2gif::FFMpeg.cropdetect_command(options, logger)) do |stdin, stdout, stderr, thread|
|
16
16
|
stdin.close
|
17
17
|
stdout.close
|
18
18
|
stderr.each(chomp: true) do |line|
|
19
19
|
logger.info(line) if options[:verbose] unless options[:quiet]
|
20
20
|
if line.include?('Parsed_cropdetect')
|
21
|
-
options[:
|
21
|
+
options[:autocrop] = line.match('crop=([0-9]+\:[0-9]+\:[0-9]+\:[0-9]+)')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
stderr.close
|
data/lib/video2gif/ffmpeg.rb
CHANGED
@@ -9,23 +9,22 @@ module Video2gif
|
|
9
9
|
width = options[:width] # default is not to scale at all
|
10
10
|
|
11
11
|
# create filter elements
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
].join(':')
|
12
|
+
fps_filter = "fps=#{fps}"
|
13
|
+
crop_filter = options[:autocrop] || 'crop=' + %W[
|
14
|
+
w=#{ options[:wregion] || 'in_w' }
|
15
|
+
h=#{ options[:hregion] || 'in_h' }
|
16
|
+
x=#{ options[:xoffset] || 0 }
|
17
|
+
y=#{ options[:yoffset] || 0 }
|
18
|
+
].join(':')
|
20
19
|
scale_filter = "scale=#{width}:-1:flags=lanczos:sws_dither=none" if options[:width] unless options[:tonemap]
|
21
20
|
tonemap_filters = if options[:tonemap] # TODO: detect input format
|
22
21
|
%W[
|
23
|
-
zscale=
|
24
|
-
zscale=
|
22
|
+
zscale=dither=none:filter=lanczos:width=#{width}:height=-1
|
23
|
+
zscale=transfer=linear:npl=100
|
25
24
|
format=yuv420p10le
|
26
|
-
zscale=
|
25
|
+
zscale=primaries=bt709
|
27
26
|
tonemap=tonemap=#{options[:tonemap]}:desat=0
|
28
|
-
zscale=
|
27
|
+
zscale=transfer=bt709:matrix=bt709:range=tv
|
29
28
|
format=yuv420p
|
30
29
|
].join(',')
|
31
30
|
end
|
@@ -40,8 +39,10 @@ module Video2gif
|
|
40
39
|
gamma_b=#{ options[:gamma_b] || 1 }
|
41
40
|
].join(':')
|
42
41
|
end
|
43
|
-
|
44
|
-
|
42
|
+
split_filter = 'split [o1] [o2]'
|
43
|
+
palettegen_filter = "[o1] palettegen=#{max_colors}stats_mode=diff [p]"
|
44
|
+
fifo_filter = '[o2] fifo [o3]'
|
45
|
+
paletteuse_filter = '[o3] [p] paletteuse=dither=floyd_steinberg:diff_mode=rectangle'
|
45
46
|
drawtext_filter = if options[:text]
|
46
47
|
count_of_lines = options[:text].scan(/\\n/).count + 1
|
47
48
|
|
@@ -73,30 +74,13 @@ module Video2gif
|
|
73
74
|
|
74
75
|
filter_complex = []
|
75
76
|
|
76
|
-
|
77
|
-
# before applying the palettegen so that we accurately predict the
|
78
|
-
# final palette
|
79
|
-
filter_complex << palettegen_fps_filter
|
80
|
-
filter_complex << crop_filter if crop_filter
|
81
|
-
filter_complex << scale_filter if options[:width] unless options[:tonemap]
|
82
|
-
filter_complex << tonemap_filters if options[:tonemap]
|
83
|
-
filter_complex << eq_filter if options[:eq]
|
84
|
-
filter_complex << drawtext_filter if options[:text]
|
85
|
-
|
86
|
-
# then generate the palette (and label this filter stream)
|
87
|
-
filter_complex << palettegen_filter + '[palette]'
|
88
|
-
|
89
|
-
# then refer back to the first video input stream and the filter
|
90
|
-
# complex stream to apply the generated palette to the video stream
|
91
|
-
# along with the other filters (drawing text last so that it isn't
|
92
|
-
# affected by scaling)
|
93
|
-
filter_complex << '[0:v][palette]' + paletteuse_filter
|
94
|
-
filter_complex << paletteuse_fps_filter
|
77
|
+
filter_complex << fps_filter
|
95
78
|
filter_complex << crop_filter if crop_filter
|
96
79
|
filter_complex << scale_filter if options[:width] unless options[:tonemap]
|
97
80
|
filter_complex << tonemap_filters if options[:tonemap]
|
98
81
|
filter_complex << eq_filter if options[:eq]
|
99
82
|
filter_complex << drawtext_filter if options[:text]
|
83
|
+
filter_complex << split_filter << palettegen_filter << fifo_filter << paletteuse_filter
|
100
84
|
|
101
85
|
filter_complex.join(',')
|
102
86
|
end
|
@@ -104,11 +88,10 @@ module Video2gif
|
|
104
88
|
def self.cropdetect_command(options, logger)
|
105
89
|
command = ['ffmpeg']
|
106
90
|
command << '-analyzeduration' << '2147483647' << '-probesize' << '2147483647'
|
107
|
-
command << '-nostdin'
|
108
91
|
command << '-ss' << options[:seek] if options[:seek]
|
109
92
|
command << '-t' << options[:time] if options[:time]
|
110
93
|
command << '-i' << options[:input_filename]
|
111
|
-
command << '-filter_complex' << "cropdetect=limit=#{options[:
|
94
|
+
command << '-filter_complex' << "cropdetect=limit=#{options[:autocrop]}"
|
112
95
|
command << '-f' << 'null'
|
113
96
|
command << '-'
|
114
97
|
|
@@ -121,12 +104,10 @@ module Video2gif
|
|
121
104
|
command = ['ffmpeg']
|
122
105
|
command << '-y' # always overwrite
|
123
106
|
command << '-analyzeduration' << '2147483647' << '-probesize' << '2147483647'
|
124
|
-
command << '-nostdin'
|
125
107
|
command << '-ss' << options[:seek] if options[:seek]
|
126
108
|
command << '-t' << options[:time] if options[:time]
|
127
109
|
command << '-i' << options[:input_filename]
|
128
110
|
command << '-filter_complex' << filter_complex(options)
|
129
|
-
command << '-gifflags' << '+transdiff' # enabled by default
|
130
111
|
command << '-f' << 'gif'
|
131
112
|
command << options[:output_filename]
|
132
113
|
|
data/lib/video2gif/options.rb
CHANGED
@@ -81,11 +81,11 @@ module Video2gif
|
|
81
81
|
options[:yoffset] = o
|
82
82
|
end
|
83
83
|
|
84
|
-
parser.on('-
|
85
|
-
'--
|
84
|
+
parser.on('-a [THRESHOLD]',
|
85
|
+
'--autocrop [THRESHOLD]',
|
86
86
|
'Attempt automatic cropping based on black region, scaled',
|
87
87
|
'from 0 (nothing) to 255 (everything), default threshold 24') do |c|
|
88
|
-
options[:
|
88
|
+
options[:autocrop] = c || 24
|
89
89
|
end
|
90
90
|
|
91
91
|
parser.on('--contrast CONTRAST',
|
data/lib/video2gif/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: video2gif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emily St.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|