screen-recorder 1.3.0 → 1.6.0

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.
@@ -6,17 +6,17 @@ module ScreenRecorder
6
6
  class Options
7
7
  attr_reader :all
8
8
 
9
- DEFAULT_LOG_FILE = 'ffmpeg.log'.freeze
10
- DEFAULT_FPS = 15.0
9
+ DEFAULT_LOG_FILE = 'ffmpeg.log'.freeze
10
+ DEFAULT_FPS = 15.0
11
11
  DEFAULT_MAC_INPUT_PIX_FMT = 'uyvy422'.freeze # For avfoundation
12
- DEFAULT_PIX_FMT = 'yuv420p'.freeze
13
- YUV420P_SCALING = '"scale=trunc(iw/2)*2:trunc(ih/2)*2"'.freeze
12
+ DEFAULT_PIX_FMT = 'yuv420p'.freeze
13
+ YUV420P_SCALING = '"scale=trunc(iw/2)*2:trunc(ih/2)*2"'.freeze
14
14
 
15
15
  def initialize(options)
16
16
  # @todo Consider using OpenStruct
17
- @all = verify_options options
18
- advanced[:input] = default_advanced_input.merge(advanced_input)
19
- advanced[:output] = default_advanced_output.merge(advanced_output)
17
+ @all = verify_options options
18
+ advanced[:input] = default_advanced_input.merge(advanced_input)
19
+ advanced[:output] = default_advanced_output.merge(advanced_output)
20
20
  advanced[:log] ||= DEFAULT_LOG_FILE
21
21
 
22
22
  # Fix for using yuv420p pixel format for output
@@ -74,9 +74,9 @@ module ScreenRecorder
74
74
  def parsed
75
75
  vals = "-f #{capture_device} "
76
76
  vals << parse_advanced(advanced_input)
77
- vals << "-i #{input} "
78
- vals << parse_advanced(advanced_output)
77
+ vals << "-i #{input} " unless advanced_input[:i] # Input provided by user
79
78
  vals << parse_advanced(advanced)
79
+ vals << parse_advanced(advanced_output)
80
80
  vals << output
81
81
  end
82
82
 
@@ -91,7 +91,7 @@ module ScreenRecorder
91
91
  TypeChecker.check options, Hash
92
92
  TypeChecker.check options[:advanced], Hash if options[:advanced]
93
93
  missing_options = required_options.select { |req| options[req].nil? }
94
- err = "Required options are missing: #{missing_options}"
94
+ err = "Required options are missing: #{missing_options}"
95
95
  raise(ArgumentError, err) unless missing_options.empty?
96
96
 
97
97
  options
@@ -131,31 +131,32 @@ module ScreenRecorder
131
131
  def parse_advanced(opts)
132
132
  # @todo Replace arr with opts.each_with_object([])
133
133
  arr = []
134
+ rejects = %i[input output log]
134
135
  # Do not parse input/output and log as they're placed separately in #parsed
135
- opts.reject { |k, _| %i[input output log].include? k }
136
+ opts.reject { |k, _| rejects.include? k }
136
137
  .each do |k, v|
137
138
  arr.push "-#{k} #{v}" unless v.nil? # Ignore blank params
138
139
  end
139
- arr.join(' ') + ' '
140
+ "#{arr.join(' ')} "
140
141
  end
141
142
 
142
143
  #
143
144
  # Returns input capture device based on user given value or the current OS.
144
145
  #
145
146
  def determine_capture_device
146
- # User given capture device or format
147
+ # User given capture device or format from advanced configs Hash
147
148
  # @see https://www.ffmpeg.org/ffmpeg.html#Main-options
148
- return advanced[:f] if advanced[:f]
149
+ return advanced_input[:f] if advanced_input[:f]
149
150
 
150
- return advanced[:fmt] if advanced[:fmt]
151
+ return advanced_input[:fmt] if advanced_input[:fmt]
151
152
 
152
- os_specific_capture_device
153
+ default_capture_device
153
154
  end
154
155
 
155
156
  #
156
157
  # Returns input capture device for current OS.
157
158
  #
158
- def os_specific_capture_device
159
+ def default_capture_device
159
160
  return 'gdigrab' if OS.windows?
160
161
 
161
162
  return 'x11grab' if OS.linux?
