blob: 78cde2c76075f2aa0b1a6b7e0a85069fb1708d24 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
|
package phenax.extensions
import org.openrndr.*
import org.openrndr.draw.*
import org.openrndr.ffmpeg.VideoWriter
import phenax.utils.recordDuration
class HeadlessRecorder : Extension {
override var enabled: Boolean = true
var videoTarget: RenderTarget? = null
var videoWriter: VideoWriter? = null
var maxFrameCount: Int? = null
override fun setup(program: Program) {
val width = program.application.configuration.width
val height = program.application.configuration.height
program.width = width
program.height = height
videoWriter =
VideoWriter().apply {
frameRate = 60
size(width, height)
output("video/${program.name}.mp4")
start()
}
videoTarget =
renderTarget(width, height) {
colorBuffer()
depthBuffer()
}
maxFrameCount = recordDuration()
program.clock = { program.frameCount / (videoWriter?.frameRate?.toDouble() ?: 0.0) }
}
override fun beforeDraw(drawer: Drawer, program: Program) {
videoTarget?.bind()
program.backgroundColor?.let { drawer.clear(it) }
}
override fun afterDraw(drawer: Drawer, program: Program) {
val target = videoTarget ?: return
val writer = videoWriter ?: return
target.unbind()
writer.frame(target.colorBuffer(0))
if (program.frameCount >= (maxFrameCount ?: 60 * 10)) {
writer.stop()
program.application.exit()
}
}
}
|