From 0a99742819e73579a2299354f0f74f60456c2e60 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 30 Aug 2021 15:52:34 +0200 Subject: [PATCH] Update ffmpeg lib to fix occasional crash --- app/build.gradle | 6 +-- .../replayer/ReplayExportService.kt | 48 ++++++++++++------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b9c36381..8dee7729 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,8 +35,8 @@ android { applicationId "net.pokeranalytics.android" minSdkVersion 23 targetSdkVersion 30 - versionCode 125 - versionName "5.4.3" + versionCode 128 + versionName "5.4.5" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -147,7 +147,7 @@ dependencies { implementation 'org.apache.commons:commons-math3:3.6.1' // ffmpeg for encoding video (HH export) - implementation 'com.arthenica:mobile-ffmpeg-min-gpl:4.4.LTS' + implementation 'com.arthenica:ffmpeg-kit-min-gpl:4.4.LTS' // Instrumented Tests androidTestImplementation 'androidx.test:core:1.3.0' diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt index 84e7734a..b93957a6 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt @@ -11,9 +11,7 @@ import android.os.Environment import android.os.IBinder import android.provider.MediaStore import androidx.core.content.FileProvider -import com.arthenica.mobileffmpeg.Config.RETURN_CODE_CANCEL -import com.arthenica.mobileffmpeg.Config.RETURN_CODE_SUCCESS -import com.arthenica.mobileffmpeg.FFmpeg +import com.arthenica.ffmpegkit.FFmpegKit import io.realm.Realm import kotlinx.coroutines.* import net.pokeranalytics.android.R @@ -180,17 +178,18 @@ class ReplayExportService : Service() { Timber.d("Assembling images for video...") - FFmpeg.executeAsync("-f concat -safe 0 -i $dpath -vb 20M -vsync vfr -s ${width}x${height} -vf fps=20 -pix_fmt yuv420p $output") { id, rc -> + val command = "-f concat -safe 0 -i $dpath -vb 20M -vsync vfr -s ${width}x${height} -vf fps=20 -pix_fmt yuv420p $output" + FFmpegKit.executeAsync(command) { - when (rc) { - RETURN_CODE_SUCCESS -> { + when { + it.returnCode.isSuccess -> { Timber.d("FFMPEG command execution completed successfully") } - RETURN_CODE_CANCEL -> { + it.returnCode.isCancel -> { Timber.d("Command execution cancelled by user.") } else -> { - Timber.d(String.format("Command execution failed with rc=%d and the output below.", rc)) + Timber.d(String.format("Command execution failed with rc=%d and the output below.", it.returnCode.value)) } } @@ -378,15 +377,32 @@ class ReplayExportService : Service() { Environment.getExternalStorageState(tmpDir) Timber.d("Assembling images for video...") - FFmpeg.executeAsync("-f concat -safe 0 -i $dpath -vb 20M -vsync vfr -s ${width}x${height} -vf fps=20 -pix_fmt yuv420p $output") { id, rc -> - - if (rc == RETURN_CODE_SUCCESS) { - Timber.d("FFMPEG command execution completed successfully") - } else if (rc == RETURN_CODE_CANCEL) { - Timber.d("Command execution cancelled by user.") - } else { - Timber.d(String.format("Command execution failed with rc=%d and the output below.", rc)) + + + val command = "-f concat -safe 0 -i $dpath -vb 20M -vsync vfr -s ${width}x${height} -vf fps=20 -pix_fmt yuv420p $output" + FFmpegKit.executeAsync(command) { + + when { + it.returnCode.isSuccess -> { + Timber.d("FFMPEG command execution completed successfully") + } + it.returnCode.isCancel -> { + Timber.d("Command execution cancelled by user.") + } + else -> { + Timber.d(String.format("Command execution failed with rc=%d and the output below.", it.returnCode.value)) + } } + +// FFmpeg.executeAsync("-f concat -safe 0 -i $dpath -vb 20M -vsync vfr -s ${width}x${height} -vf fps=20 -pix_fmt yuv420p $output") { id, rc -> +// +// if (rc == RETURN_CODE_SUCCESS) { +// Timber.d("FFMPEG command execution completed successfully") +// } else if (rc == RETURN_CODE_CANCEL) { +// Timber.d("Command execution cancelled by user.") +// } else { +// Timber.d(String.format("Command execution failed with rc=%d and the output below.", rc)) +// } // Delete descriptor and image files // tmpDir.delete() // File(dpath).delete()