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 +4 -4
- data/.github/ISSUE_TEMPLATE.md +2 -0
- data/.github/workflows/tests.yml +97 -0
- data/.rspec +1 -1
- data/.rubocop.yml +83 -32
- data/{CHANGES.md → CHANGELOG.md} +37 -1
- data/Gemfile +3 -3
- data/README.md +281 -219
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/lib/screen-recorder.rb +34 -6
- data/lib/screen-recorder/common.rb +113 -56
- data/lib/screen-recorder/desktop.rb +5 -5
- data/lib/screen-recorder/errors.rb +10 -2
- data/lib/screen-recorder/options.rb +77 -59
- data/lib/screen-recorder/titles.rb +8 -41
- data/lib/screen-recorder/type_checker.rb +2 -0
- data/lib/screen-recorder/version.rb +1 -1
- data/lib/screen-recorder/window.rb +45 -9
- data/screen-recorder.gemspec +16 -12
- metadata +57 -23
- data/.travis.yml +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c04070110a0bb4d14c22683e2e226f68a2245ec8d0ae5ebf098e8a028fc22050
|
4
|
+
data.tar.gz: eac8f6a6036d62a7634fd61b77a0a864ea589aa3b4d2d5e1693f6a813692d4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cd22bbff801124ed2e3c42d94aa50cf8f568b473dcdff045e150bf25e543d0ff81d7d8a99da78ef2e6d8fffb5e57bc8d00a291dec4b72c7abe8f37453bf5e2e
|
7
|
+
data.tar.gz: ca1af2f484ca9e360dcf94096f7066013e9fe645471c36173d417c589c1cbe12d533bc1269ae44f27fe17a61252a2e1ede833ce9dfc45bcf9daaaeb038866f18
|
data/.github/ISSUE_TEMPLATE.md
CHANGED
@@ -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
data/.rubocop.yml
CHANGED
@@ -1,58 +1,109 @@
|
|
1
|
-
require:
|
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.
|
9
|
+
TargetRubyVersion: 2.5
|
10
|
+
NewCops: enable
|
11
|
+
|
7
12
|
Gemspec/RequiredRubyVersion:
|
8
13
|
Enabled: false
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
20
|
+
|
21
|
+
Layout/ArrayAlignment:
|
31
22
|
Enabled: true
|
32
|
-
|
23
|
+
|
24
|
+
Layout/HashAlignment:
|
33
25
|
Enabled: true
|
34
26
|
EnforcedHashRocketStyle: key
|
35
27
|
EnforcedColonStyle: table
|
36
|
-
|
28
|
+
|
29
|
+
Layout/ParameterAlignment:
|
37
30
|
Enabled: true
|
38
31
|
EnforcedStyle: with_first_parameter
|
39
|
-
|
40
|
-
|
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
|
-
|
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
|
-
|
92
|
+
|
93
|
+
Style/FrozenStringLiteralComment:
|
52
94
|
Enabled: false
|
53
|
-
|
95
|
+
|
96
|
+
Style/ExponentialNotation:
|
54
97
|
Enabled: false
|
55
|
-
|
98
|
+
|
99
|
+
Style/HashEachMethods:
|
100
|
+
Enabled: true
|
101
|
+
|
102
|
+
Style/HashTransformKeys:
|
103
|
+
Enabled: false
|
104
|
+
|
105
|
+
Style/HashTransformValues:
|
56
106
|
Enabled: false
|
57
|
-
|
107
|
+
|
108
|
+
Style/SlicingWithRange:
|
58
109
|
Enabled: false
|
data/{CHANGES.md → CHANGELOG.md}
RENAMED
@@ -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)).
|
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
|
-
[](https://badge.fury.io/rb/screen-recorder)
|
4
|
-
[](https://www.rubydoc.info/
|
5
|
-
[](https://badge.fury.io/rb/screen-recorder)
|
4
|
+
[](https://www.rubydoc.info/gems/screen-recorder/)
|
5
|
+
[](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
|
+
[](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
|
+

|
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).
|