당신은 내가 첫 번째로 할 것, 두 가지 방법으로 그것을 달성 할 수
놓습니다는 FFmpeg 파일을 사용하면 원시 폴더에.
당신은 명령을 사용하여는 FFmpeg 실행 파일을 사용해야하지만,이 코드 파일 시스템 폴더에 파일을 배치해야하고 파일의 권한을 변경, 이렇게 사용합니다 :
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);
}
}
을 이 방법을 호출하십시오 :
private void installFfmpeg() {
File ffmpegFile = new File(getCacheDir(), "ffmpeg");
String 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 installed");
}
ffmpegFile.setExecutable(true);
}
그런 다음 ffmpeg 파일을 명령에서 사용할 준비가됩니다. (이 방법은 저에게는 효과적이지만 작동하지 않는다고 말하는 사람들이 있습니다. 왜 그런지 모르겠지만 당신의 경우가 아니길 바랍니다.) 나는 당신이 인터넷에서 검색하고 다음 사용할 명령을 선택해야하므로 명령으로는 FFmpeg 파일을 사용할 필요가 말했듯이
String command = "data/data/YOUR_PACKAGE/cache/ffmpeg" + THE_REST_OF_YOUR_COMMAND;
try {
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
Log.d(TAG, "Process finished");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
이 추가 : 다음, 우리는이 코드로는 FFmpeg를 사용 명령 문자열에 넣습니다. 명령이 실패하면 로그에 의해 경고되지 않으므로 터미널 에뮬레이터로 명령을 시도하고 올바르게 작동하는지 확인해야합니다. 작동하지 않으면 결과가 표시되지 않습니다.
희망 하시길 바랍니다.
[link] (http://stackoverflow.com/a/20991431/3098658) – BlueSword