ffmpeg-screenrecorder 1.0.0.beta4 → 1.0.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 857bc0e6533ccdb8dcc9c0c82cae13028e205173f14997177f2638f5a93ae65e
4
- data.tar.gz: 774c93d3e295012d242b1df752460880d93b01a41abc86812e37fa389788293a
3
+ metadata.gz: 2a72ed1c811611468b93f3a1677b651881834c3e94aa52582564a1bdee2aba60
4
+ data.tar.gz: cfce5bdfe5c575a77b7bf12d994a58c406ede56b529704ce5c9ac9d157e72d72
5
5
  SHA512:
6
- metadata.gz: 780bf876cff8c52ef37db709ba971ca4b80a2eab4422cbc6e8ee211bd363e103563217b7d8ab246f614c7d445d62895756ee078dab465bc2fbf644503f460d54
7
- data.tar.gz: 185f4b69f1932a88d1332f72db132e4ad8d46ff7457ae5a034119ebfe750efd13e8723d4395e691f86e5ea557928fdb1891d5c016939cb8c297c838d6f346730
6
+ metadata.gz: 6e74b55cb1c1e6cd0e72a4a7d59e8f171b81627102f17a17ee3020c74e672ef0c1df4b0bd1a3c4d577406209d5802d8b6fb009b07266917f9709f84ff02c3f5c
7
+ data.tar.gz: 06125f14582ae639177ceed36295de452479b6abb76f70654cb71168ca46dac4210c7b43a9c05e5133cd55b8b27aa40baf46920012b4b3f4994563d2c47eb68a
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,12 +1,12 @@
1
- # FFMPEG::Screenrecorder
1
+ # FFMPEG::ScreenRecorder
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ffmpeg-screenrecorder.svg)](https://badge.fury.io/rb/ffmpeg-screenrecorder)
4
4
 
5
5
  Ruby gem to record your computer screen - desktop or specific application/window - using [FFmpeg](https://www.ffmpeg.org/).
6
6
 
7
- ## Windows Only
7
+ ## Compatibility
8
8
 
9
- Only supports Windows as of version `1.0.0-beta3`. Linux and macOS support will be added before the final release of `v1.0.0`.
9
+ Supports Windows and Linux as of version `1.0.0-beta5`. macOS support will be added before the final release of `v1.0.0`.
10
10
 
11
11
  ## Installation
12
12
 
@@ -57,7 +57,7 @@ opts = { output: 'ffmpeg-screenrecorder-desktop.mp4',
57
57
  framerate: 30.0,
58
58
  device: 'gdigrab',
59
59
  log: 'ffmpeg-screenrecorder-log.txt' }
60
- @recorder = FFMPEG::Screenrecorder.new(opts)
60
+ @recorder = FFMPEG::ScreenRecorder.new(opts)
61
61
 
62
62
  # Start recording
63
63
  @recorder.start
@@ -70,13 +70,13 @@ opts = { output: 'ffmpeg-screenrecorder-desktop.mp4',
70
70
  # Recording file will be available: ffmpeg-screenrecorder-desktop.mp4
71
71
  ```
72
72
 
73
- ##### Record Specific Application/Window
73
+ ##### Record Specific Application/Window - gdigrab (Windows) Only
74
74
  ```
75
75
  require 'watir'
76
76
 
77
77
  browser = Watir::Browser.new :firefox
78
78
 
79
- FFMPEG::Screenrecorder.window_titles('firefox') # Name of exe
79
+ FFMPEG::RecordingRegions.fetch('firefox') # Name of exe
80
80
  #=> "Mozilla Firefox"
81
81
 
82
82
  opts = { output: 'ffmpeg-screenrecorder-firefox.mp4',
@@ -84,7 +84,7 @@ opts = { output: 'ffmpeg-screenrecorder-firefox.mp4',
84
84
  framerate: 30.0,
85
85
  device: 'gdigrab',
86
86
  log: 'ffmpeg-screenrecorder-firefox.txt' }
87
- @recorder = FFMPEG::Screenrecorder.new(opts)
87
+ @recorder = FFMPEG::ScreenRecorder.new(opts)
88
88
 
89
89
  # Start recording
90
90
  @recorder.start
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "ffmpeg/screenrecorder"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ffmpeg/screenrecorder'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -1,32 +1,32 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'ffmpeg/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'ffmpeg-screenrecorder'
7
- spec.version = FFMPEG::Screenrecorder::VERSION
8
- spec.authors = ['Lakshya Kapoor']
9
- spec.email = ['kapoorlakshya@gmail.com']
10
-
11
- spec.summary = 'Record your computer screen using ffmpeg via Ruby.'
12
- spec.description = 'Ruby gem to record your computer screen - desktop or specific application/window' \
13
- ' - using FFmpeg (https://www.ffmpeg.org).'
14
- spec.homepage = 'http://github.com/kapoorlakshya/ffmpeg-screenrecorder'
15
- spec.license = 'MIT'
16
-
17
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- end
20
-
21
- spec.require_paths = ['lib']
22
-
23
- spec.add_development_dependency 'bundler', '~> 1.16'
24
- spec.add_development_dependency 'pry-byebug', '~> 3.6'
25
- spec.add_development_dependency 'rake', '~> 10.0'
26
- spec.add_development_dependency 'rspec', '~> 3.0'
27
- spec.add_development_dependency 'watir', '~> 6.0'
28
- spec.add_development_dependency 'webdrivers', '~> 3.0'
29
-
30
- spec.add_runtime_dependency 'os', '~> 0.9.0'
31
- spec.add_runtime_dependency 'streamio-ffmpeg', '~> 1.0'
32
- end
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ffmpeg/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ffmpeg-screenrecorder'
7
+ spec.version = FFMPEG::ScreenRecorder::VERSION
8
+ spec.authors = ['Lakshya Kapoor']
9
+ spec.email = ['kapoorlakshya@gmail.com']
10
+
11
+ spec.summary = 'Record your computer screen using ffmpeg via Ruby.'
12
+ spec.description = 'Ruby gem to record your computer screen - desktop or specific application/window' \
13
+ ' - using FFmpeg (https://www.ffmpeg.org).'
14
+ spec.homepage = 'http://github.com/kapoorlakshya/ffmpeg-screenrecorder'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'pry-byebug', '~> 3.6'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'watir', '~> 6.0'
28
+ spec.add_development_dependency 'webdrivers', '~> 3.0'
29
+
30
+ spec.add_runtime_dependency 'os', '~> 0.9.0'
31
+ spec.add_runtime_dependency 'streamio-ffmpeg', '~> 1.0'
32
+ end
@@ -0,0 +1,10 @@
1
+ module FFMPEG
2
+ # @since 1.0.0-beta5
3
+ module RecorderErrors
4
+ # @since 1.0.0-beta3
5
+ class ApplicationNotFound < StandardError; end
6
+
7
+ # @since 1.0.0-beta5
8
+ class DependencyNotFound < StandardError; end
9
+ end
10
+ end
@@ -1,7 +1,6 @@
1
1
  module FFMPEG
2
2
  # @since 1.0.0-beta2
3
3
  class RecorderOptions
4
-
5
4
  def initialize(options)
6
5
  @options = verify_options options
7
6
  end
@@ -10,7 +9,7 @@ module FFMPEG
10
9
  # Returns given recording format
11
10
  #
12
11
  def format
13
- @options[:format]
12
+ determine_format
14
13
  end
15
14
 
16
15
  #
@@ -67,10 +66,10 @@ module FFMPEG
67
66
  # ready for the ffmpeg process to use
68
67
  #
69
68
  def parsed
70
- vals = "-f #{@options[:format]} "
69
+ vals = "-f #{determine_format} "
71
70
  vals << "-r #{@options[:framerate]} "
72
71
  vals << advanced_options if @options[:advanced]
73
- vals << "-i #{determine_infile @options[:infile]} "
72
+ vals << "-i #{determine_infile} "
74
73
  vals << @options[:output]
75
74
  vals << ffmpeg_log_to(@options[:log]) # If provided
76
75
  end
@@ -93,11 +92,12 @@ module FFMPEG
93
92
  # Returns Array of required options sa Symbols
94
93
  #
95
94
  def required_options
96
- # -f format
97
95
  # -r framerate
98
96
  # -i input
99
97
  # output
100
- %i[format framerate infile output]
98
+ return %i[framerate infile output] unless OS.linux?
99
+
100
+ %i[framerate output] # Linux
101
101
  end
102
102
 
103
103
  #
@@ -108,9 +108,9 @@ module FFMPEG
108
108
  raise(ArgumentError, ':advanced cannot be empty.') if options[:advanced].empty?
109
109
 
110
110
  arr = []
111
- options[:advanced].each { |k, v|
111
+ options[:advanced].each do |k, v|
112
112
  arr.push "-#{k} #{v}"
113
- }
113
+ end
114
114
  arr.join(' ') + ' '
115
115
  end
116
116
 
@@ -122,7 +122,8 @@ module FFMPEG
122
122
  #
123
123
  def ffmpeg_log_to(file)
124
124
  return " 2> #{file}" if file
125
- ' > nul 2>&1' # No log file given
125
+
126
+ '> nul 2>&1' # No log file given
126
127
  end
127
128
 
128
129
  #
@@ -130,9 +131,31 @@ module FFMPEG
130
131
  # Adds title= qualifier to infile parameter
131
132
  # unless the user is recording the desktop.
132
133
  #
133
- def determine_infile(opt)
134
- return opt if opt == 'desktop'
135
- %Q("title=#{opt}")
134
+ def determine_infile
135
+ # x11grab doesn't support window capture
136
+ return ':0.0' if OS.linux?
137
+
138
+ return @options[:infile] if @options[:infile] == 'desktop'
139
+
140
+ # Windows only
141
+ %("title=#{@options[:infile]}")
142
+ end
143
+
144
+ #
145
+ # Returns format based on the current OS.
146
+ #
147
+ def determine_format
148
+ return @options[:format] if @options[:format]
149
+
150
+ if OS.windows?
151
+ 'gdigrab'
152
+ elsif OS.linux?
153
+ 'x11grab'
154
+ elsif OS.mac?
155
+ 'avfoundation'
156
+ else
157
+ raise NotImplementedError, 'Your OS is not supported.'
158
+ end
136
159
  end
137
160
  end
138
- end
161
+ end
@@ -1,11 +1,10 @@
1
1
  module FFMPEG
2
2
  # @since 1.0.0-beta4
3
3
  module RecordingRegions
4
-
5
4
  #
6
5
  # Returns a list of available window titles for the given application (process) name.
7
6
  #
8
- def window_titles(application)
7
+ def self.fetch(application)
9
8
  FFMPEG.logger.debug "Retrieving available windows for: #{application}"
10
9
  WindowGrabber.new.available_windows_for application
11
10
  end
@@ -18,17 +17,39 @@ module FFMPEG
18
17
  # Note: Only supports Windows OS as of version beta2.
19
18
  #
20
19
  def available_windows_for(application)
20
+ return windows_os(application) if OS.windows?
21
+ return linux_os(application) if OS.linux?
22
+
23
+ raise NotImplementedError, 'Your OS is not supported.'
24
+ end
25
+
26
+ private
27
+
28
+ def windows_os(application)
21
29
  raw_list = `tasklist /v /fi "imagename eq #{application}.exe" /fo list | findstr Window`
22
- .split("\n")
23
- .reject { |title| title == 'Window Title: N/A' }
30
+ .split("\n")
31
+ .reject { |title| title == 'Window Title: N/A' }
24
32
  final_list = raw_list.map { |i| i.gsub('Window Title: ', '') } # Make it user friendly
33
+ raise RecorderErrors::ApplicationNotFound, "No open windows found for: #{application}.exe" if final_list.empty?
25
34
 
26
- raise ApplicationNotFound, "No open windows found for: #{application}.exe" if final_list.empty?
27
35
  final_list
28
36
  end
29
- end
30
37
 
31
- # @since 1.0.0-beta3
32
- class ApplicationNotFound < StandardError; end
38
+ def linux_os(application)
39
+ raise DependencyNotFound, 'wmctrl is not installed. Run: sudo apt-get install wmctrl.' unless wmctrl_installed?
40
+
41
+ final_list = `wmctrl -l | awk '{$3=""; $2=""; $1=""; print $0}'` # Returns all open windows
42
+ .split("\n")
43
+ .map(&:strip)
44
+ .select { |t| t.match?(/#{application}/i) } # Narrow down to given application
45
+ raise RecorderErrors::ApplicationNotFound, "No open windows found for: #{application}" if final_list.empty?
46
+
47
+ final_list
48
+ end
49
+
50
+ def wmctrl_installed?
51
+ !`which wmctrl`.empty? # "" when not found
52
+ end
53
+ end
33
54
  end # module Windows
34
55
  end # module FFMPEG
@@ -1,13 +1,12 @@
1
1
  require 'streamio-ffmpeg'
2
2
  require 'os'
3
+ require_relative 'recorder_errors'
3
4
  require_relative 'recorder_options'
4
5
  require_relative 'recording_regions'
5
6
 
6
7
  module FFMPEG
7
- # @since 1.0.0-beta1
8
- class Screenrecorder
9
- extend RecordingRegions
10
-
8
+ # @since 1.0.0-beta
9
+ class ScreenRecorder
11
10
  attr_reader :options, :video
12
11
 
13
12
  def initialize(options = {})
@@ -47,7 +46,10 @@ module FFMPEG
47
46
  # the given options.
48
47
  #
49
48
  def start_ffmpeg
49
+ raise RecorderErrors::DependencyNotFound, 'ffmpeg binary not found.' unless ffmpeg_exists?
50
+
50
51
  FFMPEG.logger.debug "Command: #{command}"
52
+ puts "Command: #{command}" # @todo Remove this after debugging
51
53
  process = IO.popen(command, 'r+')
52
54
  sleep(1.5) # Takes ~1.5s on average to initialize
53
55
  process
@@ -96,5 +98,16 @@ module FFMPEG
96
98
  FFMPEG.logger.debug "IO#eof? #{@process.eof?}"
97
99
  Time.now - start
98
100
  end
101
+
102
+ #
103
+ # Returns true if ffmpeg binary is found.
104
+ #
105
+ def ffmpeg_exists?
106
+ return !`which ffmpeg`.empty? if OS.linux? # "" if not found
107
+
108
+ return !`where ffmpeg`.empty? if OS.windows?
109
+
110
+ true # @todo Check on windows
111
+ end
99
112
  end # class Recorder
100
113
  end # module FFMPEG
@@ -1,5 +1,5 @@
1
1
  module FFMPEG
2
- class Screenrecorder
3
- VERSION = '1.0.0.beta4'.freeze
2
+ class ScreenRecorder
3
+ VERSION = '1.0.0.beta5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffmpeg-screenrecorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta4
4
+ version: 1.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lakshya Kapoor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,6 +142,7 @@ files:
142
142
  - bin/setup
143
143
  - ffmpeg-screenrecorder.gemspec
144
144
  - lib/ffmpeg.rb
145
+ - lib/ffmpeg/recorder_errors.rb
145
146
  - lib/ffmpeg/recorder_options.rb
146
147
  - lib/ffmpeg/recording_regions.rb
147
148
  - lib/ffmpeg/screenrecorder.rb