在Android中使用FFMPEG进行编码

时间:2011-08-31 15:14:34

标签: android ffmpeg

我成功编译了ffmpeg for Android,但我不知道如何以编程方式将flv或mp4文件转换为mp3,但我需要它。有人可以通过示例或教程帮助我吗?谢谢。

1 个答案:

答案 0 :(得分:1)

有关如何使用ProcessBuilder通过CLI为Android编译的FFmpeg二进制文件的一个很好的示例,请访问:

https://github.com/guardianproject/android-ffmpeg-java/blob/master/src/org/ffmpeg/android/FfmpegController.java

请注意方法:

private int execProcess(String cmd, ShellCallback sc, File fileExec) throws IOException, InterruptedException { 

    ProcessBuilder pb = new ProcessBuilder(cmd);
    pb.directory(fileExec);

    Log.d(TAG,cmd);

    // pb.redirectErrorStream(true);
    Process process = pb.start();


    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(process.getErrorStream(), "ERROR", sc);

    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(process.getInputStream(), "OUTPUT", sc);

    // kick them off
    errorGobbler.start();
    outputGobbler.start();

    int exitVal = process.waitFor();

    sc.processComplete(exitVal);

    return exitVal;
}