Class: Headless::VideoRecorder
- Inherits:
-
Object
- Object
- Headless::VideoRecorder
- Defined in:
- lib/headless/video/video_recorder.rb
Instance Attribute Summary collapse
-
#bin_file_path ⇒ Object
Returns the value of attribute bin_file_path.
-
#bin_version ⇒ Object
Returns the value of attribute bin_version.
-
#capture_with ⇒ Object
Returns the value of attribute capture_with.
-
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
-
#pid_file_path ⇒ Object
Returns the value of attribute pid_file_path.
-
#tmp_file_path ⇒ Object
Returns the value of attribute tmp_file_path.
Instance Method Summary collapse
- #capture_running? ⇒ Boolean
- #guess_ffmpeg_version! ⇒ Object
-
#initialize(display, dimensions, options = {}) ⇒ VideoRecorder
constructor
A new instance of VideoRecorder.
- #pause ⇒ Object
- #resume ⇒ Object
- #start_capture ⇒ Object
- #stop_and_discard ⇒ Object
- #stop_and_save(path) ⇒ Object
Constructor Details
#initialize(display, dimensions, options = {}) ⇒ VideoRecorder
Returns a new instance of VideoRecorder.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/headless/video/video_recorder.rb', line 7 def initialize(display, dimensions, = {}) CliUtil.ensure_application_exists!('ffmpeg', 'Ffmpeg not found on your system. Install it with sudo apt-get install ffmpeg') @display = display @dimensions = dimensions[/.+(?=x)/] @bin_file_path = .fetch(:bin_file_path, CliUtil.path_to('ffmpeg')) # divine version - tested on: # ffmpeg version 2.3.1 # ffmpeg version 0.10.9-7:0.10.9-1~quantal1 # ffmpeg 0.8.10-6:0.8.10-0ubuntu0.12.10.1 @bin_version = .fetch(:bin_version, guess_ffmpeg_version!) @pid_file_path = .fetch(:pid_file_path, "/tmp/.headless_ffmpeg_#{@display}.pid") @tmp_file_path = .fetch(:tmp_file_path, "/tmp/.headless_ffmpeg_#{@display}.mov") @log_file_path = .fetch(:log_file_path, '/dev/null') @codec = .fetch(:codec, 'qtrle') @frame_rate = .fetch(:frame_rate, 30).to_i @nomouse = .fetch(:nomouse, false) @audio = .fetch(:audio, false) end |
Instance Attribute Details
#bin_file_path ⇒ Object
Returns the value of attribute bin_file_path.
5 6 7 |
# File 'lib/headless/video/video_recorder.rb', line 5 def bin_file_path @bin_file_path end |
#bin_version ⇒ Object
Returns the value of attribute bin_version.
5 6 7 |
# File 'lib/headless/video/video_recorder.rb', line 5 def bin_version @bin_version end |
#capture_with ⇒ Object
Returns the value of attribute capture_with.
5 6 7 |
# File 'lib/headless/video/video_recorder.rb', line 5 def capture_with @capture_with end |
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
5 6 7 |
# File 'lib/headless/video/video_recorder.rb', line 5 def log_file_path @log_file_path end |
#pid_file_path ⇒ Object
Returns the value of attribute pid_file_path.
5 6 7 |
# File 'lib/headless/video/video_recorder.rb', line 5 def pid_file_path @pid_file_path end |
#tmp_file_path ⇒ Object
Returns the value of attribute tmp_file_path.
5 6 7 |
# File 'lib/headless/video/video_recorder.rb', line 5 def tmp_file_path @tmp_file_path end |
Instance Method Details
#capture_running? ⇒ Boolean
32 33 34 |
# File 'lib/headless/video/video_recorder.rb', line 32 def capture_running? !!CliUtil.read_pid(@pid_file_path) end |
#guess_ffmpeg_version! ⇒ Object
28 29 30 |
# File 'lib/headless/video/video_recorder.rb', line 28 def guess_ffmpeg_version! (Gem::Version.new(`#{@bin_file_path} -version`[/(?:ffmpeg )(?:version )?((?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+))/, 1])) unless @bin_file_path.empty? rescue Gem::Version.new('0') end |
#pause ⇒ Object
61 62 63 |
# File 'lib/headless/video/video_recorder.rb', line 61 def pause CliUtil.signal_process(@pid_file_path, 'STOP') end |
#resume ⇒ Object
65 66 67 |
# File 'lib/headless/video/video_recorder.rb', line 65 def resume CliUtil.signal_process(@pid_file_path, 'CONT') end |
#start_capture ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/headless/video/video_recorder.rb', line 52 def start_capture CliUtil.fork_process("#{capture_with} #{@tmp_file_path}", @pid_file_path, @log_file_path) at_exit do exit_status = $!.status if $!.is_a?(SystemExit) stop_and_discard exit exit_status if exit_status end end |
#stop_and_discard ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/headless/video/video_recorder.rb', line 81 def stop_and_discard CliUtil.kill_process(@pid_file_path, :wait => true) begin FileUtils.rm(@tmp_file_path) rescue Errno::ENOENT # that's ok if the file doesn't exist end end |
#stop_and_save(path) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/headless/video/video_recorder.rb', line 69 def stop_and_save(path) CliUtil.kill_process(@pid_file_path, :wait => true, :sig => 'INT') if File.exists? @tmp_file_path begin FileUtils.mv(@tmp_file_path, path) true rescue Errno::EINVAL false end end end |