Android ffmpeg 命令未执行

标签 android ffmpeg android-ffmpeg video-editing

我正在使用 this FFMPEG 库,
首先,我在 videoView 中播放视频以确保视频路径正确

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")
    }
  })
}
但是我上面的代码从开始到错误然后结束,它没有显示任何错误消息,这使得很难知道实际出了什么问题:(我尝试按照这些教程 tutorial1 tutorial2 link 以不同的方式编写我的命令
请帮忙,提前谢谢你...

最佳答案

好吧,经过一番挖掘,结果发现我应该给 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)

关于Android ffmpeg 命令未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62503367/

相关文章:

Android httpUrlConnection发送和接收数据

PHP/ffmpeg (Windows 7) : - Permission Denied. 什么都试过了,还是不行

ios - 在带有 10.9 的 xCode 6.1 Mac 上安装 ffmpeg ios 库 armv7、armv7s、i386 和通用

ffmpeg - 有没有办法使用 FFMpeg 识别音频是 VBR 还是 CBR?

android - 通过 GCM 向 Android/IOS 推送静默通知

android - Galaxy Mega 与其他 Phablets 和 Android Manifest

android - Java Eclipse 自动构建工作区不会停止?

linux - 如何使用 ffmpeg 将任何视频合并到我的介绍中

FFmpeg : Overlay GIF Rotation and scale

android - FFmpeg 错误输出文件 #0 不包含任何流