gpt4 book ai didi

android - 在 Android 中使用 FFmpeg 将视频裁剪为正方形格式

转载 作者:行者123 更新时间:2023-11-30 01:04:56 25 4
gpt4 key购买 nike

我目前正在开发一款可以将 16:9 视频裁剪为 1:1 视频的应用。但是我没有让代码工作。如果可能,软件应尽快转换输入的视频。分辨率可以在 480x480 和 720x720 之间变化。

如果我可以选择裁剪框的位置就完美了。

我得到的错误:

E/FFmpeg: Exception while trying to run: [Ljava.lang.String;@f0c91b8
java.io.IOException: Error running exec(). Command: [/data/user/0/com.android.grafika/files/ffmpeg, -i /storage/emulated/0/Alphacrypt1.mp4 -vf crop=640:256:0:400 -threads 5 -preset ultrafast -strict -2 /storage/emulated/0/YourCroppedMovie.mp4] Working Directory: null Environment: null
at java.lang.ProcessManager.exec(ProcessManager.java:215)
at java.lang.Runtime.exec(Runtime.java:174)
at java.lang.Runtime.exec(Runtime.java:129)
at com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10)
at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38)
at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.IOException: No such file or directory
at java.lang.ProcessManager.exec(Native Method)
at java.lang.ProcessManager.exec(ProcessManager.java:213)
at java.lang.Runtime.exec(Runtime.java:174) 
at java.lang.Runtime.exec(Runtime.java:129) 
at com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10) 
at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38) 
at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10) 
at android.os.AsyncTask$2.call(AsyncTask.java:295) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 

我使用的代码:

final String[] cmd = new String[]{"-i /storage/emulated/0/Alphacrypt1.mp4 -vf crop=640:256:0:400 -threads 5 -preset ultrafast -strict -2 /storage/emulated/0/YourCroppedMovie.mp4"};

try {
final FFmpeg ffmpeg = FFmpeg.getInstance(this);
ffmpeg.execute(cmd, new FFmpegExecuteResponseHandler() {
@Override
public void onSuccess(String message) {
Toast.makeText(getApplicationContext(), "Successfully converted!",
Toast.LENGTH_LONG).show();
}

@Override
public void onProgress(String message) {

}

@Override
public void onFailure(String message) {
Toast.makeText(getApplicationContext(), "Fail!"+ message,
Toast.LENGTH_LONG).show();
}

@Override
public void onStart() {
Toast.makeText(getApplicationContext(), "Started!",
Toast.LENGTH_LONG).show();
}

@Override
public void onFinish() {
Toast.makeText(getApplicationContext(), "Stopped!",
Toast.LENGTH_LONG).show();
}
});
} catch (FFmpegCommandAlreadyRunningException e) {

}

感谢您的帮助。

解决方案:

  1. 我没有添加“加载二进制”部分,这是运行FFmpeg 库 ( http://writingminds.github.io/ffmpeg-android-java/ )。
  2. 命令需要使用 .split(""); 进行拆分,printfmyname
  3. 已告知
  4. 现在我使用 -vf crop=1080:1080:0:0 将视频裁剪成正方形。 (不要弄乱比例)

最佳答案

我认为从 Ffmpeg 调用的 exec 命令需要一个所有参数都标记化的字符串数组。尝试改变

final String[] cmd = new String[]{"-i /storage/emulated/0/Alphacrypt1.mp4 -vf crop=640:256:0:400 -threads 5 -preset ultrafast -strict -2 /storage/emulated/0/YourCroppedMovie.mp4"};

final String[] cmd = "-i /storage/emulated/0/Alphacrypt1.mp4 -vf crop=640:256:0:400 -threads 5 -preset ultrafast -strict -2 /storage/emulated/0/YourCroppedMovie.mp4".split(" ");

关于android - 在 Android 中使用 FFmpeg 将视频裁剪为正方形格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38962746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com