Class: FFMpeg

Inherits:
Player show all
Defined in:
lib/player/ffmpeg.rb

Instance Method Summary collapse

Methods inherited from Player

#duration

Constructor Details

#initializeFFMpeg

Returns a new instance of FFMpeg.



7
8
9
10
11
# File 'lib/player/ffmpeg.rb', line 7

def initialize
  self['loglevel'] = 'warning'
  self['n']        = '' # do not overwrite
  @mplayer = Mplayer.new('-')
end

Instance Method Details

#commandObject



14
15
16
# File 'lib/player/ffmpeg.rb', line 14

def command
  'ffmpeg'
end

#optionsObject



18
19
20
# File 'lib/player/ffmpeg.rb', line 18

def options
  map{ |k,v| "-#{k} #{v}"}*' '
end

#playObject

Raises:

  • ($?)


29
30
31
32
33
34
35
36
# File 'lib/player/ffmpeg.rb', line 29

def play
  self['f'] = 'mpegts'
  @output = 'pipe:1'
  cmd = "#{to_s} | #{@mplayer}"
  $stderr.puts 'play: '+cmd
  `#{cmd}`
  raise $? unless $?.success?
end

#rec(file, sec, quiet = true) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/player/ffmpeg.rb', line 39

def rec(file, sec, quiet = true)
  self['t'] = sec if sec
  if quiet
    @output = file
    cmd = to_s
  else
    self['f'] = 'mpegts'
    @output = 'pipe:1'
    cmd = "#{to_s} | tee #{file} | #{@mplayer}"
  end

  puts "rec: #{cmd}"
  stdout, stderr, status = Open3.capture3(cmd)
end

#to_sObject



23
24
25
26
# File 'lib/player/ffmpeg.rb', line 23

def to_s
  # novideoオプション -vn は、この位置でないと機能しない
  %Q(#{command} #{options} -vn #{@output})
end