Class: FFMPEG::Transcoder
- Inherits:
-
Object
- Object
- FFMPEG::Transcoder
- Defined in:
- lib/ffmpeg/transcoder.rb
Overview
Transcodes media files with progress reporting
Instance Attribute Summary collapse
-
#media ⇒ Media
readonly
Source media.
-
#options ⇒ Hash
readonly
Transcoding options.
-
#output_path ⇒ String
readonly
Output path.
Instance Method Summary collapse
-
#command ⇒ Array<String>
Get the FFmpeg command that will be executed.
-
#command_preview ⇒ String
Preview the command as a string.
-
#initialize(media, output_path, **options) ⇒ Transcoder
constructor
Create a new Transcoder.
-
#run {|Float| ... } ⇒ Media
Run the transcoding.
Constructor Details
#initialize(media, output_path, **options) ⇒ Transcoder
Create a new Transcoder
50 51 52 53 54 |
# File 'lib/ffmpeg/transcoder.rb', line 50 def initialize(media, output_path, **) @media = media @output_path = File.(output_path) = .merge() end |
Instance Attribute Details
#media ⇒ Media (readonly)
Returns source media.
22 23 24 |
# File 'lib/ffmpeg/transcoder.rb', line 22 def media @media end |
#options ⇒ Hash (readonly)
Returns transcoding options.
28 29 30 |
# File 'lib/ffmpeg/transcoder.rb', line 28 def end |
#output_path ⇒ String (readonly)
Returns output path.
25 26 27 |
# File 'lib/ffmpeg/transcoder.rb', line 25 def output_path @output_path end |
Instance Method Details
#command ⇒ Array<String>
Get the FFmpeg command that will be executed
80 81 82 |
# File 'lib/ffmpeg/transcoder.rb', line 80 def command build_command end |
#command_preview ⇒ String
Preview the command as a string
86 87 88 |
# File 'lib/ffmpeg/transcoder.rb', line 86 def command_preview build_command.join(" ") end |
#run {|Float| ... } ⇒ Media
Run the transcoding
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ffmpeg/transcoder.rb', line 60 def run(&block) ensure_output_directory! cmd = build_command total_duration = calculate_duration Command.run!(*cmd) do |line| if block_given? && total_duration&.positive? progress = parse_progress(line, total_duration) yield progress if progress end end yield 100.0 if block_given? Media.new(output_path) end |