Module: AnimateIt::AssetRenderer
- Defined in:
- lib/animate_it/asset_renderer.rb
Overview
Drives a composition through every Output it declared, writing each one to its absolute repo-relative path. One VideoRenderer per output (cheap — frames are captured once per output even when the same composition has several formats, because each format wants a different ffmpeg encode).
Class Method Summary collapse
-
.effective_range_for(output, frame_range) ⇒ Object
A still PNG output always renders its declared single frame; if the caller-supplied range excludes that frame, skip the output entirely.
- .render_composition(composition, host:, on_progress: nil, frame_range: nil) ⇒ Object
- .render_output(composition, output, host:, on_progress: nil, frame_range: nil) ⇒ Object
Class Method Details
.effective_range_for(output, frame_range) ⇒ Object
A still PNG output always renders its declared single frame; if the caller-supplied range excludes that frame, skip the output entirely. Animated outputs use the caller's range when provided, otherwise render the full composition.
39 40 41 42 43 44 45 46 47 |
# File 'lib/animate_it/asset_renderer.rb', line 39 def effective_range_for(output, frame_range) if output.still? return :skip if frame_range && !frame_range.cover?(output.frame) output.frame..output.frame else frame_range end end |
.render_composition(composition, host:, on_progress: nil, frame_range: nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/animate_it/asset_renderer.rb', line 9 def render_composition(composition, host:, on_progress: nil, frame_range: nil) raise Error, "Composition #{composition.id} has no `outputs do ... end`" if composition.outputs.empty? composition.outputs.map do |output| render_output(composition, output, host: host, on_progress: on_progress, frame_range: frame_range) end end |
.render_output(composition, output, host:, on_progress: nil, frame_range: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/animate_it/asset_renderer.rb', line 17 def render_output(composition, output, host:, on_progress: nil, frame_range: nil) effective_range = effective_range_for(output, frame_range) return nil if effective_range == :skip destination = output.absolute_path FileUtils.mkdir_p(destination.dirname) renderer = VideoRenderer.new( composition: composition, host: host, output_path: destination, format: output.format ) renderer.render(frame_range: effective_range, on_progress: on_progress) destination end |