我浏览了许多网站并搜索有关“ FFMPEG ”的 android 项目实现。
建立的大多数解决方案都使用 NDK。
但我想使用 不使用 NDK 的 FFmpeg 正如我在 中发现的那样This Link
最佳答案
我用过这个项目
https://github.com/guardianproject/android-ffmpeg-java
它已经为 FFMPEG 库的 android 版本编译,这个文件将在 res/raw 文件夹中(如果你需要更新版本,你可以更新这个文件)。您需要将此项目作为库添加到您的项目中。之后,您可以在 java 中编写自己的函数,例如:
public Clip convert (Clip mediaIn, String outPath, ShellCallback sc) throws Exception
{
ArrayList<String> cmd = new ArrayList<String>();
cmd.add(mFfmpegBin);
cmd.add("-y");
cmd.add("-i");
cmd.add(new File(mediaIn.path).getCanonicalPath());
if (mediaIn.startTime != null)
{
cmd.add("-ss");
cmd.add(mediaIn.startTime);
}
if (mediaIn.duration != -1)
{
cmd.add("-t");
cmd.add(String.format(Locale.US,"%f",mediaIn.duration));
}
Clip mediaOut = new Clip();
File fileOut = new File(outPath);
mediaOut.path = fileOut.getCanonicalPath();
cmd.add(mediaOut.path);
execFFMPEG(cmd, sc);
return mediaOut;
}
并使用 FfmpegController 对象执行它。
如果您有任何问题或者这是您想要的,请通知我。
编辑:
我希望您将此 github 代码连接为您项目的库。
有FfmpegController.java src 文件夹中的类。它是使用命令行 ffmpeg exe 文件的包装器。如果你想例如执行这样的命令
ffmpeg -i source.wav -b:a 128k output.mp3
您需要向 FfmpegController.java 类添加函数。像这样的东西:
public Clip convert(Clip mediaIn, String outPath, ShellCallback sc) throws Exception
{
ArrayList<String> cmd = new ArrayList<String>();
Clip mediaOut = new Clip();
String mediaPath = mediaIn.path;
cmd = new ArrayList<String>();
cmd.add(mFfmpegBin);
cmd.add("-i");
cmd.add(mediaPath);
cmd.add("-b:a");
cmd.add("128k");
mediaOut.path = outPath;
cmd.add(mediaOut.path);
execFFMPEG(cmd, sc);
return mediaOut; // this is not importatnt because file will be put in outPath
}
现在在您的项目中初始化 FfmpegController 对象并运行您的函数。
关于android - 在android中使用没有NDK的FFmpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29166919/