ffmpeg-screenrecorder 1.0.0.beta5 → 1.0.0.beta6

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: 2a72ed1c811611468b93f3a1677b651881834c3e94aa52582564a1bdee2aba60
4
- data.tar.gz: cfce5bdfe5c575a77b7bf12d994a58c406ede56b529704ce5c9ac9d157e72d72
3
+ metadata.gz: 2c62a747ed63c6178eace85bc00839f1d1812f13eb2c024df6341fa7c9550ac5
4
+ data.tar.gz: 340337ba29b6f447a77c9c721645aa5cc572c38082db63433e0e73fc70872919
5
5
  SHA512:
6
- metadata.gz: 6e74b55cb1c1e6cd0e72a4a7d59e8f171b81627102f17a17ee3020c74e672ef0c1df4b0bd1a3c4d577406209d5802d8b6fb009b07266917f9709f84ff02c3f5c
7
- data.tar.gz: 06125f14582ae639177ceed36295de452479b6abb76f70654cb71168ca46dac4210c7b43a9c05e5133cd55b8b27aa40baf46920012b4b3f4994563d2c47eb68a
6
+ metadata.gz: f09d8655ffa42956ec4bfabafa38d742986f9f73781885d190e2b8598156dfe2f7dd70748059a0a6685f6f0b27b87e03af7bc4716c2f614616abb7b86209f261
7
+ data.tar.gz: 4a8db4f7460bc9dbcae758730bb79a5355ea3ecafe4ffb6f8902d090e8dc4e0e9f4f617a0b3fb2e2571e7ec9ce1d5ffc1ce23da1e1804ea1baa931f887b31abb
data/.gitignore CHANGED
@@ -15,6 +15,7 @@ Gemfile.lock # Part of best practice
15
15
  /spec/reports/
16
16
  /tmp/
17
17
  /webdrivers_bin
18
+ *.log
18
19
 
19
20
  Gemfile.lock
20
21
 
data/README.md CHANGED
@@ -54,9 +54,7 @@ Or install it yourself as:
54
54
  ```
55
55
  opts = { output: 'ffmpeg-screenrecorder-desktop.mp4',
56
56
  input: 'desktop',
57
- framerate: 30.0,
58
- device: 'gdigrab',
59
- log: 'ffmpeg-screenrecorder-log.txt' }
57
+ framerate: 30.0 }
60
58
  @recorder = FFMPEG::ScreenRecorder.new(opts)
61
59
 
62
60
  # Start recording
@@ -67,7 +65,10 @@ opts = { output: 'ffmpeg-screenrecorder-desktop.mp4',
67
65
  # Stop recording
68
66
  @recorder.stop
69
67
 
70
- # Recording file will be available: ffmpeg-screenrecorder-desktop.mp4
68
+ # Recorded file
69
+ @recorder.video #=> 'ffmpeg-screenrecorder-desktop.mp4'
70
+
71
+ # ffmpeg log will be stored in 'ffmpeg.log'
71
72
  ```
72
73
 
73
74
  ##### Record Specific Application/Window - gdigrab (Windows) Only
@@ -82,7 +83,6 @@ FFMPEG::RecordingRegions.fetch('firefox') # Name of exe
82
83
  opts = { output: 'ffmpeg-screenrecorder-firefox.mp4',
83
84
  input: 'Mozilla Firefox',
84
85
  framerate: 30.0,
85
- device: 'gdigrab',
86
86
  log: 'ffmpeg-screenrecorder-firefox.txt' }
87
87
  @recorder = FFMPEG::ScreenRecorder.new(opts)
88
88
 
@@ -1,6 +1,8 @@
1
1
  module FFMPEG
2
2
  # @since 1.0.0-beta2
3
3
  class RecorderOptions
4
+ DEFAULT_LOG_FILE = 'ffmpeg.log'
5
+
4
6
  def initialize(options)
5
7
  @options = verify_options options
6
8
  end
@@ -44,7 +46,7 @@ module FFMPEG
44
46
  # Returns given log filename
45
47
  #
46
48
  def log
47
- @options[:log]
49
+ @options[:log] || DEFAULT_LOG_FILE
48
50
  end
49
51
 
50
52
  #
@@ -115,15 +117,12 @@ module FFMPEG
115
117
  end
116
118
 
117
119
  #
118
- # Returns portion of the command which determines
119
- # if the ffmpeg output will be logged to a file
120
- # or completely ignored based on if the user
121
- # provides a log filepath in the options.
120
+ # Returns logging command with user given log file
121
+ # from options or the default file.
122
122
  #
123
123
  def ffmpeg_log_to(file)
124
- return " 2> #{file}" if file
125
-
126
- '> nul 2>&1' # No log file given
124
+ file ||= DEFAULT_LOG_FILE
125
+ " 2> #{file}"
127
126
  end
128
127
 
129
128
  #
