Class: VncTools::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/vnctools/recorder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display, output, opts = {}) ⇒ Recorder

Returns a new instance of Recorder.



6
7
8
9
10
# File 'lib/vnctools/recorder.rb', line 6

def initialize(display, output, opts = {})
  @display = display
  @output  = output
  @options = opts
end

Instance Attribute Details

#displayObject (readonly)

Returns the value of attribute display.



4
5
6
# File 'lib/vnctools/recorder.rb', line 4

def display
  @display
end

#outputObject (readonly)

Returns the value of attribute output.



4
5
6
# File 'lib/vnctools/recorder.rb', line 4

def output
  @output
end

Instance Method Details

#startObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vnctools/recorder.rb', line 12

def start
  @process = ChildProcess.build(
    "ffmpeg",
    "-an",                                      # no audio,
    "-f", "x11grab",                            # force format
    "-y",                                       # overwrite output files
    "-r", @options[:frame_rate] || "5",         # frame rate
    "-s", @options[:frame_size] || "1024x768",  # frame size
    "-i", "#{display}.0+0,0",                   # display :1
    "-vcodec", @options[:codec] || "mpeg4",     # video codec
    "-sameq", output                            # output
  )

  if $DEBUG
    @process.io.inherit!
  else
    @process.io.stdout = @process.io.stderr = File.open("/dev/null", "w")
  end

  @process.start

  # TODO: this may be too quick to actually catch the failure
  if @process.crashed?
    raise Error, "ffmpeg failed, run with $DEBUG = true for full output"
  end
end

#stopObject



39
40
41
# File 'lib/vnctools/recorder.rb', line 39

def stop
  @process && @process.stop
end