@@ -0,0 +1,39 @@
1
+ module ScreenRecorder
2
+ # All screenshot related code
3
+ module Screenshot
4
+ #
5
+ # Takes a screenshot in the current context (input) - desktop or current window
6
+ #
7
+ def screenshot(filename, resolution = nil)
8
+ ScreenRecorder.logger.debug "Screenshot filename: #{filename}, resolution: #{resolution}"
9
+ cmd = screenshot_cmd(filename: filename, resolution: resolution)
10
+ process = execute_command(cmd)
11
+ exit_code = wait_for_process_exit(process) # 0 (success) or 1 (fail)
12
+ if exit_code&.zero?
13
+ ScreenRecorder.logger.info "Screenshot: #{filename}"
14
+ return filename
15
+ end
16
+ ScreenRecorder.logger.error 'Failed to take a screenshot.'
17
+ nil
18
+ end
19
+
20
+ #
21
+ # Parameters to capture a single frame
22
+ #
23
+ def screenshot_cmd(filename:, resolution: nil)
24
+ resolution = resolution ? resolution_arg(resolution) : nil
25
+ # -f overwrites existing file
26
+ "#{ffmpeg_bin} -f #{options.capture_device} -i #{options.input} -framerate 1 -frames:v 1 #{resolution}#{filename}"
27
+ end
28
+
29
+ private
30
+
31
+ #
32
+ # Returns OS specific video resolution arg for ffmpeg
33
+ #
34
+ def resolution_arg(size)
35
+ # macOS likes -s, windows and linux like -video_size
36
+ OS.mac? ? "-s #{size} " : "-video_size #{size} "
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module ScreenRecorder
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.6.0'.freeze
3
3
  end
@@ -2,6 +2,8 @@
2
2
  module ScreenRecorder
3
3
  # @since 1.0.0-beta11
4
4
  class Window < Common
5
+ include Screenshot
6
+
5
7
  #
6
8
  # Window recording mode.
7
9
  #
@@ -21,7 +23,7 @@ module ScreenRecorder
21
23
  # ScreenRecorder::Window.fetch_title('chrome')
22
24
  # #=> ["New Tab - Google Chrome"]
23
25
  def fetch_title(process_name)
24
- ScreenRecorder.logger.debug "Retrieving window title for: #{process_name}"
26
+ ScreenRecorder.logger.debug "Retrieving window title from '#{process_name}'"
25
27
  window_title_for process_name
26
28
  end
27
29
 
@@ -43,6 +45,8 @@ module ScreenRecorder
43
45
  raise Errors::ApplicationNotFound, "No open windows found for: #{process_name}.exe" if titles.empty?
44
46
 
45
47
  warn_on_mismatch(titles, process_name)
48
+ ScreenRecorder.logger.debug "Retrieved titles: #{titles}"
49
+
46
50
  titles
47
51
  end
48
52
 
@@ -9,15 +9,15 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Lakshya Kapoor']
10
10
  spec.email = ['kapoorlakshya@gmail.com']
11
11
  spec.homepage = 'http://github.com/kapoorlakshya/screen-recorder'
12
- spec.summary = 'Video record your computer screen using FFmpeg.'
13
- spec.description = 'Video record your computer screen - desktop or specific window - using FFmpeg ' \
14
- 'on Windows, Linux, and macOS. Primarily geared towards recording automated UI ' \
15
- '(Selenium) test executions for debugging and documentation.'
12
+ spec.summary = 'Video record and take screenshots your computer screen using FFmpeg.'
13
+ spec.description = 'A Ruby gem to video record and take screenshots of your desktop or ' \
14
+ ' specific application window. Works on Windows, Linux, and macOS.'
16
15
  spec.license = 'MIT'
17
- # noinspection RubyStringKeysInHashInspection,RubyStringKeysInHashInspection,RubyStringKeysInHashInspection
16
+ # noinspection RubyStringKeysInHashInspection
18
17
  spec.metadata = {
19
18
  'changelog_uri' => 'https://github.com/kapoorlakshya/screen-recorder/blob/master/CHANGELOG.md',
20
- 'source_code_uri' => 'https://github.com/kapoorlakshya/screen-recorder/',
19
+ 'source_code_uri' => "https://github.com/kapoorlakshya/screen-recorder/tree/v#{ScreenRecorder::VERSION}",
20
+ 'documentation_uri' => "https://www.rubydoc.info/gems/screen-recorder/#{ScreenRecorder::VERSION}",
21
21
  'bug_tracker_uri' => 'https://github.com/kapoorlakshya/screen-recorder/issues',
22
22
  'wiki_uri' => 'https://github.com/kapoorlakshya/screen-recorder/wiki'
23
23
  }
@@ -28,17 +28,17 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.require_paths = ['lib']
30
30
 
