Class: Vizcore::Renderer::RenderSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/vizcore/renderer/render_sequence.rb

Overview

Writes a deterministic PNG image sequence from a scene.

Constant Summary collapse

DEFAULT_FRAME_COUNT =
60
DEFAULT_FRAME_RATE =
30.0

Instance Method Summary collapse

Constructor Details

#initialize(config:, frames: DEFAULT_FRAME_COUNT, fps: DEFAULT_FRAME_RATE, width: SnapshotRenderer::DEFAULT_WIDTH, height: SnapshotRenderer::DEFAULT_HEIGHT, duration: nil, from_frame: 1, to_frame: nil, resume: false, seed: nil, transparent: false, video_codec: nil, video_bitrate: nil, video_crf: nil, pixel_format: "yuv420p", progress_reporter: nil, command_runner: Open3, ffmpeg_checker: nil) ⇒ RenderSequence

Returns a new instance of RenderSequence.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vizcore/renderer/render_sequence.rb', line 17

def initialize(
  config:,
  frames: DEFAULT_FRAME_COUNT,
  fps: DEFAULT_FRAME_RATE,
  width: SnapshotRenderer::DEFAULT_WIDTH,
  height: SnapshotRenderer::DEFAULT_HEIGHT,
  duration: nil,
  from_frame: 1,
  to_frame: nil,
  resume: false,
  seed: nil,
  transparent: false,
  video_codec: nil,
  video_bitrate: nil,
  video_crf: nil,
  pixel_format: "yuv420p",
  progress_reporter: nil,
  command_runner: Open3,
  ffmpeg_checker: nil
)
  @config = config
  @fps = normalize_frame_rate(fps)
  @frames = normalize_frame_count(duration ? (Float(duration) * @fps).ceil : frames)
  @from_frame = normalize_frame_index(from_frame, "from-frame")
  @to_frame = normalize_optional_frame_index(to_frame, "to-frame")
  @to_frame = @frames if @to_frame.nil?
  raise ArgumentError, "to-frame must be greater than or equal to from-frame" if @to_frame < @from_frame
  raise ArgumentError, "from-frame must be within rendered frame count" if @from_frame > @frames

  @to_frame = [@to_frame, @frames].min
  @output_frames = @to_frame - @from_frame + 1
  @resume = !!resume
  @seed = normalize_seed(seed)
  @transparent = !!transparent
  @video_codec = optional_string(video_codec, "video codec")
  @video_bitrate = optional_string(video_bitrate, "video bitrate")
  @video_crf = optional_string(video_crf, "video crf")
  @pixel_format = optional_string(pixel_format, "pixel format") || "yuv420p"
  @progress_reporter = progress_reporter
  @width = width
  @height = height
  @command_runner = command_runner
  @ffmpeg_checker = ffmpeg_checker || method(:ffmpeg_available?)
end

Instance Method Details

#write(out:) ⇒ Hash

Returns render metadata.

Parameters:

  • out (String, Pathname)

    output directory for PNG frames, or ‘.mp4`

Returns:

  • (Hash)

    render metadata



64
65
66
67
68
69
# File 'lib/vizcore/renderer/render_sequence.rb', line 64

def write(out:)
  output_path = Pathname.new(out.to_s).expand_path
  return write_video(output_path) if video_output?(output_path)

  write_frames(output_path)
end