screen-recorder 1.1.0 → 1.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f46c2cd0518ebc956772cc5586b95974e0f51cede0d456ff0934bb2aaa9cef92
4
- data.tar.gz: a8f5113b23a9a3521a282e9385f7c8502e01991594ee065eb6cf5a55fd6403f3
3
+ metadata.gz: c04070110a0bb4d14c22683e2e226f68a2245ec8d0ae5ebf098e8a028fc22050
4
+ data.tar.gz: eac8f6a6036d62a7634fd61b77a0a864ea589aa3b4d2d5e1693f6a813692d4cd
5
5
  SHA512:
6
- metadata.gz: '059777ec5a7b09f8c1bf97727c57f07cf4172918a445aa1015544b92cb4bf8454ea6d5c79daaf8aab0667aad132ec6fcb466ce52cc365f05cb9f598fd8266445'
7
- data.tar.gz: 0ecbe285d1a4d6f9fd6f579c9233614d6e8e1f0130ab31d9f40ba2f348e2dac8ba3d1cc82f9fc0f0340f2f1215fec9e89f89996688dce76ab26bc7c7efc42034
6
+ metadata.gz: 1cd22bbff801124ed2e3c42d94aa50cf8f568b473dcdff045e150bf25e543d0ff81d7d8a99da78ef2e6d8fffb5e57bc8d00a291dec4b72c7abe8f37453bf5e2e
7
+ data.tar.gz: ca1af2f484ca9e360dcf94096f7066013e9fe645471c36173d417c589c1cbe12d533bc1269ae44f27fe17a61252a2e1ede833ce9dfc45bcf9daaaeb038866f18
@@ -5,6 +5,8 @@ Short summary of the bug or feature request.
5
5
  Please provide the following information for bug reports:
6
6
 
7
7
  * Operating system - Microsoft Windows, Linux, or macOS.
8
+ * Ruby version
9
+ * screen-recorder version
8
10
  * Recorder parameters - input, output, etc.
9
11
  * Recorder log (`ffmpeg.log`) file as a gist or on pastebin.com.
10
12
  * Set `ScreenRecorder.logger.level = Logger::DEBUG`, run the recorder, and share the
@@ -0,0 +1,97 @@
1
+
2
+ name: Tests
3
+
4
+ on: [push, pull_request]
5
+
6
+ jobs:
7
+ lint:
8
+ runs-on: ubuntu-18.04
9
+ steps:
10
+ - name: Cancel any previous run(s) on new commit push
11
+ uses: styfle/cancel-workflow-action@0.8.0
12
+ with:
13
+ access_token: ${{ secrets.GITHUB_TOKEN }}
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.5
19
+ bundler-cache: true
20
+ - name: Run rubocop
21
+ run: bundle exec rake rubocop
22
+
23
+ test-ubuntu:
24
+ runs-on: ubuntu-latest
25
+ strategy:
26
+ matrix:
27
+ ruby-version: [2.7, jruby]
28
+ env:
29
+ DISPLAY: ":0"
30
+ steps:
31
+ - name: Cancel any previous run(s) on new commit push
32
+ uses: styfle/cancel-workflow-action@0.8.0
33
+ with:
34
+ access_token: ${{ secrets.GITHUB_TOKEN }}
35
+ - uses: actions/checkout@v2
36
+ - name: Set up ffmpeg
37
+ uses: FedericoCarboni/setup-ffmpeg@v1
38
+ with:
39
+ token: ${{ secrets.GITHUB_TOKEN }}
40
+ id: setup-ffmpeg
41
+ - name: Set up Ruby
42
+ uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: ${{ matrix.ruby-version }}
45
+ bundler-cache: true
46
+ - name: Start xvfb
47
+ run: Xvfb -ac $DISPLAY -screen 0 1024x768x24 > /dev/null 2>&1 &
48
+ - name: Run tests
49
+ run: bundle exec rake spec
50
+
51
+ test-windows:
52
+ runs-on: windows-latest
53
+ strategy:
54
+ matrix:
55
+ ruby-version: [2.5, jruby]
56
+ steps:
57
+ - name: Cancel any previous run(s) on new commit push
58
+ uses: styfle/cancel-workflow-action@0.8.0
59
+ with:
60
+ access_token: ${{ secrets.GITHUB_TOKEN }}
61
+ - uses: actions/checkout@v2
62
+ - name: Set up ffmpeg
63
+ uses: FedericoCarboni/setup-ffmpeg@v1
64
+ with:
65
+ token: ${{ secrets.GITHUB_TOKEN }}
66
+ id: setup-ffmpeg
67
+ - name: Set up Ruby
68
+ uses: ruby/setup-ruby@v1
69
+ with:
70
+ ruby-version: ${{ matrix.ruby-version }}
71
+ bundler-cache: true
72
+ - name: Run tests
73
+ run: bundle exec rake spec
74
+
75
+ test-macos:
76
+ runs-on: macos-latest
77
+ strategy:
78
+ matrix:
79
+ ruby-version: [2.5, 2.7]
80
+ steps:
81
+ - name: Cancel any previous run(s) on new commit push
82
+ uses: styfle/cancel-workflow-action@0.8.0
83
+ with:
84
+ access_token: ${{ secrets.GITHUB_TOKEN }}
85
+ - uses: actions/checkout@v2
86
+ - name: Set up ffmpeg
87
+ uses: FedericoCarboni/setup-ffmpeg@v1
88
+ with:
89
+ token: ${{ secrets.GITHUB_TOKEN }}
90
+ id: setup-ffmpeg
91
+ - name: Set up Ruby
92
+ uses: ruby/setup-ruby@v1
93
+ with:
94
+ ruby-version: ${{ matrix.ruby-version }}
95
+ bundler-cache: true
96
+ - name: Run tests
97
+ run: bundle exec rake spec
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,58 +1,109 @@
1
- require: rubocop-rspec
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
2
5
  AllCops:
