I am using this FFMPEG library,
first I am playing the video inside my videoView to make sure that the video path is correct
videoView.setVideoURI(Uri.parse(getExternalFilesDir(null)?.absolutePath + "videoToBeEdit"))
then I am calling the code written below to crop the video then put it inside the videoView again just to see the result
val ff = FFmpeg.getInstance(this@EditVideoActivity)
if (ff.isSupported){
val inFile = File(getExternalFilesDir(null)?.absolutePath ,"videoToBeEdit")
val outFile = File(getExternalFilesDir(null)?.absolutePath , "result")
val command = arrayOf("ffmpeg","-i", inFile.absolutePath , "-filter:v", "crop=100:100:0:0", outFile.absolutePath)
ff.execute(command, object : ExecuteBinaryResponseHandler() {
override fun onSuccess(message: String?) {
super.onSuccess(message)
videoView.setVideoURI(Uri.parse(getExternalFilesDir(null)?.absolutePath + "videoToBeEdit"))
}
override fun onProgress(message: String?) {
super.onProgress(message)
}
override fun onFailure(message: String?) {
super.onFailure(message)
Log.e("error", "failed")
}
override fun onStart() {
super.onStart()
Log.e("start", "started the process")
}
override fun onFinish() {
super.onFinish()
Log.e("finish", "done")
}
})
}
but my code above goes from start to error then finish, it doesn't show any error messages and that's making it really hard to know what's actually wrong :( I tried to write my command in different ways following those tutorials tutorial1 tutorial2 link please help, thank you in advance...
Alright After some digging around it turns out that I was supposed to give a path and a name to the FFmpeg to create the file for me and save the data inside that file, I shouldn't create the file and give it the file path because FFmpeg will try to overwrite that file with the one it is trying to create, by default FFmpeg doesn't have permission to overwrite it,lastly, you should also add the file extension (I was saving the file without the extension)
So what is the solution? you can simply give a path to where you want to the FFmpeg to create the file but without creating the file yourself like so
val inFile = File(getExternalFilesDir(null)?.absolutePath ,"videoToBeEdit.mp4")
val outFile = getExternalFilesDir(null)?.absolutePath , "result.mp4"
val command = arrayOf("ffmpeg","-i", inFile.absolutePath , "-filter:v", "crop=100:100:0:0", outfile)
Or you can create the file and then tell the FFmp3g to overwrite it by adding
-y
to the command like so
val inFile = File(getExternalFilesDir(null)?.absolutePath ,"videoToBeEdit.mp4")
val outFile = File(getExternalFilesDir(null)?.absolutePath , "result.mp4")
val command = arrayOf("ffmpeg","-i", inFile.absolutePath ,"-y","-filter:v", "crop=100:100:0:0", outFile.absolutePath)