Skip to content

Instantly share code, notes, and snippets.

@prateek54
Last active October 24, 2023 15:18
Show Gist options
  • Save prateek54/30250599fa5bd5fc9f0d430ad6589afc to your computer and use it in GitHub Desktop.
Save prateek54/30250599fa5bd5fc9f0d430ad6589afc to your computer and use it in GitHub Desktop.
Method to Transform the video
val effect = arrayListOf<Effect>()
effect.add(RgbFilter.createGrayscaleFilter())
effect.add(MatrixTransformationFactory.createZoomInTransition())
effect.add(ScaleAndRotateTransformation.Builder().setRotationDegrees(90F).build())
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.fromUri(videoUrl)
val filePath = File(externalCacheDir, fileName)
val editedMediaItem = EditedMediaItem.Builder(inputMediaItem).apply {
setRemoveAudio(true)
setEffects(Effects(mutableListOf(), effect))
}
transformer.start(editedMediaItem.build(), filePath.absolutePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment