【问题标题】:Android ffmpeg Command not executingAndroid ffmpeg 命令未执行
【发布时间】:2020-10-11 15:53:00
【问题描述】:

我正在使用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")
    }
  })
}

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

【问题讨论】:

  • ffmpeg 是否执行?在 ffmpeg 命令中添加 -report 选项。查找日志文件。如果没有日志文件,则 ffmpeg 没有执行,问题出在其他地方。
  • 我解决了问题检查我的答案

标签: android ffmpeg android-ffmpeg video-editing


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-04
    • 2015-03-13
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 2013-08-14
    • 2014-11-15
    • 1970-01-01
    相关资源
    最近更新 更多