Created
October 21, 2023 21:00
-
-
Save prateek54/9adbd07e4308d34bd372e7b2dc50e1e1 to your computer and use it in GitHub Desktop.
Function to Convert Video to Grayscale using Media Transaformer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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