Android – 连接两个视频

前端之家收集整理的这篇文章主要介绍了Android – 连接两个视频前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在 Android上连接两个视频.我已经在使用ffmpeg来满足其他需求,但我使用的是 halfninja’s one,只有0.9. 0.9版本不允许以下方式执行此操作:
// filter_complex isn't recognized
vk.run(new String[] {
        "ffmpeg","-i",inputFile1,inputFile2,"-filter_complex","'[0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a]'","-map","'[v]'","'[a]'",outputFile
});

// Or,after converting the two videos to ts,trying to merge them: concat:file1.ts|file2.ts: No such file or directory
vk.run(new String[] {
        "ffmpeg","'concat:" + ts1 + "|" + ts2 + "'","-vcodec","copy","-acodec","-absf","aac_adtstoasc",output
});

我尝试的第三件事是使用here解释的concat demuxer,ffmpeg 0.9也无法识别.

有没有办法在Android上用ffmpeg 0.9(或其他库)连接两个视频?

解决方法

嗯,找到的唯一解决方案是使用ffmpeg≥1.1.我编译了2.1,它工作得很好.这是我现在使用的:
/**
 * Concatenates two videos
 * @param inputFile1 First video file path
 * @param inputFile2 Second video file path
 * @param outputFile Output file path
 */
public static void concatenate(String inputFile1,String inputFile2,String outputFile) {
    Log.d(TAG,"Concatenating " + inputFile1 + " and " + inputFile2 + " to " + outputFile);
    String list = generateList(new String[] {inputFile1,inputFile2});
    Videokit vk = Videokit.getInstance();
    vk.run(new String[] {
            "ffmpeg","-f","concat",list,"-c",outputFile
    });
}

/**
 * Generate an ffmpeg file list
 * @param inputs Input files for ffmpeg
 * @return File path
 */
private static String generateList(String[] inputs) {
    File list;
    Writer writer = null;
    try {
        list = File.createTempFile("ffmpeg-list",".txt");
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
        for (String input: inputs) {
            writer.write("file '" + input + "'\n");
            Log.d(TAG,"Writing to list file: file '" + input + "'");
        }
    } catch (IOException e) {
        e.printStackTrace();
        return "/";
    } finally {
        try {
            if (writer != null)
                writer.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    Log.d(TAG,"Wrote list file to " + list.getAbsolutePath());
    return list.getAbsolutePath();
}

猜你在找的Android相关文章