Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ffmpeg命令未执行_Android_Ffmpeg_Android Ffmpeg_Video Editing - Fatal编程技术网

Android ffmpeg命令未执行

Android ffmpeg命令未执行,android,ffmpeg,android-ffmpeg,video-editing,Android,Ffmpeg,Android Ffmpeg,Video Editing,我正在使用FFMPEG库 首先,我在视频视图中播放视频,以确保视频路径正确 videoView.setVideoURI(Uri.parse(getExternalFilesDir(null)?.absolutePath + "videoToBeEdit")) 然后,我调用下面编写的代码来裁剪视频,然后再次将其放入videoView中以查看结果 val ff = FFmpeg.getInstance(this@EditVideoActivity) if (ff.isSuppo

我正在使用FFMPEG库

首先,我在视频视图中播放视频,以确保视频路径正确

videoView.setVideoURI(Uri.parse(getExternalFilesDir(null)?.absolutePath + "videoToBeEdit"))
然后,我调用下面编写的代码来裁剪视频,然后再次将其放入videoView中以查看结果

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")
    }
  })
}
但是我上面的代码从头到尾都是错误的,它没有显示任何错误消息,这让我很难知道到底哪里出了问题:(在这些教程之后,我尝试以不同的方式编写我的命令
请帮助,提前谢谢…

好吧,在仔细研究之后,发现我应该给FFmpeg一个路径和名称,以便为我创建文件并将数据保存在该文件中,我不应该创建文件并给它文件路径,因为FFmpeg将尝试用它试图创建的文件覆盖该文件,默认情况下,FFmpeg没有覆盖它的权限,最后,您还应该添加文件扩展名(我保存文件时没有扩展名)

那么解决方案是什么呢?您可以简单地给出一条路径,指向您希望FFmpeg创建文件的位置,但不需要像这样自己创建文件

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)
或者,您可以创建该文件,然后告诉FFmp3g通过添加

-y

像这样服从命令

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)

是否执行ffmpeg?将
-report
选项添加到ffmpeg命令。查找日志文件。如果没有日志文件,则ffmpeg未执行,问题在别处。我已修复问题,请检查我的答案