Class: Xvfb::VideoRecorder
- Inherits:
-
Object
- Object
- Xvfb::VideoRecorder
- Defined in:
- lib/xvfb/video/video_recorder.rb
Instance Attribute Summary collapse
-
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
-
#pid_file_path ⇒ Object
Returns the value of attribute pid_file_path.
-
#provider_binary_path ⇒ Object
Returns the value of attribute provider_binary_path.
-
#tmp_file_path ⇒ Object
Returns the value of attribute tmp_file_path.
Instance Method Summary collapse
- #capture_running? ⇒ Boolean
-
#initialize(display, dimensions, options = {}) ⇒ VideoRecorder
constructor
Construct a new Video Recorder instance.
- #start_capture ⇒ Object
- #stop_and_discard ⇒ Object
- #stop_and_save(path) ⇒ Object
Constructor Details
#initialize(display, dimensions, options = {}) ⇒ VideoRecorder
Construct a new Video Recorder instance. Typically done from inside Xvfb, but can be also created manually, and even used separately from Xvfb’ Xvfb features.
-
display - display number to capture
-
dimensions - dimensions of the captured video
-
options - available options:
-
provider - either :ffmpeg or :libav; default is :ffmpeg - switch if your system is provisioned with FFMpeg
-
provider_binary_path - override path to ffmpeg / libav binary
-
pid_file_path - override path to PID file, default is placed in /tmp
-
tmp_file_path - override path to temp file, default is placed in /tmp
-
log_file_path - set log file path, default is /dev/null
-
codec - change ffmpeg codec, default is qtrle
-
frame_rate - change frame rate, default is 30
-
devices - array of device options - see www.ffmpeg.org/ffmpeg-devices.html
-
extra - array of extra options to append to the FFMpeg command line
-
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xvfb/video/video_recorder.rb', line 21 def initialize(display, dimensions, = {}) @display = display @dimensions = dimensions[/.+(?=x)/] @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, "libx264" @frame_rate = .fetch :frame_rate, 12 @provider = .fetch :provider, :ffmpeg # or :libav # If no provider_binary_path was specified, then # make a guess based upon the provider. @provider_binary_path = .fetch(:provider_binary_path, guess_the_provider_binary_path) @extra = Array(.fetch :extra, []) @devices = Array(.fetch :devices, []) CliUtil.ensure_application_exists! provider_binary_path, "#{provider_binary_path} not found on your system. Install it or change video recorder provider" end |
Instance Attribute Details
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
5 6 7 |
# File 'lib/xvfb/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/xvfb/video/video_recorder.rb', line 5 def pid_file_path @pid_file_path end |
#provider_binary_path ⇒ Object
Returns the value of attribute provider_binary_path.
5 6 7 |
# File 'lib/xvfb/video/video_recorder.rb', line 5 def provider_binary_path @provider_binary_path end |
#tmp_file_path ⇒ Object
Returns the value of attribute tmp_file_path.
5 6 7 |
# File 'lib/xvfb/video/video_recorder.rb', line 5 def tmp_file_path @tmp_file_path end |
Instance Method Details
#capture_running? ⇒ Boolean
42 43 44 |
# File 'lib/xvfb/video/video_recorder.rb', line 42 def capture_running? CliUtil.read_pid @pid_file_path end |
#start_capture ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/xvfb/video/video_recorder.rb', line 46 def start_capture CliUtil.fork_process command_line_for_capture, @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
67 68 69 70 71 72 73 74 |
# File 'lib/xvfb/video/video_recorder.rb', line 67 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
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/xvfb/video/video_recorder.rb', line 55 def stop_and_save(path) CliUtil.kill_process @pid_file_path, wait: true if File.exists? @tmp_file_path begin FileUtils.mkdir_p File.dirname(path) FileUtils.mv @tmp_file_path, path rescue nil end end end |