Class: FFSplitter::FFMpeg

Inherits:
Object
  • Object
show all
Defined in:
lib/ffsplitter/ffmpeg.rb

Constant Summary collapse

CODEC_OPTIONS =
"-c copy -movflags faststart"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ FFMpeg

Returns a new instance of FFMpeg.



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

def initialize(options)
  @filename         = options[:filename]
  @output_path      = options[:output_path]
  @output_extension = options[:output_extension] || File.extname(@filename)
  @runner = CommandRunner
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



4
5
6
# File 'lib/ffsplitter/ffmpeg.rb', line 4

def filename
  @filename
end

#output_extensionObject

Returns the value of attribute output_extension.



4
5
6
# File 'lib/ffsplitter/ffmpeg.rb', line 4

def output_extension
  @output_extension
end

#output_pathObject

Returns the value of attribute output_path.



4
5
6
# File 'lib/ffsplitter/ffmpeg.rb', line 4

def output_path
  @output_path
end

#runnerObject

Returns the value of attribute runner.



4
5
6
# File 'lib/ffsplitter/ffmpeg.rb', line 4

def runner
  @runner
end

Instance Method Details

#chapter_command(chapter) ⇒ Object



22
23
24
25
# File 'lib/ffsplitter/ffmpeg.rb', line 22

def chapter_command(chapter)
  output_file = File.expand_path(chapter.filename, output_path)
  "ffmpeg -ss #{chapter.start_time} -i '#{filename}' -t #{chapter.duration} #{CODEC_OPTIONS} '#{output_file}#{output_extension}'"
end

#encode(chapters) ⇒ Object



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

def encode(chapters)
  commands = chapters.collect { |c| chapter_command(c) }
  runner.run("#{commands.join(' && ')}")
end

#read_metadataObject



13
14
15
# File 'lib/ffsplitter/ffmpeg.rb', line 13

def 
  runner.run("ffmpeg -i '#{filename}' -v quiet -f ffmetadata -")
end