Class: FFMpeg

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

Instance Method Summary collapse

Methods inherited from Player

#duration

Constructor Details

#initialize(hash = {}) ⇒ FFMpeg

Returns a new instance of FFMpeg.



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

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

Instance Method Details

#commandObject



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

def command
	'ffmpeg'
end

#optionsObject



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

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

#playObject

Raises:

  • ($?)


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

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

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



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

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

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

#to_sObject



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

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