31
- spec.add_development_dependency 'ffi' # For selenium_webdriver on Windows
32
- spec.add_development_dependency 'rake', '~> 12.0'
31
+ spec.add_development_dependency 'ffi' # For selenium-webdriver on Windows
32
+ spec.add_development_dependency 'rake', '>= 12.0'
33
33
  spec.add_development_dependency 'rspec', '~> 3.0'
34
- spec.add_development_dependency 'rubocop', '~> 0.73'
35
- spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
36
- spec.add_development_dependency 'rubocop-rspec', '~> 1.32'
34
+ spec.add_development_dependency 'rubocop', '~> 0.75'
35
+ spec.add_development_dependency 'rubocop-performance', '~> 1.0'
36
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.0'
37
37
  spec.add_development_dependency 'simplecov', '~> 0.16'
38
38
  spec.add_development_dependency 'watir', '~> 6.0'
39
39
  spec.add_development_dependency 'webdrivers', '~> 4.0'
40
40
 
41
- spec.add_runtime_dependency 'childprocess', '~> 1.0'
42
- spec.add_runtime_dependency 'os', '~> 1.0.0'
41
+ spec.add_runtime_dependency 'childprocess', '>= 1.0', '< 5.0' # Roughly match Selenium
42
+ spec.add_runtime_dependency 'os', '~> 1.0'
43
43
  spec.add_runtime_dependency 'streamio-ffmpeg', '~> 3.0'
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screen-recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lakshya Kapoor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-26 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
@@ -58,42 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.73'
61
+ version: '0.75'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.73'
68
+ version: '0.75'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-performance
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.1.0
75
+ version: '1.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.1.0
82
+ version: '1.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.32'
89
+ version: '1.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.32'
96
+ version: '1.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -140,30 +140,36 @@ dependencies:
140
140
  name: childprocess
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '1.0'
146
+ - - "<"
147
+ - !ruby/object:Gem::Version
148
+ version: '5.0'
146
149
  type: :runtime
147
150
  prerelease: false
148
151
  version_requirements: !ruby/object:Gem::Requirement
149
152
  requirements:
150
- - - "~>"
153
+ - - ">="
151
154
  - !ruby/object:Gem::Version
152
155
  version: '1.0'
156
+ - - "<"
157
+ - !ruby/object:Gem::Version
158
+ version: '5.0'
153
159
  - !ruby/object:Gem::Dependency
154
160
  name: os
155
161
  requirement: !ruby/object:Gem::Requirement
156
162
  requirements:
157
163
  - - "~>"
158
164
  - !ruby/object:Gem::Version
159
- version: 1.0.0
165
+ version: '1.0'
160
166
  type: :runtime
161
167
  prerelease: false
162
168
  version_requirements: !ruby/object:Gem::Requirement
163
169
  requirements:
164
170
  - - "~>"
165
171
  - !ruby/object:Gem::Version
166
- version: 1.0.0
172
+ version: '1.0'
167
173
  - !ruby/object:Gem::Dependency
168
174
  name: streamio-ffmpeg
169
175
  requirement: !ruby/object:Gem::Requirement
@@ -178,9 +184,8 @@ dependencies:
178
184
  - - "~>"
179
185
  - !ruby/object:Gem::Version
180
186
  version: '3.0'
181
- description: Video record your computer screen - desktop or specific window - using
182
- FFmpeg on Windows, Linux, and macOS. Primarily geared towards recording automated
183
- UI (Selenium) test executions for debugging and documentation.
187
+ description: A Ruby gem to video record and take screenshots of your desktop or specific
188
+ application window. Works on Windows, Linux, and macOS.
184
189
  email:
185
190
  - kapoorlakshya@gmail.com
186
191
  executables: []
@@ -188,16 +193,15 @@ extensions: []
188
193
  extra_rdoc_files: []
189
194
  files:
190
195
  - ".github/ISSUE_TEMPLATE.md"
196
+ - ".github/workflows/tests.yml"
191
197
  - ".gitignore"
192
198
  - ".rspec"
193
199
  - ".rubocop.yml"
194
- - ".travis.yml"
195
200
  - CHANGELOG.md
196
201
  - Gemfile
197
202
  - LICENSE.txt
198
203
  - README.md
199
204
  - Rakefile
200
- - appveyor.yml
201
205
  - bin/console
202
206
  - bin/setup
203
207
  - lib/screen-recorder.rb
@@ -205,21 +209,19 @@ files:
205
209
  - lib/screen-recorder/desktop.rb
206
210
  - lib/screen-recorder/errors.rb
207
211
  - lib/screen-recorder/options.rb
212
+ - lib/screen-recorder/screenshot.rb
208
213
  - lib/screen-recorder/titles.rb
