From 367a227ccd82174933f3532e6531a4757684e837 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Wed, 25 Jan 2023 14:53:06 +0100 Subject: [PATCH] [orx-video-profiles] Expose filters in video profiles --- .../src/main/kotlin/GIFProfile.kt | 4 +- .../src/main/kotlin/H265Profile.kt | 93 ++++++++++--------- .../src/main/kotlin/PNGProfile.kt | 4 +- .../src/main/kotlin/ProresProfile.kt | 4 +- .../src/main/kotlin/TIFFProfile.kt | 3 +- .../src/main/kotlin/WebpProfile.kt | 5 +- 6 files changed, 63 insertions(+), 50 deletions(-) diff --git a/orx-jvm/orx-video-profiles/src/main/kotlin/GIFProfile.kt b/orx-jvm/orx-video-profiles/src/main/kotlin/GIFProfile.kt index 2e8816c8..7d0947fa 100644 --- a/orx-jvm/orx-video-profiles/src/main/kotlin/GIFProfile.kt +++ b/orx-jvm/orx-video-profiles/src/main/kotlin/GIFProfile.kt @@ -5,8 +5,10 @@ import org.openrndr.ffmpeg.VideoWriterProfile class GIFProfile : VideoWriterProfile() { override val fileExtension = "gif" + val filters = mutableListOf("split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=none:diff_mode=rectangle", "vflip") + override fun arguments(): Array { - return arrayOf("-vf", "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=none:diff_mode=rectangle,vflip") + return arrayOf("-vf", filters.joinToString(",")) } } diff --git a/orx-jvm/orx-video-profiles/src/main/kotlin/H265Profile.kt b/orx-jvm/orx-video-profiles/src/main/kotlin/H265Profile.kt index 52039803..832760b8 100644 --- a/orx-jvm/orx-video-profiles/src/main/kotlin/H265Profile.kt +++ b/orx-jvm/orx-video-profiles/src/main/kotlin/H265Profile.kt @@ -5,61 +5,64 @@ import org.openrndr.ffmpeg.VideoWriterProfile @Deprecated("use h265 profile", replaceWith = ReplaceWith("H265Profile")) typealias X265Profile = H265Profile + class H265Profile : VideoWriterProfile() { - internal var mode = WriterMode.Normal - internal var constantRateFactor = 28 - var hlg = false - - enum class WriterMode { - Normal, - Lossless - } - - fun mode(mode: WriterMode): X265Profile { - this.mode = mode - return this - } /** - * Sets the constant rate factor - * @param constantRateFactor the constant rate factor (default is 28) - * @return + * constant rate factor (default is 23) */ - fun constantRateFactor(constantRateFactor: Int): X265Profile { - this.constantRateFactor = constantRateFactor - return this + var constantRateFactor = null as Int? + + @Deprecated("Use constantRateFactor property") + fun constantRateFactor(factor: Int) { + constantRateFactor = factor } - override val fileExtension = "mp4" + override var fileExtension = "mp4" + var highPrecisionChroma = true + + val CODEC_LIBX265 = "libx265" + + + var videoCodec = CODEC_LIBX265 as String? + var hwaccel = null as String? + var preset = null as String? + + + var pixelFormat = "yuv420p" as String? + var userArguments = emptyArray() + + val filters = mutableListOf("vflip") override fun arguments(): Array { - when (mode) { - WriterMode.Normal -> { - return if (!hlg) { - arrayOf("-pix_fmt", "yuv420p", // this will produce videos that are playable by quicktime - "-vf", "vflip", - "-an", "-vcodec", "libx265", "-crf", "" + constantRateFactor) - } else { - arrayOf( // this will produce videos that are playable by quicktime - "-an", "" + - "-vcodec", "libx265", - "-pix_fmt", "yuv420p10le", - "-color_primaries", "bt2020", - "-colorspace", "bt2020_ncl", - "-color_trc", "arib-std-b67", - "-crf", "" + constantRateFactor) - // transfer=arib-std-b67 - } - } - WriterMode.Lossless -> { - return arrayOf("-pix_fmt", "yuv420p10", // this will produce videos that are playable by quicktime - "-an", "-vcodec", "libx265", "-preset", "ultrafast") - } - else -> { - throw RuntimeException("unsupported write mode") - } + val chromaArguments = if (highPrecisionChroma) { + arrayOf( + "-sws_flags", "spline+accurate_rnd+full_chroma_int", + "-color_range", "1", + "-colorspace", "1", + "-color_primaries","1", + "-color_trc", "1" + ) + } else { + emptyArray() } + + if (highPrecisionChroma) { + filters.add("colorspace=bt709:iall=bt601-6-625:fast=1") + } + + val hwaccelArguments = hwaccel?.let { arrayOf("-hwaccel", it) } ?: emptyArray() + val pixelFormatArguments = pixelFormat?.let { arrayOf("-pix_fmt", it) } ?: emptyArray() + val constantRateArguments = constantRateFactor?.let { arrayOf("-crf", it.toString()) } ?: emptyArray() + val presetArguments = preset?.let { arrayOf("-preset", it) } ?: emptyArray() + val videoCodecArguments = videoCodec?.let { arrayOf("-vcodec", it) } ?: emptyArray() + val filterArguments = arrayOf("-vf", filters.joinToString(",")) + + val arguments = + hwaccelArguments + pixelFormatArguments + chromaArguments + filterArguments + videoCodecArguments + constantRateArguments + presetArguments + userArguments + + return arguments } } diff --git a/orx-jvm/orx-video-profiles/src/main/kotlin/PNGProfile.kt b/orx-jvm/orx-video-profiles/src/main/kotlin/PNGProfile.kt index b44e7bd8..53d275c3 100644 --- a/orx-jvm/orx-video-profiles/src/main/kotlin/PNGProfile.kt +++ b/orx-jvm/orx-video-profiles/src/main/kotlin/PNGProfile.kt @@ -11,8 +11,10 @@ import org.openrndr.ffmpeg.VideoWriterProfile class PNGProfile : VideoWriterProfile() { override val fileExtension = "png" + val filters = mutableListOf("vflip") + override fun arguments(): Array { - return arrayOf("-vf", "vflip") + return arrayOf("-vf", filters.joinToString(",")) } } diff --git a/orx-jvm/orx-video-profiles/src/main/kotlin/ProresProfile.kt b/orx-jvm/orx-video-profiles/src/main/kotlin/ProresProfile.kt index c232093e..077bd46b 100644 --- a/orx-jvm/orx-video-profiles/src/main/kotlin/ProresProfile.kt +++ b/orx-jvm/orx-video-profiles/src/main/kotlin/ProresProfile.kt @@ -16,10 +16,12 @@ class ProresProfile : VideoWriterProfile() { var profile = Profile.SQ var codec = "prores_ks" + val filters = mutableListOf("vflip") + override fun arguments(): Array { val vcodec = arrayOf("-vcodec", codec) val profile = arrayOf("-profile:v", profile.argument) - val filters = arrayOf("-vf", "vflip") + val filters = arrayOf("-vf", filters.joinToString(",")) val audio = arrayOf("-an") return vcodec + profile + filters + audio } diff --git a/orx-jvm/orx-video-profiles/src/main/kotlin/TIFFProfile.kt b/orx-jvm/orx-video-profiles/src/main/kotlin/TIFFProfile.kt index 60a604b9..776242e0 100644 --- a/orx-jvm/orx-video-profiles/src/main/kotlin/TIFFProfile.kt +++ b/orx-jvm/orx-video-profiles/src/main/kotlin/TIFFProfile.kt @@ -11,8 +11,9 @@ import org.openrndr.ffmpeg.VideoWriterProfile class TIFFProfile : VideoWriterProfile() { override val fileExtension = "tif" + val filters = mutableListOf("vflip") override fun arguments(): Array { - return arrayOf("-vf", "vflip") + return arrayOf("-vf", filters.joinToString(",")) } } diff --git a/orx-jvm/orx-video-profiles/src/main/kotlin/WebpProfile.kt b/orx-jvm/orx-video-profiles/src/main/kotlin/WebpProfile.kt index 6b25d8a5..c4b2bf0f 100644 --- a/orx-jvm/orx-video-profiles/src/main/kotlin/WebpProfile.kt +++ b/orx-jvm/orx-video-profiles/src/main/kotlin/WebpProfile.kt @@ -5,8 +5,11 @@ import org.openrndr.ffmpeg.VideoWriterProfile class WebpProfile : VideoWriterProfile() { override val fileExtension = "webp" + + val filters = mutableListOf("vflip") + override fun arguments(): Array { - return arrayOf("-vf", "vflip") + return arrayOf("-vf", filters.joinToString(",")) } }