video2gif 0.0.29 → 0.0.30

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62e8037d3f2d5c9f1fd4ef4be2455b6d831407cb4485bf4169bb0d44aaafa21e
4
- data.tar.gz: 49dd66cac75ba0ddf7c98b363b39770237034695098c516ac5e62a853fb16a3e
3
+ metadata.gz: 4e3d8fc9f7c1f1753c1aeb09c6760650055182e1b5d2f68d29d1453b14c6a63d
4
+ data.tar.gz: 9525b0c28289532b777d89b6443fa9873d2ab8c94d3bd01ebcc37c27628a3b33
5
5
  SHA512:
6
- metadata.gz: 39ab1ea8910042d75f3608ea6d112a0941e98dcc42c09683ec91e93e91935bf99b8fcad2f8b586ff46c98097ffca1323babfa42d81f32f2d817e30ffa1aea511
7
- data.tar.gz: 3da078214b6d9799d1fa0cebee2d1da6b24b16656e822b359683a79a44d7d639c34c6821bdd05487e562b02b3cab6bd851b762f6898009b63bb6d560c1a6e7da
6
+ metadata.gz: bc904a92ac20deb0bbc643c2cf9fe6919fbbbb9977e78dc08fc12e824acc61e25938ba6160527fd70ecff232d556b2b617f63a84ca61269fea5d3b3404cc000f
7
+ data.tar.gz: 510759bd40cdec24eb975b68ea48e942806fc54de7c52b3ab11e67f69e6294b506ff8f5270e1b667b79d6992457b9761802615c00f40b0b68aebe86a8a5b313d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- video2gif (0.0.29)
4
+ video2gif (0.0.30)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,51 +5,43 @@ module Video2gif
5
5
  module FFmpeg
6
6
  CROP_REGEX = /crop=([0-9]+\:[0-9]+\:[0-9]+\:[0-9]+)/
7
7
 
8
+ # TODO: This whole method needs to be broken up significantly.
8
9
  def self.filtergraph(options)
9
10
  filtergraph = []
10
11
 
11
- if options[:subtitles] && options[:probe_infos][:streams].any? do |s|
12
- s[:codec_type] == 'subtitle'
13
- end
12
+ # If we want subtitles and *have* subtitles, we need some info to
13
+ # use them.
14
+ if options[:subtitles] && options[:probe_infos][:streams].any? { |s| s[:codec_type] == 'subtitle' }
14
15
  video_info = options[:probe_infos][:streams].find { |s| s[:codec_type] == 'video' }
15
16
  subtitle_info = options[:probe_infos][:streams].find_all { |s| s[:codec_type] == 'subtitle' }[options[:subtitle_index]]
17
+ end
16
18
 
17
- if Subtitles::KNOWN_TEXT_FORMATS.include?(subtitle_info[:codec_name])
18
- filtergraph << "setpts=PTS+#{Utils.duration_to_seconds(options[:seek])}/TB"
19
- filtergraph << "subtitles='#{options[:input_filename]}':si=#{options[:subtitle_index]}"
20
- filtergraph << 'setpts=PTS-STARTPTS'
21
- elsif Subtitles::KNOWN_BITMAP_FORMATS.include?(subtitle_info[:codec_name])
22
- filtergraph << "[0:s:#{options[:subtitle_index]}]scale=" + %W[
23
- flags=lanczos
24
- sws_dither=none
25
- width=#{video_info[:width]}
26
- height=#{video_info[:height]}
27
- ].join(':') + '[subs]'
28
- filtergraph << '[0:v][subs]overlay=format=auto'
29
- end
19
+ # Bitmap formatted subtitles go first so that they get scaled
20
+ # correctly.
21
+ if options[:subtitles] &&
22
+ options[:probe_infos][:streams].any? { |s| s[:codec_type] == 'subtitle' } &&
23
+ Subtitles::KNOWN_BITMAP_FORMATS.include?(subtitle_info[:codec_name])
24
+ filtergraph << "[0:s:#{options[:subtitle_index]}]scale=" + %W[
25
+ flags=lanczos
26
+ sws_dither=none
27
+ width=#{video_info[:width]}
28
+ height=#{video_info[:height]}
29
+ ].join(':') + '[subs]'
30
+ filtergraph << '[0:v][subs]overlay=format=auto'
30
31
  end
31
32
 
32
33
  # Set 'fps' filter first, drop unneeded frames instead of
33
34
  # processing those.
34
35
  filtergraph << "fps=#{ options[:fps] || 10 }"
