Sha256: 160ba9b11dd2865eab091c238b737cf97fa046d60da62f72b3540178baa52aee

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module VncTools
  class Recorder

    attr_reader :display, :output

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

    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 = "/dev/null"
      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

    def stop
      @process && @process.stop
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vnctools-0.0.2 lib/vnctools/recorder.rb