3
6
  DisplayCopNames: true
4
7
  DisplayStyleGuide: true
5
8
  ExtraDetails: false
6
- TargetRubyVersion: 2.2
9
+ TargetRubyVersion: 2.5
10
+ NewCops: enable
11
+
7
12
  Gemspec/RequiredRubyVersion:
8
13
  Enabled: false
9
- Metrics/LineLength:
10
- Enabled: false
11
- Metrics/MethodLength:
12
- Enabled: false
13
- Metrics/BlockLength:
14
- Enabled: false
15
- Metrics/ClassLength:
16
- Enabled: false
17
- Metrics/AbcSize:
18
- Enabled: false
19
- Metrics/CyclomaticComplexity:
20
- Enabled: false
21
- Style/Documentation:
22
- Enabled: false
23
- RSpec/ExampleLength:
24
- Enabled: false
25
- RSpec/MultipleExpectations:
26
- Enabled: false
14
+
15
+ Layout/EndOfLine:
16
+ EnforcedStyle: lf
17
+
27
18
  Layout/MultilineMethodCallIndentation:
28
- Enabled: false
29
19
  EnforcedStyle: indented_relative_to_receiver
30
- Layout/AlignArray:
20
+
21
+ Layout/ArrayAlignment:
31
22
  Enabled: true
32
- Layout/AlignHash:
23
+
24
+ Layout/HashAlignment:
33
25
  Enabled: true
34
26
  EnforcedHashRocketStyle: key
35
27
  EnforcedColonStyle: table
36
- Layout/AlignParameters:
28
+
29
+ Layout/ParameterAlignment:
37
30
  Enabled: true
38
31
  EnforcedStyle: with_first_parameter
39
- Layout/EndOfLine:
40
- Enabled: false
41
- Layout/IndentHash:
32
+
33
+ Layout/FirstHashElementIndentation:
42
34
  Enabled: true
35
+
36
+ Layout/TrailingEmptyLines:
37
+ Enabled: false
38
+
39
+ Layout/LineLength:
40
+ Max: 120
41
+
42
+ Layout/EmptyLinesAroundAttributeAccessor:
43
+ Enabled: true
44
+
45
+ Layout/SpaceAroundOperators:
46
+ Enabled: true
47
+
48
+ Layout/SpaceAroundMethodCallOperator:
49
+ Enabled: true
50
+
51
+ Lint/DeprecatedOpenSSLConstant:
52
+ Enabled: true
53
+
54
+ Lint/RaiseException:
55
+ Enabled: true
56
+
57
+ Lint/StructNewOverride:
58
+ Enabled: true
59
+
60
+ Metrics/MethodLength:
61
+ Max: 20
62
+
63
+ Metrics/ClassLength:
64
+ Max: 120
65
+
66
+ Metrics/AbcSize:
67
+ Max: 18
68
+
69
+ Metrics/BlockLength:
70
+ Exclude:
71
+ - 'screen-recorder.gemspec'
72
+ - 'spec/**/*'
73
+
43
74
  Naming/FileName:
