编辑:我知道可能重复,但答案不能直接适用。我正在使用ProcessBuilder而不是Runtime.getRuntime()。exec:
public int execProcess(List<String> cmds, ShellUtils.ShellCallback sc) {
StringBuilder cmdlog = new StringBuilder();
for (String cmd : cmds) {
cmdlog.append(' ');
}
Utils.logger("v", cmdlog.toString(), DEBUG_TAG);
ProcessBuilder pb = new ProcessBuilder();
pb.directory(mBinFileDir);
pb.command(cmds);
Process process = null;
int exitVal = 1; // Default error
try {
process = pb.start();
StreamGobbler errorGobbler = new
StreamGobbler(process.getErrorStream(), "ERROR", sc);
StreamGobbler outputGobbler = new
StreamGobbler(process.getInputStream(), "OUTPUT", sc);
errorGobbler.start();
outputGobbler.start();
exitVal = process.waitFor();
sc.processComplete(exitVal);
} catch (Exception e) {
Log.e(DEBUG_TAG, "Error executing ffmpeg command!", e);
} finally {
if (process != null) {
Utils.logger("w", "destroyng process", DEBUG_TAG);
process.destroy();
}
}
return exitVal;
}
我在为android编译的FFmpeg上有两个版本:启用和不启用liblame
。
当我加载/data/data/<<my-package-name>>/app_bin/
编译时没有蹩脚支持的FFmpeg二进制文件时,它会从视频中提取音频而不会出现问题。但是当我使用启用了跛脚支持的那个时,我会将下面的错误记录到日志中。
在运送到libs
项目文件夹System.loadLibrary("lame")
时,也为Android编译的必需库已正确加载。
我想知道是否还有其他事可做,以便正确使FFmpeg二进制文件找到libs。 这些是为NDK提供的用于构建FFmpeg二进制文件的库。
D/dalvikvm(13741): Trying to load lib /data/app-lib/<<my-package-name>>/liblame.so 0x40ffed08
D/dalvikvm(13741): Added shared lib /data/app-lib/<<my-package-name>>/liblame.so 0x40ffed08
D/dalvikvm(13741): No JNI_OnLoad found in /data/app-lib/<<my-package-name>>/liblame.so 0x40ffed08, skipping init
D/FfmpegController(13741): Trying to chmod '/data/data/<<my-package-name>>/app_bin/ffmpeg' to: 755
V/FfmpegController(13741): /data/data/<<my-package-name>>/app_bin/ffmpeg -y -i /storage/sdcard0/Download/video.webm -vn -acodec copy /storage/sdcard0/Download/audio.ogg
>>>>>> ---------- <<<<<<
D/DownloadsService(13741): soinfo_link_image(linker.cpp:1673): could not load library "liblame.so" needed by "/data/data/<<my-package-name>>/app_bin/ffmpeg"; caused by load_library(linker.cpp:771): library "liblame.so" not foundCANNOT LINK EXECUTABLE
>>>>>> ---------- <<<<<<
I/DownloadsService(13741): FFmpeg process exit value: 255
我没有附加代码,因为它相当简单:
/data/data/<<my-package-name>>/app_bin/
; 如果需要其他内容,请发表评论。
答案 0 :(得分:2)
有趣的是我最近找到了所有的答案......无论如何,因为如果你想要的话,那对其他人有用:
liblame.so
System.loadLibrary("lame")
文件夹libs
ProcessBuilder
<强>做强>:
1)
ProcessBuilder pb = new ProcessBuilder("liblame.so");
Map<String, String> envMap = pb.environment();
envMap.put("LD_LIBRARY_PATH", "/data/app-lib/<<my-pkg-name>>/");
或者更好的是,避免在包名称后面处理“-1”或“-2”后缀(更改):
2)
ProcessBuilder pb = new ProcessBuilder();
Map<String, String> envMap = pb.environment();
envMap.put("LD_LIBRARY_PATH", "/data/data/<<my-pkg-name>>/lib");
并且没有硬编码/data/data/<<my-pkg-name>>/lib
使用:Context.getApplicationInfo().nativeLibraryDir
使用此解决方案2)我发现System.loadLibrary("lame")
需要。