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_extension ⇒ Object
Returns the value of attribute output_extension.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#runner ⇒ Object
Returns the value of attribute runner.
Instance Method Summary collapse
- #chapter_command(chapter) ⇒ Object
- #encode(chapters) ⇒ Object
-
#initialize(options) ⇒ FFMpeg
constructor
A new instance of FFMpeg.
- #read_metadata ⇒ Object
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() @filename = [:filename] @output_path = [:output_path] @output_extension = [:output_extension] || File.extname(@filename) @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_extension ⇒ Object
Returns the value of attribute output_extension.
4 5 6 |
# File 'lib/ffsplitter/ffmpeg.rb', line 4 def output_extension @output_extension end |
#output_path ⇒ Object
Returns the value of attribute output_path.
4 5 6 |
# File 'lib/ffsplitter/ffmpeg.rb', line 4 def output_path @output_path 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
22 23 24 25 |
# File 'lib/ffsplitter/ffmpeg.rb', line 22 def chapter_command(chapter) output_file = File.(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_metadata ⇒ Object
13 14 15 |
# File 'lib/ffsplitter/ffmpeg.rb', line 13 def runner.run("ffmpeg -i '#{filename}' -v quiet -f ffmetadata -") end |