@@ -1,55 +1,64 @@
1
- module FFMPEG
2
- # @since 1.0.0-beta4
3
- module RecordingRegions
4
- #
5
- # Returns a list of available window titles for the given application (process) name.
6
- #
7
- def self.fetch(application)
8
- FFMPEG.logger.debug "Retrieving available windows for: #{application}"
9
- WindowGrabber.new.available_windows_for application
10
- end
11
-
12
- # @since 1.0.0-beta4
13
- class WindowGrabber
14
- #
15
- # Returns a cleaned up list of available window titles
16
- # for the given application (process) name.
17
- # Note: Only supports Windows OS as of version beta2.
18
- #
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)
29
- raw_list = `tasklist /v /fi "imagename eq #{application}.exe" /fo list | findstr Window`
30
- .split("\n")
31
- .reject { |title| title == 'Window Title: N/A' }
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?
34
-
35
- final_list
36
- end
37
-
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
54
- end # module Windows
1
+ module FFMPEG
2
+ # @since 1.0.0-beta4
3
+ module RecordingRegions
4
+ #
5
+ # Returns a list of available window titles for the given application (process) name.
6
+ #
7
+ def self.fetch(application)
8
+ FFMPEG.logger.debug "Retrieving available windows for: #{application}"
9
+ WindowGrabber.new.available_windows_for application
10
+ end
11
+
12
+ # @since 1.0.0-beta4
13
+ class WindowGrabber
14
+ #
15
+ # Returns a cleaned up list of available window titles
16
+ # for the given application (process) name.
17
+ # Note: Only supports Windows OS as of version beta2.
18
+ #
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
+ #
29
+ # Returns list of windows for Microsoft Windows
30
+ #
31
+ def windows_os(application)
32
+ raw_list = `tasklist /v /fi "imagename eq #{application}.exe" /fo list | findstr Window`
33
+ .split("\n")
34
+ .reject { |title| title == 'Window Title: N/A' }
35
+ final_list = raw_list.map { |i| i.gsub('Window Title: ', '') } # Match ffmpeg expected format
36
+ raise RecorderErrors::ApplicationNotFound, "No open windows found for: #{application}.exe" if final_list.empty?
37
+
38
+ final_list
39
+ end
40
+
41
+ #
42
+ # Returns list of windows for Linux
43
+ #
44
+ def linux_os(application)
45
+ raise DependencyNotFound, 'wmctrl is not installed. Run: sudo apt-get install wmctrl.' unless wmctrl_installed?
46
+
47
+ final_list = `wmctrl -l | awk '{$3=""; $2=""; $1=""; print $0}'` # Returns all open windows
48
+ .split("\n")
49
+ .map(&:strip)
50
+ .select { |t| t.match?(/#{application}/i) } # Narrow down to given application
51
+ raise RecorderErrors::ApplicationNotFound, "No open windows found for: #{application}" if final_list.empty?
52
+
53
+ final_list
54
+ end
55
+
56
+ #
57
+ # Returns true if wmctrl is installed
58
+ #
59
+ def wmctrl_installed?
60
+ !`which wmctrl`.empty? # "" when not found
61
+ end
62
+ end
63
+ end # module Windows
55
64
  end # module FFMPEG
@@ -13,7 +13,7 @@ module FFMPEG
13
13
  @options = RecorderOptions.new(options)
14
14
  @video = nil
15
15
  @process = nil
16
- initialize_logger(@options.log_level || Logger::ERROR)
16
+ initialize_logger(@options.log_level)
17
17
  end
18
18
 
19
19
  #
@@ -49,7 +49,6 @@ module FFMPEG
49
49
  raise RecorderErrors::DependencyNotFound, 'ffmpeg binary not found.' unless ffmpeg_exists?
50
50
 
51
51
  FFMPEG.logger.debug "Command: #{command}"
52
- puts "Command: #{command}" # @todo Remove this after debugging
53
52
  process = IO.popen(command, 'r+')
54
53
  sleep(1.5) # Takes ~1.5s on average to initialize
55
54
  process
@@ -63,6 +62,11 @@ module FFMPEG
63
62
  elapsed = wait_for_io_eof(5)
64
63
  @process.close_write # Close IO
65
64
  elapsed
65
+
66
+ rescue Errno::EPIPE
67
+ # Gets last line from log file
68
+ err_line = get_lines_from_log(count = 2, :last)
69
+ raise FFMPEG::Error, err_line
66
70
  end
67
71
 
68
72
  #
@@ -70,7 +74,7 @@ module FFMPEG
70
74
  #
71
75
  def initialize_logger(level)
72
76
  FFMPEG.logger.progname = 'FFmpeg'
73
- FFMPEG.logger.level = level
77
+ FFMPEG.logger.level = level || Logger::ERROR
74
78
  FFMPEG.logger.formatter = proc do |severity, time, progname, msg|
75
79
  "#{time.strftime('%F %T')} #{progname} - #{severity} - #{msg}\n"
76
80
  end
@@ -107,7 +111,20 @@ module FFMPEG
107
111
 
108
112
  return !`where ffmpeg`.empty? if OS.windows?
109
113
 
110
- true # @todo Check on windows
114
+ true
115
+ end
116
+
117
+ #
118
+ # Returns lines from the log file
119
+ #
120
+ def get_lines_from_log(count = 2, position = :last)
121
+ f = File.open(options.log)
122
+ lines = f.readlines
123
+ lines = lines.last(count) if position == :last
124
+ lines = lines.first(count) if position == :first
125
+ f.close
126
+
127
+ lines.join(' ')
111
128
  end
112
129
  end # class Recorder
113
130
  end # module FFMPEG
@@ -1,5 +1,5 @@
1
1
  module FFMPEG
2
2
  class ScreenRecorder
3
- VERSION = '1.0.0.beta5'.freeze
3
+ VERSION = '1.0.0.beta6'.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.beta5
4
+ version: 1.0.0.beta6
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-26 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler