Android的 - 连接两个视频 [英] Android - concatenate two videos

查看:167
本文介绍了Android的 - 连接两个视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图来连接在Android两个视频。我已经使用了其他需要的ffmpeg,但我使用 halfninja的之一,这只有0.9。 0.9一个不容许通过以下方式来做到这一点:

I'm trying to concatenate two videos on Android. I'm already using ffmpeg for other needs, but I'm using halfninja's one, which is only 0.9. The 0.9 one doesn't allow the following ways to do it:

// filter_complex isn't recognized
vk.run(new String[] {
        "ffmpeg",
        "-i",
        inputFile1,
        "-i",
        inputFile2,
        "-filter_complex",
        "'[0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a]'",
        "-map",
        "'[v]'",
        "-map",
        "'[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",
        "-i",
        "'concat:" + ts1 + "|" + ts2 + "'",
        "-vcodec",
        "copy",
        "-acodec",
        "copy",
        "-absf",
        "aac_adtstoasc",
        output
});

我试过的第三件事是使用CONCAT分路器解释的这里,这是不符合FFmpeg的0.9要么承认。

The third thing I tried is to use the concat demuxer explained here, which isn't recognized with ffmpeg 0.9 either.

有什么办法来连接Android上的两个视频与ffmpeg的0.9(或其他库)?

Is there any way to concatenate two videos on Android with ffmpeg 0.9 (or another library)?

推荐答案

那么,唯一的解决办法是找到使用的ffmpeg≥1.1。我编译2.1,它的工作就好了。下面是我现在用的:

Well, the only solution found was to use ffmpeg ≥1.1. I compiled the 2.1, it's working just fine. Here's what I use now:

/**
 * 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",
            "-i",
            list,
            "-c",
            "copy",
            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的 - 连接两个视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