Untitled

mail@pastecode.io avatar
unknown
kotlin
a year ago
1.7 kB
2
Indexable
Never
private fun generateVideo(outputFile: File, videoResolution: VideoResolution) {
        try {
            prepareEncoder(outputFile, videoResolution)

            lottie_container_view.prepareTransformMatrix()
//            lottie_container_view.prepareAnimationFrame()
            val scale = videoResolution.width.toFloat() / frame_final_image.width
            for (i in 0..vidDuration step step) {
                if (interruptExporting) {
                    return
                }

                viewModel.exportProgress.postValue(i * 100 / vidDuration)
                drainEncoder(false)
                var postedCount = 0
                lottie_container_view.stickers.forEach {
                    val currentFrame = (i * it.maxFrame * it.speed / it.duration) % it.maxFrame
                    if (isBelowAndroid8()) {
                        it.post {
                            it.frame = currentFrame.toInt()
                            postedCount++
                        }
                    } else {
                        it.frame = currentFrame.toInt()
                    }
                }
                if (isBelowAndroid8()) {
                    while (postedCount != lottie_container_view.stickers.size) {
                        // Do nothing, just use this to block the call to the next function until all frames are ready
                    }
                }
                generateFrame(scale)
            }

            drainEncoder(true)
        } catch (ex: IOException) {
            ex.printStackTrace()
        } finally {
            releaseEncoder()
        }
    }