209
214
  - lib/screen-recorder/type_checker.rb
210
215
  - lib/screen-recorder/version.rb
211
216
  - lib/screen-recorder/window.rb
212
217
  - screen-recorder.gemspec
213
- - support/install_jruby.ps1
214
- - support/start_test_reporter.sh
215
- - support/start_xvfb.sh
216
- - support/stop_test_reporter.sh
217
218
  homepage: http://github.com/kapoorlakshya/screen-recorder
218
219
  licenses:
219
220
  - MIT
220
221
  metadata:
221
222
  changelog_uri: https://github.com/kapoorlakshya/screen-recorder/blob/master/CHANGELOG.md
222
- source_code_uri: https://github.com/kapoorlakshya/screen-recorder/
223
+ source_code_uri: https://github.com/kapoorlakshya/screen-recorder/tree/v1.6.0
224
+ documentation_uri: https://www.rubydoc.info/gems/screen-recorder/1.6.0
223
225
  bug_tracker_uri: https://github.com/kapoorlakshya/screen-recorder/issues
224
226
  wiki_uri: https://github.com/kapoorlakshya/screen-recorder/wiki
225
227
  post_install_message:
@@ -237,8 +239,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
239
  - !ruby/object:Gem::Version
238
240
  version: '0'
239
241
  requirements: []
240
- rubygems_version: 3.0.3
242
+ rubygems_version: 3.1.4
241
243
  signing_key:
242
244
  specification_version: 4
243
- summary: Video record your computer screen using FFmpeg.
245
+ summary: Video record and take screenshots your computer screen using FFmpeg.
244
246
  test_files: []
data/.travis.yml DELETED
@@ -1,42 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- branches:
4
- only:
5
- - /.*/
6
- env:
7
- global:
8
- - DISPLAY=":0"
9
- matrix:
10
- include:
11
- - rvm: 2.4.6
12
- dist: xenial
13
- env: RAKE_TASK=spec
14
- - rvm: 2.4.6
15
- dist: xenial
16
- env: RAKE_TASK=rubocop
17
- - rvm: 2.6.3
18
- dist: xenial
19
- env: RAKE_TASK=spec
20
- - rvm: jruby-9.2.7.0
21
- dist: xenial
22
- jdk: openjdk8
23
- env: RAKE_TASK=spec JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"
24
- - rvm: 2.6.3
25
- os: osx
26
- osx_image: xcode11
27
- env: RAKE_TASK=spec
28
- addons:
29
- firefox: latest
30
- chrome: stable
31
- apt:
32
- packages:
33
- - ffmpeg
34
- homebrew:
35
- packages:
36
- - ffmpeg
37
- before_script:
38
- - bash support/start_xvfb.sh
39
- - bash support/start_test_reporter.sh
40
- script: bundle exec rake $RAKE_TASK
41
- after_script:
42
- - bash support/stop_test_reporter.sh
data/appveyor.yml DELETED
@@ -1,39 +0,0 @@
1
- build: off
2
- cache:
3
- - vendor/bundle
4
- environment:
5
- matrix:
6
- - RUBY_VERSION: Ruby24
7
- RUBY_BIN: ruby
8
- RAKE_TASK: spec
9
- SCRIPT_CONTEXT: bundle exec
10
- - RUBY_VERSION: Ruby24
11
- RUBY_BIN: ruby
12
- RAKE_TASK: rubocop
13
- SCRIPT_CONTEXT: bundle exec
14
- - RUBY_VERSION: Ruby26
15
- RUBY_BIN: ruby
16
- RAKE_TASK: spec
17
- SCRIPT_CONTEXT: bundle exec
18
- - RUBY_VERSION: jruby-9.2.7.0
19
- RUBY_BIN: jruby
20
- RAKE_TASK: spec
21
- SCRIPT_CONTEXT: jruby -G -S
22
- install:
23
- - ps: |
24
- if ($env:RUBY_BIN -eq 'jruby')
25
- {
26
- support\install_jruby.ps1
27
- }
28
- - choco install ffmpeg
29
- - set PATH=C:\%RUBY_VERSION%\bin;%PATH%
30
- - '%RUBY_BIN% -S gem update --system'
31
- - '%RUBY_BIN% -S gem install bundler'
32
- - '%RUBY_BIN% -S bundle install'
33
- before_test:
34
- - ffmpeg -version
35
- - '%RUBY_BIN% -v'
36
- - '%RUBY_BIN% -S gem -v'
37
- - '%RUBY_BIN% -S bundle -v'
38
- test_script:
39
- - '%SCRIPT_CONTEXT% rake %RAKE_TASK%'