[orx-video-profiles] Add video profile extension functions

This commit is contained in:
Edwin Jakobs
2022-07-14 12:54:37 +02:00
parent 5b7327eda1
commit a6de46d71c
7 changed files with 64 additions and 17 deletions

View File

@@ -15,7 +15,7 @@ import org.openrndr.ffmpeg.ScreenRecorder
fun main() = application { fun main() = application {
program { program {
extend(ScreenRecorder()) { extend(ScreenRecorder()) {
profile = GIFProfile() gif()
} }
extend { extend {
drawer.clear(ColorRGBa.GREEN) drawer.clear(ColorRGBa.GREEN)
@@ -38,7 +38,7 @@ This profile requires specifying a file name: `outputFile = "frame-%05d.png"`,
where `%05d` means "zero-padded five-digit frame number". where `%05d` means "zero-padded five-digit frame number".
The frame number format is not optional. The frame number format is not optional.
``` ```kotlin
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.extra.videoprofiles.* import org.openrndr.extra.videoprofiles.*
@@ -47,7 +47,7 @@ import org.openrndr.ffmpeg.ScreenRecorder
fun main() = application { fun main() = application {
program { program {
extend(ScreenRecorder()) { extend(ScreenRecorder()) {
profile = PNGProfile() pngSequence()
outputFile = "frame-%05d.png" outputFile = "frame-%05d.png"
} }
extend { extend {
@@ -59,7 +59,7 @@ fun main() = application {
### Animated Webp ### Animated Webp
``` ```kotlin
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.extra.videoprofiles.* import org.openrndr.extra.videoprofiles.*
@@ -68,7 +68,7 @@ import org.openrndr.ffmpeg.ScreenRecorder
fun main() = application { fun main() = application {
program { program {
extend(ScreenRecorder()) { extend(ScreenRecorder()) {
profile = WebpProfile() webp()
} }
extend { extend {
drawer.clear(ColorRGBa.GREEN) drawer.clear(ColorRGBa.GREEN)
@@ -80,7 +80,7 @@ fun main() = application {
### Prores (large file, high quality video) ### Prores (large file, high quality video)
``` ```kotlin
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.extra.videoprofiles.* import org.openrndr.extra.videoprofiles.*
@@ -89,10 +89,8 @@ import org.openrndr.ffmpeg.ScreenRecorder
fun main() = application { fun main() = application {
program { program {
extend(ScreenRecorder()) { extend(ScreenRecorder()) {
// .apply is optional, for further configuration prores {
profile = ProresProfile().apply {
profile = ProresProfile.Profile.HQ4444 profile = ProresProfile.Profile.HQ4444
codec = "prores_ks"
} }
} }
extend { extend {
@@ -102,9 +100,9 @@ fun main() = application {
} }
``` ```
### X265 ### H265
``` ```kotlin
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.extra.videoprofiles.* import org.openrndr.extra.videoprofiles.*
@@ -113,11 +111,8 @@ import org.openrndr.ffmpeg.ScreenRecorder
fun main() = application { fun main() = application {
program { program {
extend(ScreenRecorder()) { extend(ScreenRecorder()) {
// .apply is optional, for further configuration h265 {
profile = X265Profile().apply {
mode(X265Profile.WriterMode.Lossless)
constantRateFactor(23) constantRateFactor(23)
hlg = true
} }
} }
extend { extend {

View File

@@ -1,4 +1,5 @@
package org.openrndr.extra.videoprofiles package org.openrndr.extra.videoprofiles
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.ffmpeg.VideoWriterProfile import org.openrndr.ffmpeg.VideoWriterProfile
class GIFProfile : VideoWriterProfile() { class GIFProfile : VideoWriterProfile() {
@@ -8,3 +9,10 @@ class GIFProfile : VideoWriterProfile() {
return arrayOf("-vf", "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=none:diff_mode=rectangle,vflip") return arrayOf("-vf", "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=none:diff_mode=rectangle,vflip")
} }
} }
/**
* Configure an animated GIF video profile
*/
fun ScreenRecorder.gif(configure : GIFProfile.() -> Unit = {}) {
profile = GIFProfile().apply(configure)
}

View File

@@ -1,7 +1,11 @@
package org.openrndr.extra.videoprofiles package org.openrndr.extra.videoprofiles
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.ffmpeg.VideoWriterProfile import org.openrndr.ffmpeg.VideoWriterProfile
class X265Profile : VideoWriterProfile() { @Deprecated("use h265 profile", replaceWith = ReplaceWith("H265Profile"))
typealias X265Profile = H265Profile
class H265Profile : VideoWriterProfile() {
internal var mode = WriterMode.Normal internal var mode = WriterMode.Normal
internal var constantRateFactor = 28 internal var constantRateFactor = 28
var hlg = false var hlg = false
@@ -58,3 +62,10 @@ class X265Profile : VideoWriterProfile() {
} }
} }
} }
/**
* Configure a h265 video profile
*/
fun ScreenRecorder.h265(configure : H265Profile.() -> Unit = {}) {
profile = H265Profile().apply(configure)
}

View File

@@ -1,4 +1,5 @@
package org.openrndr.extra.videoprofiles package org.openrndr.extra.videoprofiles
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.ffmpeg.VideoWriterProfile import org.openrndr.ffmpeg.VideoWriterProfile
/** /**
@@ -14,3 +15,10 @@ class PNGProfile : VideoWriterProfile() {
return arrayOf("-vf", "vflip") return arrayOf("-vf", "vflip")
} }
} }
/**
* Configure a png sequence profile
*/
fun ScreenRecorder.pngSequence(configure : PNGProfile.() -> Unit = {}) {
profile = PNGProfile().apply(configure)
}

View File

@@ -1,5 +1,6 @@
package org.openrndr.extra.videoprofiles package org.openrndr.extra.videoprofiles
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.ffmpeg.VideoWriterProfile import org.openrndr.ffmpeg.VideoWriterProfile
class ProresProfile : VideoWriterProfile() { class ProresProfile : VideoWriterProfile() {
@@ -23,3 +24,10 @@ class ProresProfile : VideoWriterProfile() {
return vcodec + profile + filters + audio return vcodec + profile + filters + audio
} }
} }
/**
* Configure a Prores video profile
*/
fun ScreenRecorder.prores(configure : ProresProfile.() -> Unit = {}) {
profile = ProresProfile().apply(configure)
}

View File

@@ -1,4 +1,5 @@
package org.openrndr.extra.videoprofiles package org.openrndr.extra.videoprofiles
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.ffmpeg.VideoWriterProfile import org.openrndr.ffmpeg.VideoWriterProfile
/** /**
@@ -14,3 +15,10 @@ class TIFFProfile : VideoWriterProfile() {
return arrayOf("-vf", "vflip") return arrayOf("-vf", "vflip")
} }
} }
/**
* Configure a tiff sequence profile
*/
fun ScreenRecorder.tiffSequence(configure : TIFFProfile.() -> Unit = {}) {
profile = TIFFProfile().apply(configure)
}

View File

@@ -1,4 +1,5 @@
package org.openrndr.extra.videoprofiles package org.openrndr.extra.videoprofiles
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.ffmpeg.VideoWriterProfile import org.openrndr.ffmpeg.VideoWriterProfile
class WebpProfile : VideoWriterProfile() { class WebpProfile : VideoWriterProfile() {
@@ -8,3 +9,11 @@ class WebpProfile : VideoWriterProfile() {
return arrayOf("-vf", "vflip") return arrayOf("-vf", "vflip")
} }
} }
/**
* Configure a webp video profile
*/
fun ScreenRecorder.webp(configure : WebpProfile.() -> Unit) {
profile = WebpProfile().apply(configure)
}