0

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...

2
  • Does ffmpeg execute? Add -report option to ffmpeg command. Look for log file. If there is no log file then ffmpeg did not execute and the problem is elsewhere. Commented Jun 22, 2020 at 17:34
  • I fixed the problem check my answer Commented Jun 22, 2020 at 18:48

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.