Skip to content

Instantly share code, notes, and snippets.

@prateek54
Created October 21, 2023 21:00
Show Gist options
  • Save prateek54/9adbd07e4308d34bd372e7b2dc50e1e1 to your computer and use it in GitHub Desktop.
Save prateek54/9adbd07e4308d34bd372e7b2dc50e1e1 to your computer and use it in GitHub Desktop.
Function to Convert Video to Grayscale using Media Transaformer
private fun convertToGrayScale() {
val effect = arrayListOf<Effect>()
effect.add(RgbFilter.createGrayscaleFilter())
val transformer = with(Transformer.Builder(this)) {
addListener(object : Transformer.Listener {
override fun onCompleted(composition: Composition, exportResult: ExportResult) {
//Play the video from the path you specified below
}
override fun onError(
composition: Composition,
exportResult: ExportResult,
exportException: ExportException
) {
//Handle error scenarios
}
})
build()
}
val inputMediaItem = MediaItem.Builder().apply {
setUri("<videoUrl>")
}.build()
val editedMediaItem = EditedMediaItem.Builder(inputMediaItem).apply {
setEffects(Effects(mutableListOf(), effect))
}
transformer.start(editedMediaItem.build(), "file://<path>")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment