Class: Ace::Demo::Molecules::MediaRetimer
- Inherits:
-
Object
- Object
- Ace::Demo::Molecules::MediaRetimer
- Defined in:
- lib/ace/demo/molecules/media_retimer.rb
Instance Method Summary collapse
-
#initialize(ffmpeg_bin: "ffmpeg") ⇒ MediaRetimer
constructor
A new instance of MediaRetimer.
- #retime(input_path:, speed:, output_path: nil, dry_run: false) ⇒ Object
Constructor Details
#initialize(ffmpeg_bin: "ffmpeg") ⇒ MediaRetimer
Returns a new instance of MediaRetimer.
11 12 13 |
# File 'lib/ace/demo/molecules/media_retimer.rb', line 11 def initialize(ffmpeg_bin: "ffmpeg") @ffmpeg_bin = ffmpeg_bin end |
Instance Method Details
#retime(input_path:, speed:, output_path: nil, dry_run: false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ace/demo/molecules/media_retimer.rb', line 15 def retime(input_path:, speed:, output_path: nil, dry_run: false) raise ArgumentError, "Input file not found: #{input_path}" unless File.exist?(input_path) parsed = Atoms::PlaybackSpeedParser.parse(speed) raise ArgumentError, "Playback speed is required." unless parsed target_path = output_path || default_output_path(input_path, parsed[:label]) return {input_path: input_path, output_path: target_path, speed: parsed[:label], dry_run: true} if dry_run ensure_ffmpeg_available! FileUtils.mkdir_p(File.dirname(target_path)) cmd = build_ffmpeg_command( input_path: input_path, output_path: target_path, factor: parsed[:factor] ) _stdout, stderr, status = Open3.capture3(*cmd) raise MediaRetimeError, "FFmpeg retime failed: #{stderr.strip}" unless status.success? {input_path: input_path, output_path: target_path, speed: parsed[:label], dry_run: false} rescue Errno::ENOENT raise FfmpegNotFoundError, "FFmpeg not found. Install ffmpeg to use retime." end |