Android - 连接两个视频

 陈雅洁惠真慧瑋 发布于 2023-02-13 14:26

我正在尝试在Android上连接两个视频.我已经在使用ffmpeg来满足其他需求,但我使用的是halfninja的一个,只有0.9.0.9版本不允许以下方式执行此操作:

// 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 demuxer ,ffmpeg 0.9也无法识别.

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

1 个回答
  • 嗯,找到的唯一解决方案是使用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",
                "-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();
    }

    2023-02-13 14:27 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有