本文介绍了FFmpeg的可执行文件模式的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用存储在Android应用程序文件夹生食的可执行文件运行FFmpeg的命令。我得到许可被拒绝的错误,不能够调整视频。我怎样才能从我的Java文件给出正确的权限。
Trying to run FFmpeg command using executable file stored in Raw folder eclipse for android app. I am getting permission denied error and not able to resize video. How can i give right permissions from my java file.
推荐答案
把这个code在静态类或任何你想要的:
put this code in a static class or wherever you want:
public static void installBinaryFromRaw(Context context, int resId, File file) {
final InputStream rawStream = context.getResources().openRawResource(resId);
final OutputStream binStream = getFileOutputStream(file);
if (rawStream != null && binStream != null) {
pipeStreams(rawStream, binStream);
try {
rawStream.close();
binStream.close();
} catch (IOException e) {
Log.e(TAG, "Failed to close streams!", e);
}
doChmod(file, 777);
}
}
public static OutputStream getFileOutputStream(File file) {
try {
return new FileOutputStream(file);
} catch (FileNotFoundException e) {
Log.e(TAG, "File not found attempting to stream file.", e);
}
return null;
}
public static void pipeStreams(InputStream is, OutputStream os) {
byte[] buffer = new byte[IO_BUFFER_SIZE];
int count;
try {
while ((count = is.read(buffer)) > 0) {
os.write(buffer, 0, count);
}
} catch (IOException e) {
Log.e(TAG, "Error writing stream.", e);
}
}
public static void doChmod(File file, int chmodValue) {
final StringBuilder sb = new StringBuilder();
sb.append("chmod");
sb.append(' ');
sb.append(chmodValue);
sb.append(' ');
sb.append(file.getAbsolutePath());
try {
Runtime.getRuntime().exec(sb.toString());
} catch (IOException e) {
Log.e(TAG, "Error performing chmod", e);
}
}
而与此code调用它:
And call it with this code:
private void installFfmpeg() {
File ffmpegFile = new File(getCacheDir(), "ffmpeg");
mFfmpegInstallPath = ffmpegFile.toString();
Log.d(TAG, "ffmpeg install path: " + mFfmpegInstallPath);
if (!ffmpegFile.exists()) {
try {
ffmpegFile.createNewFile();
} catch (IOException e) {
Log.e(TAG, "Failed to create new file!", e);
}
Utils.installBinaryFromRaw(this, R.raw.ffmpeg, ffmpegFile);
}else{
Log.d(TAG, "It was already installed");
}
ffmpegFile.setExecutable(true);
Log.d(TAG, String.valueOf(ffmpegFile.canExecute()));
}
希望吸取信息时!!
Hope it´s useful!!
这篇关于FFmpeg的可执行文件模式的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!