44
- Enabled: false
75
+ Exclude:
76
+ - 'lib/screen-recorder.rb'
77
+
45
78
  RSpec/FilePath:
46
79
  Enabled: false
80
+
81
+ RSpec/ExampleLength:
82
+ Enabled: false
83
+
84
+ RSpec/MultipleExpectations:
85
+ Enabled: false
86
+
47
87
  Style/BlockDelimiters:
48
88
  EnforcedStyle: braces_for_chaining
89
+
49
90
  Style/CommentedKeyword:
50
91
  Enabled: false
51
- Style/DoubleNegation:
92
+
93
+ Style/FrozenStringLiteralComment:
52
94
  Enabled: false
53
- Style/MethodCallWithoutArgsParentheses:
95
+
96
+ Style/ExponentialNotation:
54
97
  Enabled: false
55
- Style/FrozenStringLiteralComment:
98
+
99
+ Style/HashEachMethods:
100
+ Enabled: true
101
+
102
+ Style/HashTransformKeys:
103
+ Enabled: false
104
+
105
+ Style/HashTransformValues:
56
106
  Enabled: false
57
- TrailingBlankLines:
107
+
108
+ Style/SlicingWithRange:
58
109
  Enabled: false
@@ -1,5 +1,41 @@
1
+ # Changelog
2
+
3
+ This project adheres to [Semantic Versioning](https://semver.org/).
4
+
5
+ ### 1.5.0 (2021-03-23)
6
+ * Relax "os" gem version to minor level ([#97](https://github.com/kapoorlakshya/screen-recorder/pull/97)). Thanks, [hlascelles](https://github.com/hlascelles)!
7
+
8
+ ### 1.4.0 (2020-01-27)
9
+ * Users can now select a ffmpeg [capture device](https://ffmpeg.org/ffmpeg-devices.html) from advanced -> input.
10
+ * Fix a bug where some advanced parameters were not parsed correctly.
11
+ * Add support for audio stream capture ([#15](https://github.com/kapoorlakshya/screen-recorder/issues/15))
12
+ * Fix [#84](https://github.com/kapoorlakshya/screen-recorder/issues/84) where the user given ffmpeg binary path was never used.
13
+ * Relax childprocess gem version requirement to roughly match requirements in `selenium-webdriver` gem ([#85](https://github.com/kapoorlakshya/screen-recorder/issues/85))
14
+ * Add support for capturing screenshots in both desktop and window modes ([#44](https://github.com/kapoorlakshya/screen-recorder/issues/44)).
15
+
16
+ ### 1.3.1 (2019-10-20)
17
+ * Reattempt `ffprobe` execution up to times if the first try raises `Errno::EAGAIN`.
18
+ Hopefully fixes [#79](https://github.com/kapoorlakshya/screen-recorder/issues/79).
19
+
20
+ ### 1.3.0 (2019-07-26)
21
+ * Support JRuby 9.2+ ([#58](https://github.com/kapoorlakshya/screen-recorder/issues/58))
22
+ * Add `ScreenRecorder::` as an alias for `ScreenRecorder::Window.fetch_title`.
23
+ The `Titles` class will be removed in version 2.0.
24
+
25
+ ### 1.2.0 (2019-05-12)
26
+ * Separate input/output specific `ffmpeg` arguments through the `advanced`
27
+ Hash. See example [here](https://github.com/kapoorlakshya/screen-recorder#advanced-options).
28
+ * Check for errors after starting the `ffmpeg` process to make sure the
29
+ recording does not stop silently because of an error. Prints the error
30
+ from the log if the process exists unexpectedly.
31
+ * Now using [`childprocess`](https://github.com/enkessler/childprocess) gem
32
+ to manage the `ffmpeg` process. This requires the `ffi` gem to be
33
+ installed on Windows. See [childprocess#132](https://github.com/enkessler/childprocess/issues/150)
34
+ for more information.
35
+
1
36
  ### 1.1.0 (2019-04-14)
2
- * <b>Add support for macOS</b> ([#55](https://github.com/kapoorlakshya/screen-recorder/issues/55)). Please [raise an Issue](https://github.com/kapoorlakshya/screen-recorder/issues/new) if you run into problems.
37
+ * <b>Add support for macOS</b> ([#55](https://github.com/kapoorlakshya/screen-recorder/issues/55)).
38
+ Thanks to [Denys Bazarnyi](https://github.com/bazarnyi) for testing this and providing feedback.
3
39
  * Force kill `ffmpeg` if it takes more than 10s to quit ([#60](https://github.com/kapoorlakshya/screen-recorder/issues/60)).
4
40
  * Fix a bug where `ScreenRecorder.ffmpeg_binary=()` was not properly defined.
5
41
  * `ScreenRecorder::Titles#fetch` will now raise `NotImplementedError` when used in a
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -1,219 +1,281 @@
1
- # ScreenRecorder
2
-
3
- [![Gem Version](https://badge.fury.io/rb/screen-recorder.svg)](https://badge.fury.io/rb/screen-recorder)
4
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/github/kapoorlakshya/screen-recorder/master)
5
- [![Build Status](https://travis-ci.org/kapoorlakshya/screen-recorder.svg?branch=master)](https://travis-ci.org/kapoorlakshya/screen-recorder)
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/b6049dfee7375aed9bc8/maintainability)](https://codeclimate.com/github/kapoorlakshya/screen-recorder/maintainability)
7
-
8
- A Ruby gem to video record your computer screen - desktop or specific
9
- window - using [FFmpeg](https://www.ffmpeg.org/). Primarily
10
- geared towards recording automated UI test executions for debugging
11
- and documentation.
12
-
13
- Demo - [https://kapoorlakshya.github.io/introducing-screen-recorder-ruby-gem](https://kapoorlakshya.github.io/introducing-screen-recorder-ruby-gem).
14
-
15
- ## Compatibility
16
-
17
- Works on Windows, Linux, and macOS. Requires Ruby 2.0.0 or higher.
18
-
19
- ## Installation
20
-
21
- ##### 1. Setup FFmpeg
22
-
23
- Linux and macOS instructions are [here](https://www.ffmpeg.org/download.html).
24
-
25
- For Microsoft Windows, download the *libx264* enabled binary from [here](https://ffmpeg.zeranoe.com/builds/).
26
- Once downloaded, add location of the `ffmpeg/bin` folder to `PATH` environment variable
27
- ([instructions](https://windowsloop.com/install-ffmpeg-windows-10/)).
28
-
29
- Alternatively, you can provide the location using
30
- `ScreenRecorder.ffmpeg_binary = '/path/to/binary'` in your project.
31
-
32
- ##### 2. Install gem
33
-
34
- Next, add this line to your application's Gemfile:
35
-
36
- ```ruby
37
- gem 'screen-recorder'
38
- ```
39
-
40
- And then execute:
41
-
42
- ```bash
43
- $ bundle
44
- ```
45
-
46
- Or install it yourself as:
47
-
48
- ```bash
49
- $ gem install screen-recorder
50
- ```
51
-
52
- ##### 3. Require gem
53
-
54
- ```ruby
55
- require 'screen-recorder'
56
- ```
57
-
58
- ## Usage
59
-
60
- #### Record Desktop
61
-
62
- ```ruby
63
- @recorder = ScreenRecorder::Desktop.new(output: 'recording.mkv')
64
- @recorder.start
65
-
66
- # Run tests or whatever you want to record
67
-
68
- @recorder.stop
69
- ```
70
-
71
- Linux and macOS users can optionally provide a display or input device number as
72
- `input: ':99'`. Default is `:0` on Linux and `1` on macOS.
73
-
74
- Run command `echo $DISPLAY` on Linux and `ffmpeg -f avfoundation -list_devices true -i ""` on macOS to get a list of available
75
- inputs.
76
-
77
- #### Record Application Window (Microsoft Windows only)
78
-
79
- ```ruby
80
- require 'watir'
81
-
82
- browser = Watir::Browser.new :firefox
83
- @recorder = ScreenRecorder::Window.new(title: 'Mozilla Firefox', output: 'recording.mkv')
84
- @recorder.start
85
-
86
- # Run tests or whatever you want to record
87
-
88
- @recorder.stop
89
- browser.quit
90
- ```
91
-
92
- ##### Fetch Title
93
-
94
- A helper method is available to fetch the title of the active window
95
- for the given process name.
96
-
97
- ```ruby
98
- ScreenRecorder::Titles.fetch('firefox') # Name of exe
99
- #=> ["Mozilla Firefox"]
100
- ```
101
-
102
- ##### Limitations
103
-
104
- - Only available for Microsoft Windows (*gdigrab*). Linux (*x11grab*) and macOS
105
- (*avfoundation*) capture devices do not provide this feature. However, there
106
- is a workaround documented in the [wiki](https://github.com/kapoorlakshya/screen-recorder/wiki/Window-recording-in-Linux-and-Mac).
107
- - Always stop the recording before closing the application. Otherwise,
108
- ffmpeg will force exit as soon as the window disappears and may produce
109
- an invalid video file.
110
- - If you're launching multiple applications or testing an application
111
- at different window sizes, recording the `desktop` is a better option.
112
- - `#fetch` only returns the title from a currently active (visible) window
113
- for the given process.
114
- - `#fetch` may return `ArgumentError (invalid byte sequence in UTF-8)`
115
- for a window title with non `UTF-8` characters. See [wiki](https://github.com/kapoorlakshya/screen-recorder/wiki/Invalid-byte-sequence-in-UTF-8)
116
- for workaround.
117
-
118
- #### Output
119
-
120
- Once the recorder is stopped, you can view the video metadata or transcode
121
- it if desired. See [`streamio-ffmpeg`](https://github.com/streamio/streamio-ffmpeg) for more details.
122
-
123
- ```ruby
124
- @recorder.video
125
- => #<FFMPEG::Movie:0x0000000004327900
126
- @path="recording.mkv",
127
- @metadata={:streams=>[{:index=>0, :codec_name=>"h264", :codec_long_name=>"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
128
- :profile=>"High",
129
- :codec_type=>"video",
130
- ...
131
- @bitrate=264198,
132
- @video_codec="h264",
133
- @colorspace="yuv420p",
134
- @width=1920,
135
- @height=1080,
136
- @video_bitrate=0,
137
- ... >
138
- ```
139
-
140
- If your test passes or you do not want the recording for any reason,
141
- simply call `@recorder.discard` or `@recorder.delete` to delete
142
- the video file.
143
-
144
- #### Advanced Options
145
-
146
- You can provide additional parameters to FFmpeg using the `advanced`
147
- parameter. The keys in the Hash are prefixed with `-` and paired with the
148
- values in the final command.
149
-
150
- ```ruby
151
- advanced = { framerate: 30,
152
- log: 'recorder.log',
153
- loglevel: 'level+debug', # For FFmpeg
154
- video_size: '640x480',
155
- show_region: '1' }
156
- ScreenRecorder::Desktop.new(output: 'recording.mkv',
157
- advanced: advanced)
158
- ```
159
-
160
- This will be parsed as:
161
-
162
- ```bash
163
- ffmpeg -y -f gdigrab -framerate 30 -loglevel level+debug -video_size 640x480 -show_region 1 -i desktop recording.mkv 2> recorder.log
164
- ```
165
-
166
- This feature is yet to be fully tested, so please feel free
167
- to report any bugs or request a feature.
168
-
169
- #### Logging
170
-
171
- You can configure the logging level of the gem to troubleshoot problems:
172
-
173
- ```ruby
174
- ScreenRecorder.logger.level = :DEBUG
175
- ```
176
-
177
- Also refer to the `ffmpeg.log` file for details.
178
-
179
- #### Use with Cucumber
180
-
181
- A Cucumber + Watir based example is available
182
- [here](https://github.com/kapoorlakshya/cucumber-watir-test-recorder-example).
183
-
184
- ## Wiki
185
-
186
- Please see the [wiki](https://github.com/kapoorlakshya/screen-recorder/wiki) for solutions to commonly reported issues.
187
-
188
- ## Development
189
-
190
- After checking out the repo, run `bin/setup` to install dependencies.
191
- Then, run `bundle exec rake spec` to run the tests. You can also run
192
- `bin/console` for an interactive prompt that will allow you to experiment.
193
-
194
- To install this gem onto your local machine, run `bundle exec rake install`.
195
-
196
- ### Contributing
197
-
198
- Bug reports and pull requests are welcome.
199
-
200
- - Please update the specs for your code changes and run them locally with `bundle exec rake spec`.
201
- - Follow the Ruby style guide and format your code - <https://github.com/rubocop-hq/ruby-style-guide>
202
-
203
- ### License
204
-
205
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
206
-
207
- ## Credits
208
-
209
- [![Streamio](http://d253c4ja9jigvu.cloudfront.net/assets/small-logo.png)](http://streamio.com)
210
-
211
- This gem is based on the [streamio-ffmpeg](https://github.com/streamio/streamio-ffmpeg) gem.
212
- <br />
213
- <br />
214
-
215
- ![SauceLabs Logo](https://saucelabs.com/content/images/logo.png)
216
-
217
- Thanks to [SauceLabs](https://saucelabs.com) for providing me with a
218
- free account. If you manage an open source project, you can apply for
219
- a free account [here](https://saucelabs.com/open-source).
1
+ # ScreenRecorder
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/screen-recorder.svg)](https://badge.fury.io/rb/screen-recorder)
4
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/screen-recorder/)
5
+ [![Tests](https://github.com/kapoorlakshya/screen-recorder/actions/workflows/tests.yml/badge.svg)](https://github.com/kapoorlakshya/screen-recorder/actions/workflows/tests.yml)
6
+
7
+ A Ruby gem to video record or take screenshots of your computer screen - desktop or specific
8
+ window - using [FFmpeg](https://www.ffmpeg.org/). Primarily
9
+ geared towards recording automated UI (Selenium) test executions for
10
+ debugging and documentation.
11
+
12
+ #### Demo
13
+ [https://kapoorlakshya.github.io/introducing-screen-recorder-ruby-gem](https://kapoorlakshya.github.io/introducing-screen-recorder-ruby-gem)
14
+
15
+ ## Compatibility
16
+
17
+ Works on Windows, Linux, and macOS. Requires Ruby 2.0+ or JRuby 9.2+.
18
+
19
+ ## Installation
20
+
21
+ ##### 1. Setup FFmpeg
22
+
23
+ Linux and macOS instructions are [here](https://trac.ffmpeg.org/wiki/CompilationGuide).
24
+
25
+ > macOS: Follow [these steps](https://github.com/kapoorlakshya/screen-recorder/issues/88#issuecomment-629139032) to avoid
26
+ > issues related to Privacy settings.
27
+
28
+ For Microsoft Windows, download the binary from [here](https://www.videohelp.com/software/ffmpeg). Once downloaded,
29
+ add location of the `ffmpeg/bin` folder to the `PATH` environment variable ([instructions](https://windowsloop.com/install-ffmpeg-windows-10/)).
30
+
31
+ Alternatively, you can point to the binary file using
32
+ `ScreenRecorder.ffmpeg_binary = '/path/to/ffmpeg'` in your project.
33
+
34
+ ##### 2. Install gem
35
+
36
+ Next, add these lines to your application's Gemfile:
37
+
38
+ ```ruby
39
+ gem 'ffi' # Windows only
40
+ gem 'screen-recorder', '~> 1.0'
41
+ ```
42
+
43
+ The [`ffi`](https://github.com/ffi/ffi) gem is used by the
44
+ [`childprocess`](https://github.com/enkessler/childprocess) gem on
45
+ Windows, but it does not explicitly require it. More information
46
+ on this [here](https://github.com/enkessler/childprocess/issues/160).
47
+
48
+
49
+ And then execute:
50
+
51
+ ```bash
52
+ $ bundle
53
+ ```
54
+
55
+ Or install it yourself as:
56
+
57
+ ```bash
58
+ $ gem install ffi # Windows only
59
+ $ gem install screen-recorder
60
+ ```
61
+
62
+ ##### 3. Require gem
63
+
64
+ ```ruby
65
+ require 'screen-recorder'
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ #### Record Desktop
71
+
72
+ ```ruby
73
+ @recorder = ScreenRecorder::Desktop.new(output: 'recording.mkv')
74
+ @recorder.start
75
+
76
+ # Run tests or whatever you want to record
77
+
78
+ @recorder.stop
79
+ ```
80
+
81
+ Linux and macOS users can optionally provide a display or input device number.
82
+ Read more about it in the wiki [here](https://github.com/kapoorlakshya/screen-recorder/wiki/Display-or-Input-Device-Selection).
83
+
84
+ #### Record Application Window (Microsoft Windows only)
85
+
86
+ ```ruby
87
+ require 'watir'
88
+
89
+ browser = Watir::Browser.new :firefox
90
+ @recorder = ScreenRecorder::Window.new(title: 'Mozilla Firefox', output: 'recording.mkv')
91
+ @recorder.start
92
+
93
+ # Run tests or whatever you want to record
94
+
95
+ @recorder.stop
96
+ browser.quit
97
+ ```
98
+ This mode has a few limitations which are listed in the wiki
99
+ [here](https://github.com/kapoorlakshya/screen-recorder/wiki/Window-Capture-Limitations).
100
+
101
+ ##### Fetch Title
102
+
103
+ A helper method is available to fetch the title of the active window
104
+ for the given process name.
105
+
106
+ ```ruby
107
+ ScreenRecorder::('firefox') # Name of exe
108
+ #=> ["Mozilla Firefox"]
109
+
110
+ ScreenRecorder::('chrome')
111
+ #=> ["New Tab - Google Chrome"]
112
+ ```
113
+
114
+ #### Capture Audio
115
+
116
+ Provide the following `advanced` configurations to capture audio:
117
+
118
+ ```ruby
119
+ # Linux
120
+ advanced = { f: 'alsa', ac: 2, i: 'hw:0'} # Using ALSA
121
+ # Or using PulseAudio
122
+ advanced = { 'f': 'pulse', 'ac': 2, 'i': 'default' } # Records default sound output device
123
+
124
+ # macOS
125
+ advanced = { input: { i: '1:1' } } # -i video:audio input device ID
126
+
127
+ # Windows
128
+ advanced = { f: 'dshow', i: 'audio="Microphone (Realtek High Definition Audio)"' }
129
+ ```
130
+
131
+ You can retrieve a list of audio devices by running these commands:
132
+
133
+ ```
134
+ # Linux
135
+ $ arecord -L # See https://trac.ffmpeg.org/wiki/Capture/ALSA
136
+
137
+ # macOS
138
+ $ ffmpeg -f avfoundation -list_devices true -i ""
139
+
140
+ # Windows
141
+ > ffmpeg -list_devices true -f dshow -i dummy
142
+ ```
143
+
144
+ #### Screenshots
145
+
146
+ Screenshots can be captured at any point after initializing the recorder:
147
+
148
+ ```ruby
149
+ # Desktop
150
+ @recorder = ScreenRecorder::Desktop.new(output: 'recording.mkv')
151
+ @recorder.screenshot('before-recording.png')
152
+ @recorder.start
153
+ @recorder.screenshot('during-recording.png')
154
+ @recorder.stop
155
+ @recorder.screenshot('after-recording.png')
156
+
157
+ # Window (Microsoft Windows only)
158
+ browser = Watir::Browser.new :chrome, options: { args: ['--disable-gpu'] } # Hardware acceleration must be disabled
159
+ browser.goto('watir.com')
160
+ window_title = ScreenRecorder::('chrome').first
161
+ @recorder = ScreenRecorder::Window.new(title: window_title, output: 'recording.mkv')
162
+ @recorder.screenshot('before-recording.png')
163
+ @recorder.start
164
+ @recorder.screenshot('during-recording.png')
165
+ @recorder.stop
166
+ @recorder.screenshot('after-recording.png')
167
+ browser.quit
168
+ ```
169
+ #### Video Output
170
+
171
+ Once the recorder is stopped, you can view the video metadata or transcode
172
+ it if desired.
173
+
174
+ ```ruby
175
+ @recorder.video
176
+ => #<FFMPEG::Movie:0x0000000004327900
177
+ @path="recording.mkv",
178
+ @metadata={:streams=>[{:index=>0, :codec_name=>"h264", :codec_long_name=>"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
179
+ :profile=>"High",
180
+ :codec_type=>"video"}
181
+ @video_codec="h264",
182
+ @colorspace="yuv420p",
183
+ ... >
184
+
185
+ @recorder.video.transcode("recording.mp4") { |progress| puts progress } # 0.2 ... 0.5 ... 1.0
186
+ ```
187
+
188
+ See [`streamio-ffmpeg`](https://github.com/streamio/streamio-ffmpeg) gem for more details.
189
+
190
+ #### Discard Recording
191
+
192
+ If your test passes or you do not want the recording for any reason,
193
+ simply call `@recorder.discard` or `@recorder.delete` to delete
194
+ the video file.
195
+
196
+ #### Advanced Options
197
+
198
+ You can provide additional parameters to FFmpeg using the `advanced`
199
+ parameter. You can specify input/output specific parameters using `input: {}`
200
+ and `output: {}` within the `advanced` Hash.
201
+
202
+ ```ruby
203
+ advanced = {
204
+ input: {
205
+ framerate: 30,
206
+ pix_fmt: 'yuv420p',
207
+ video_size: '1280x720'
208
+ },
209
+ output: {
210
+ r: 15, # Framerate
211
+ pix_fmt: 'yuv420p'
212
+ },
213
+ log: 'recorder.log',
214
+ loglevel: 'level+debug', # For FFmpeg
215
+ }
216
+ ScreenRecorder::Desktop.new(output: 'recording.mkv', advanced: advanced)
217
+ ```
218
+
219
+ This will be parsed as:
220
+
221
+ ```bash
222
+ ffmpeg -y -f gdigrab -framerate 30 -pix_fmt yuv420p -video_size 1280x720 -i desktop -r 15 pix_fmt yuv420p -loglevel level+debug recording.mkv
223
+ ```
224
+
225
+ #### Logging & Debugging
226
+
227
+ You can configure the logging level of the gem to troubleshoot problems:
228
+
229
+ ```ruby
230
+ ScreenRecorder.logger.level = :DEBUG
231
+ ```
232
+
233
+ Also refer to the `ffmpeg.log` file for details.
234
+
235
+ #### Use with Cucumber
236
+
237
+ A Cucumber + Watir based example is available
238
+ [here](https://github.com/kapoorlakshya/cucumber-watir-test-recorder-example).
239
+
240
+ ## Wiki
241
+
242
+ Please see the [wiki](https://github.com/kapoorlakshya/screen-recorder/wiki) for solutions to commonly reported issues.
243
+
244
+ ## Development
245
+
246
+ After checking out the repo, run `bin/setup` to install dependencies.
247
+ Then, run `bundle exec rake` to run the tests and rubocop. You can also run
248
+ `bin/console` for an interactive prompt that will allow you to experiment.
249
+
250
+ To install this gem onto your local machine, run `bundle exec rake install`.
251
+
252
+ ### Contributing
253
+
254
+ Bug reports and pull requests are welcome.
255
+
256
+ - Please update the specs for your code changes and run them locally with `bundle exec rake spec`.
257
+ - Follow the Ruby style guide and format your code - <https://github.com/rubocop-hq/ruby-style-guide>
258
+
259
+ ### License
260
+
261
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
262
+
263
+ ## Credits
264
+
265
+ Thanks to [Denys Bazarnyi](https://github.com/bazarnyi) for testing
266
+ macOS compatibility in v1.1.0.
267
+ <br />
268
+ <br />
269
+
270
+ [![Streamio](http://d253c4ja9jigvu.cloudfront.net/assets/small-logo.png)](http://streamio.com)
271
+
272
+ This gem relies on the [streamio-ffmpeg](https://github.com/streamio/streamio-ffmpeg)
273
+ gem to extract metadata from the output file.
274
+ <br />
275
+ <br />
276
+
277
+ ![SauceLabs Logo](https://saucelabs.com/content/images/logo.png)
278
+
279
+ Thanks to [SauceLabs](https://saucelabs.com) for providing me with a
280
+ free account. If you manage an open source project, you can apply for
281
+ a free account [here](https://saucelabs.com/open-source).