video2gif 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/video2gif/ffmpeg.rb +66 -75
- 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: f5e988966072feb88cc7335dc5133930c704011f7caf45ab30cb9172dc7f07c2
|
4
|
+
data.tar.gz: 4c7d0cda62bebd3350ef7f949f447b30d50e767177ec0fb78761f7456ec6221a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26c279eff6a44ad910662335e838375b77b4f754314d81784f0dc2cec30721e07f4c7ac1a8b5c52aab99fffaba9d91149b0cfb2597096020ec24193a2e701c81
|
7
|
+
data.tar.gz: 3a3f4f8c4ac6e399cc6b67e11a6627121a67f968b2d0406410cdb112007c63cd8ad1ed34df547811e3a9e1bdb0117d6874f0bae984dd5ec6287cdb424fc8b38f
|
data/lib/video2gif/ffmpeg.rb
CHANGED
@@ -4,83 +4,73 @@
|
|
4
4
|
module Video2gif
|
5
5
|
module FFMpeg
|
6
6
|
def self.filter_complex(options)
|
7
|
-
fps = options[:fps] || 10
|
8
|
-
max_colors = options[:palette] ? "max_colors=#{options[:palette]}:" : ''
|
9
|
-
width = options[:width] # default is not to scale at all
|
10
|
-
|
11
|
-
# create filter elements
|
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(':')
|
19
|
-
scale_filter = "scale=#{width}:-1:flags=lanczos:sws_dither=none" if options[:width] unless options[:tonemap]
|
20
|
-
tonemap_filters = if options[:tonemap] # TODO: detect input format
|
21
|
-
%W[
|
22
|
-
zscale=dither=none:filter=lanczos:width=#{width}:height=-1
|
23
|
-
zscale=transfer=linear:npl=100
|
24
|
-
format=yuv420p10le
|
25
|
-
zscale=primaries=bt709
|
26
|
-
tonemap=tonemap=#{options[:tonemap]}:desat=0
|
27
|
-
zscale=transfer=bt709:matrix=bt709:range=tv
|
28
|
-
format=yuv420p
|
29
|
-
].join(',')
|
30
|
-
end
|
31
|
-
eq_filter = if options[:eq]
|
32
|
-
'eq=' + %W[
|
33
|
-
contrast=#{ options[:contrast] || 1 }
|
34
|
-
brightness=#{ options[:brightness] || 0 }
|
35
|
-
saturation=#{ options[:saturation] || 1 }
|
36
|
-
gamma=#{ options[:gamma] || 1 }
|
37
|
-
gamma_r=#{ options[:gamma_r] || 1 }
|
38
|
-
gamma_g=#{ options[:gamma_g] || 1 }
|
39
|
-
gamma_b=#{ options[:gamma_b] || 1 }
|
40
|
-
].join(':')
|
41
|
-
end
|
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'
|
46
|
-
drawtext_filter = if options[:text]
|
47
|
-
count_of_lines = options[:text].scan(/\\n/).count + 1
|
48
|
-
|
49
|
-
x = options[:xpos] || '(main_w/2-text_w/2)'
|
50
|
-
y = options[:ypos] || "(main_h-line_h*1.5*#{count_of_lines})"
|
51
|
-
size = options[:textsize] || 32
|
52
|
-
color = options[:textcolor] || 'white'
|
53
|
-
border = options[:textborder] || 3
|
54
|
-
font = options[:textfont] || 'Arial'
|
55
|
-
style = options[:textvariant] || 'Bold'
|
56
|
-
text = options[:text]
|
57
|
-
.gsub(/\\n/, '')
|
58
|
-
.gsub(/([:])/, '\\\\\\\\\\1')
|
59
|
-
.gsub(/([,])/, '\\\\\\1')
|
60
|
-
.gsub(/\b'\b/, "\u2019")
|
61
|
-
.gsub(/\B"\b([^"\u201C\u201D\u201E\u201F\u2033\u2036\r\n]+)\b?"\B/, "\u201C\\1\u201D")
|
62
|
-
.gsub(/\B'\b([^'\u2018\u2019\u201A\u201B\u2032\u2035\r\n]+)\b?'\B/, "\u2018\\1\u2019")
|
63
|
-
|
64
|
-
'drawtext=' + %W[
|
65
|
-
x='#{x}'
|
66
|
-
y='#{y}'
|
67
|
-
fontsize='#{size}'
|
68
|
-
fontcolor='#{color}'
|
69
|
-
borderw='#{border}'
|
70
|
-
fontfile='#{font}'\\\\:style='#{style}'
|
71
|
-
text='#{text}'
|
72
|
-
].join(':')
|
73
|
-
end
|
74
|
-
|
75
7
|
filter_complex = []
|
76
8
|
|
77
|
-
filter_complex <<
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
9
|
+
filter_complex << "fps=#{ options[:fps] || 10 }"
|
10
|
+
|
11
|
+
if options[:autocrop]
|
12
|
+
filter_complex << options[:autocrop]
|
13
|
+
else
|
14
|
+
filter_complex << 'crop=' + [
|
15
|
+
"w=#{ options[:wregion] || 'in_w' }",
|
16
|
+
"h=#{ options[:hregion] || 'in_h' }",
|
17
|
+
"x=#{ options[:xoffset] || 0 }",
|
18
|
+
"y=#{ options[:yoffset] || 0 }",
|
19
|
+
].join(':')
|
20
|
+
end
|
21
|
+
|
22
|
+
if options[:width] && !options[:tonemap]
|
23
|
+
filter_complex << "scale=flags=lanczos:sws_dither=none:width=#{options[:width]}:height=-1"
|
24
|
+
end
|
25
|
+
|
26
|
+
if options[:tonemap]
|
27
|
+
filter_complex << "zscale=dither=none:filter=lanczos:width=#{options[:width]}:height=-1" if options[:width]
|
28
|
+
filter_complex << 'zscale=transfer=linear:npl=100'
|
29
|
+
filter_complex << 'zscale=npl=100'
|
30
|
+
filter_complex << 'format=gbrpf32le'
|
31
|
+
filter_complex << 'zscale=primaries=bt709'
|
32
|
+
filter_complex << "tonemap=tonemap=#{options[:tonemap]}:desat=0"
|
33
|
+
filter_complex << 'zscale=transfer=bt709:matrix=bt709:range=tv'
|
34
|
+
filter_complex << 'format=yuv420p'
|
35
|
+
end
|
36
|
+
|
37
|
+
filter_complex << "eq=contrast=#{options[:contrast]}" if options[:contrast]
|
38
|
+
filter_complex << "eq=brightness=#{options[:brightness]}" if options[:brightness]
|
39
|
+
filter_complex << "eq=saturation=#{options[:saturation]}" if options[:saturation]
|
40
|
+
filter_complex << "eq=gamma=#{options[:gamma]}" if options[:gamma]
|
41
|
+
filter_complex << "eq=gamma_r=#{options[:gamma_r]}" if options[:gamma_r]
|
42
|
+
filter_complex << "eq=gamma_g=#{options[:gamma_g]}" if options[:gamma_g]
|
43
|
+
filter_complex << "eq=gamma_b=#{options[:gamma_b]}" if options[:gamma_b]
|
44
|
+
|
45
|
+
if options[:text]
|
46
|
+
count_of_lines = options[:text].scan(/\\n/).count + 1
|
47
|
+
text = options[:text]
|
48
|
+
.gsub(/\\n/, '')
|
49
|
+
.gsub(/([:])/, '\\\\\\\\\\1')
|
50
|
+
.gsub(/([,])/, '\\\\\\1')
|
51
|
+
.gsub(/\b'\b/, "\u2019")
|
52
|
+
.gsub(/\B"\b([^"\u201C\u201D\u201E\u201F\u2033\u2036\r\n]+)\b?"\B/, "\u201C\\1\u201D")
|
53
|
+
.gsub(/\B'\b([^'\u2018\u2019\u201A\u201B\u2032\u2035\r\n]+)\b?'\B/, "\u2018\\1\u2019")
|
54
|
+
|
55
|
+
filter_complex << 'drawtext=' + [
|
56
|
+
"x='#{ options[:xpos] || '(main_w/2-text_w/2)' }'",
|
57
|
+
"y='#{ options[:ypos] || "(main_h-line_h*1.5*#{count_of_lines})" }'",
|
58
|
+
"fontsize='#{ options[:textsize] || 32 }'",
|
59
|
+
"fontcolor='#{ options[:textcolor] || 'white' }'",
|
60
|
+
"borderw='#{ options[:textborder] || 3 }'",
|
61
|
+
"fontfile='#{ options[:textfont] || 'Arial'}'\\\\:style='#{options[:textvariant] || 'Bold' }'",
|
62
|
+
"text='#{text}'",
|
63
|
+
].join(':')
|
64
|
+
end
|
65
|
+
|
66
|
+
filter_complex << 'split [o1] [o2]'
|
67
|
+
if options[:palette]
|
68
|
+
filter_complex << "[o1] palettegen=#{options[:palette]}:stats_mode=diff [p]"
|
69
|
+
else
|
70
|
+
filter_complex << "[o1] palettegen=stats_mode=diff [p]"
|
71
|
+
end
|
72
|
+
filter_complex << '[o2] fifo [o3]'
|
73
|
+
filter_complex << '[o3] [p] paletteuse=dither=floyd_steinberg:diff_mode=rectangle'
|
84
74
|
|
85
75
|
filter_complex.join(',')
|
86
76
|
end
|
@@ -104,6 +94,7 @@ module Video2gif
|
|
104
94
|
command = ['ffmpeg']
|
105
95
|
command << '-y' # always overwrite
|
106
96
|
command << '-analyzeduration' << '2147483647' << '-probesize' << '2147483647'
|
97
|
+
command << '-loglevel' << 'level+verbose'
|
107
98
|
command << '-ss' << options[:seek] if options[:seek]
|
108
99
|
command << '-t' << options[:time] if options[:time]
|
109
100
|
command << '-i' << options[:input_filename]
|
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.10
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|