Class: FFSplitter::FFMpeg
- Inherits:
-
Object
- Object
- FFSplitter::FFMpeg
- Defined in:
- lib/ffsplitter/ffmpeg.rb
Constant Summary collapse
- CODEC_OPTIONS =
"-c copy -movflags faststart"
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#output_directory ⇒ Object
Returns the value of attribute output_directory.
-
#runner ⇒ Object
Returns the value of attribute runner.
Instance Method Summary collapse
- #chapter_command(chapter) ⇒ Object
- #encode(chapters) ⇒ Object
-
#initialize(filename, output_directory = nil) ⇒ FFMpeg
constructor
A new instance of FFMpeg.
- #read_metadata ⇒ Object
Constructor Details
#initialize(filename, output_directory = nil) ⇒ FFMpeg
Returns a new instance of FFMpeg.
6 7 8 9 10 |
# File 'lib/ffsplitter/ffmpeg.rb', line 6 def initialize(filename, output_directory=nil) @filename = filename @output_directory = output_directory @runner = CommandRunner end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/ffsplitter/ffmpeg.rb', line 4 def filename @filename end |
#output_directory ⇒ Object
Returns the value of attribute output_directory.
4 5 6 |
# File 'lib/ffsplitter/ffmpeg.rb', line 4 def output_directory @output_directory end |
#runner ⇒ Object
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
21 22 23 24 |
# File 'lib/ffsplitter/ffmpeg.rb', line 21 def chapter_command(chapter) output_file = File.(chapter.filename, output_directory) "ffmpeg -ss #{chapter.start_time} -i '#{filename}' -t #{chapter.duration} #{CODEC_OPTIONS} '#{output_file}.mp4'" end |
#encode(chapters) ⇒ Object
16 17 18 19 |
# File 'lib/ffsplitter/ffmpeg.rb', line 16 def encode(chapters) commands = chapters.collect { |c| chapter_command(c) } runner.run("#{commands.join(' && ')}") end |
#read_metadata ⇒ Object
12 13 14 |
# File 'lib/ffsplitter/ffmpeg.rb', line 12 def runner.run("ffmpeg -i '#{filename}' -v quiet -f ffmetadata -") end |