airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
35.03k stars 5.41k forks source link

App Crash Due to Lottie Animation Frame Updates During Video Rendering #2563

Closed SujalLathiya closed 4 weeks ago

SujalLathiya commented 4 weeks ago

Description:

The app crashes when recording a video using Lottie animations in the background. During the rendering operation, the animation frames continue to update in the background, which causes the app to become unresponsive and eventually crash.

Steps to Reproduce:

  1. Start video rendering using the provided code.
  2. Notice that the Lottie animation continues to update its frames while recording.
  3. As the frames update, the app becomes non-responsive and crashes.

Video Demonstration:

Here is a video demonstration of the issue, showing the behavior during rendering.

Expected Behavior:

Actual Behavior:

Relevant Code:

private fun startRendering() {
    isRender = true
    binding.mainvideoContainer.animationView.pauseAnimation()
    mediaPlayer?.pause()

    binding.progressInclude.root.visibility = View.VISIBLE
    binding.seekTemplateDuration.visibility = View.GONE
    binding.progressInclude.tvProgress.text = "0%"

    renderVideo()
}

private fun renderVideo() {
    val outputPath = "$templateJsonPath/InstaStoryMaker/"
    val outputDir = File(outputPath)
    if (!outputDir.exists()) {
        outputDir.mkdirs()
    }

    val videoFile = File(outputPath, "${System.currentTimeMillis()}_video.mp4")
    val themeDir = File(
        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
        FOLDER_NAME
    )
    if (!themeDir.exists()) {
        themeDir.mkdirs()
    }

    val finalOutputPath = "${themeDir.absolutePath}/${System.currentTimeMillis()}_videos.mp4"

    CoroutineScope(Dispatchers.IO).launch {
        lottieDrawable = binding.mainvideoContainer.animationView.drawable as LottieDrawable
        val recordingOperation = RecordingOperation(
            Recorder(
                mimeType = MimeTypes.VIDEO_H264,
                videoOutput = videoFile,
                width = 720,
                height = 1280
            ),
            FrameCreator(lottieDrawable),
            onCompleteListener = {
                Log.d("TAG", "Recording completed")
                loadBinary(videoFile.absolutePath, File(""), finalOutputPath, themeDir)
            },
            onProgressUpdate = { progress ->
                Log.d("TAG", "Progress: $progress%")
                runOnUiThread {
                    binding.progressInclude.tvProgress.text = "$progress%"
                }
            }
        )
        recordingOperation.start()
    }
}
gpeal commented 4 weeks ago

Duplicate of #2562