#android #ffmpeg
#Android #ffmpeg
Вопрос:
Я пытаюсь конвертировать MP4, размещенный в MediaStore, в GIF. с помощью этой библиотеки
Но, похоже, он не работает с Uri MediaStore
Это мой код :
fun convertToGif(fileUri: Uri): Boolean {
var result = false
val newFileName = fileUri.toString().substringAfterLast("/").substringBefore(".") ".gif"
val values = ContentValues()
values.put(MediaStore.Images.Media.DISPLAY_NAME, newFileName)
values.put(MediaStore.Images.Media.MIME_TYPE, "image/gif")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
values.put(MediaStore.Images.Media.IS_PENDING, 1)
}
val contentResolver: ContentResolver = context.contentResolver
val newFileUri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)!!
try {
val pdf = contentResolver.openFileDescriptor(newFileUri, "w", null)
if (pdf == null) {
throw NullPointerException("ParcelFileDescriptor is Null")
} else {
val source = File(fileUri.toString())
val destination = File(newFileUri.toString())
val command = "-i $source $destination"
result = when (FFmpeg.execute(command)) {
Config.RETURN_CODE_SUCCESS -> {
Log.i(Config.TAG, "Command execution completed successfully.")
true
}
Config.RETURN_CODE_CANCEL -> {
Log.i(Config.TAG, "Command execution cancelled by user.")
false
}
else -> {
Log.i(
Config.TAG,
String.format("Command execution failed with rc=%d and the output below.", result)
)
Config.printLastCommandOutput(Log.INFO)
false
}
}
}
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
return result
}
Могу ли я как-нибудь решить эту проблему?