Playing videos
OPENRNDR comes with FFMPEG-backed video support.
A simple video player
Relevant APIs
fun main() = application {
program {
val videoPlayer = loadVideo("data/video.mp4")
videoPlayer.play()
extend {
drawer.clear(ColorRGBa.BLACK)
videoPlayer.draw(drawer)
}
}
}
Looping a video
// Loop: restart when reaching the end
videoPlayer.ended.listen {
videoPlayer.restart()
}
extend {
videoPlayer.draw(drawer)
}
Video from camera devices
The VideoPlayerFFMPEG class can be used to get and display video data from camera devices. To open a camera device you use the fromDevice(null) method. The first argument specifies the audio device to use, which we can set to null for video-only.
VideoPlayerFFMPEG has minimal device listing capabilities. The device names of available input devices can be listed using VideoPlayerFFMPEG.listDeviceNames.
Relevant APIs
Examples
fun main() = application {
program {
val videoPlayer = VideoPlayerFFMPEG.fromDevice(null)
videoPlayer.play()
extend {
drawer.clear(ColorRGBa.BLACK)
videoPlayer.draw(drawer)
}
}
}
Processing video
Video playback can be combined with render targets and filters.
In the following example the video player output is blurred before presenting it on the screen.
fun main() = application {
program {
val videoPlayer = loadVideo("data/video.mp4")
val blur = BoxBlur()
val renderTarget = renderTarget(width, height) {
colorBuffer()
}
videoPlayer.play()
extend {
drawer.clear(ColorRGBa.BLACK)
// -- draw the video on the render target
drawer.withTarget(renderTarget) {
videoPlayer.draw(drawer)
}
// -- apply a blur on the render target's color attachment
blur.apply(renderTarget.colorBuffer(0), renderTarget.colorBuffer(0))
// -- draw the blurred color attachment
drawer.image(renderTarget.colorBuffer(0))
}
}
}