35
36
 
36
- # Crop if needed, using either settings discovered during the
37
- # autocrop run or manually set parameters, so we don't process
38
- # additional parts of the image (and exclude it from palette
39
- # generation).
40
- if options[:autocrop]
41
- filtergraph << options[:autocrop]
42
- elsif options[:wregion] ||
43
- options[:hregion] ||
44
- options[:xoffset] ||
45
- options[:yoffset]
46
- filtergraph << 'crop=' + [
47
- "w=#{ options[:wregion] || 'in_w' }",
48
- "h=#{ options[:hregion] || 'in_h' }",
49
- "x=#{ options[:xoffset] || 0 }",
50
- "y=#{ options[:yoffset] || 0 }",
51
- ].join(':')
52
- end
37
+ # Apply automatic cropping discovered during the cropdetect run.
38
+ filtergraph << options[:autocrop] if options[:autocrop]
39
+
40
+ # Apply manual cropping, if any.
41
+ filtergraph << "crop=w=#{options[:wregion]}" if options[:wregion]
42
+ filtergraph << "crop=h=#{options[:hregion]}" if options[:hregion]
43
+ filtergraph << "crop=x=#{options[:xoffset]}" if options[:xoffset]
44
+ filtergraph << "crop=y=#{options[:yoffset]}" if options[:yoffset]
53
45
 
54
46
  # Scale here before other filters to avoid unnecessary processing.
55
47
  if options[:tonemap]
@@ -90,6 +82,16 @@ module Video2gif
90
82
  filtergraph << "eq=gamma_g=#{options[:gamma_g]}" if options[:gamma_g]
91
83
  filtergraph << "eq=gamma_b=#{options[:gamma_b]}" if options[:gamma_b]
92
84
 
85
+ # Embed text subtitles later so that they don't get processed by
86
+ # cropping, etc., which might accidentally crop them out.
87
+ if options[:subtitles] &&
88
+ options[:probe_infos][:streams].any? { |s| s[:codec_type] == 'subtitle' } &&
89
+ Subtitles::KNOWN_TEXT_FORMATS.include?(subtitle_info[:codec_name])
90
+ filtergraph << "setpts=PTS+#{Utils.duration_to_seconds(options[:seek])}/TB"
91
+ filtergraph << "subtitles='#{options[:input_filename]}':si=#{options[:subtitle_index]}"
92
+ filtergraph << 'setpts=PTS-STARTPTS'
93
+ end
94
+
93
95
  # If there is text to superimpose, do it here before palette
94
96
  # generation to ensure the color looks appropriate.
95
97
  if options[:text]
@@ -68,22 +68,26 @@ module Video2gif
68
68
  end
69
69
  end
70
70
 
71
- parser.on('--crop-size-w SIZE',
71
+ parser.on('--crop-width SIZE',
72
+ '--crop-size-w SIZE',
72
73
  'Pixel size of width to select from source video, before scaling') do |s|
73
74
  options[:wregion] = s
74
75
  end
75
76
 
76
- parser.on('--crop-size-h SIZE',
77
+ parser.on('--crop-height SIZE',
78
+ '--crop-size-h SIZE',
77
79
  'Pixel size of height to select from source video, before scaling') do |s|
78
80
  options[:hregion] = s
79
81
  end
80
82
 
81
- parser.on('--crop-offset-x OFFSET',
83
+ parser.on('--crop-x OFFSET',
84
+ '--crop-offset-x OFFSET',
82
85
  'Pixel offset from left to select from source video, before scaling') do |o|
83
86
  options[:xoffset] = o
84
87
  end
85
88
 
86
- parser.on('--crop-offset-y OFFSET',
89
+ parser.on('--crop-y OFFSET',
90
+ '--crop-offset-y OFFSET',
87
91
  'Pixel offset from top to select from source video, before scaling') do |o|
88
92
  options[:yoffset] = o
89
93
  end
@@ -257,7 +261,7 @@ module Video2gif
257
261
  exit
258
262
  end
259
263
 
260
- options[:input_filename] = args[0]
264
+ options[:input_filename] = args[0]
261
265
  options[:output_filename] = if args[1]
262
266
  args[1].end_with?('.gif') ? args[1] : args[1] + '.gif'
263
267
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Video2gif
4
- VERSION = '0.0.29'
4
+ VERSION = '0.0.30'
5
5
  end
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.29
4
+ version: 0.0.30
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-05-03 00:00:00.000000000 Z
11
+ date: 2019-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler