如何在Java的新视频文件中串联/合并两个视频? [英] How to concatenate/merge two videos in a new video file in Java?

查看:75
本文介绍了如何在Java的新视频文件中串联/合并两个视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用不起眼的视频我现在要合并两个视频,第一个是录制的视频,第二个是在我的系统上具有相同帧速率和分辨率的预存储视频.由于限制,我想通过在Java中使用不起眼的视频 apis 来做到这一点.如果有人使用过它,请指导我如何做.

I Now want to combine two videos first is the recorded video and second is the pre-stored video of same frame-rate and resolution on my system. Due to limitation, I want to do this by using humble-video apis in java. If anyone have used it please guide me how to do it.

这是我尝试过的代码:

  public static void combineVideo() throws InterruptedException, IOException {
    final Demuxer demuxer = Demuxer.make();
    demuxer.open("a.mp4", null, false, true, null, null);
    final Muxer muxer = Muxer.make("b.mp4", null, null);
    final MuxerFormat format = muxer.getFormat();
    final MediaPacket packet = MediaPacket.make();
    muxer.open(null, null);
    while (demuxer.read(packet) >= 0) {
        muxer.write(packet, false);
    }
    muxer.close();
    demuxer.close();
}

更新

我要串联两个视频文件并另存为新的视频文件.我知道以前的问题例如-

I want to concatenate two video files and save as a new Video File. I know this had been asked in the previous questions e.g-

  1. how-to-concat在Android中合并两个或多个视频文件
  2. merge-multiple-video-file-in-a-文件

但是大多数答案都链接到不可用的资源或库.谁能指导我一些资源.任何代码段都可能会有所帮助.

But most of the answer links to the resources or libraries which are not available. Can anyone guide me to some resources. Any code snippet may be helpful.

推荐答案

大多数编解码器也不支持串联-它将无法帮助您将比特流串联在一起.

Most codecs also do not support concatenation - it will not help you to concatenate the bitstreams together.

但是,如果您确定编解码器具有相同的属性,则某些容器格式支持串联.MPEG-TS就是其中之一.您可以将视频复制到传输流中,而无需重新编码,然后使用常规文件操作将传输流连接起来.

However, if you're sure that the codecs have the same properties, then some container formats support concatenation. MPEG-TS is one of these. You could copy the video into a Transport Stream without re-encoding, and then concatenate the transport streams using normal file operations.

这篇关于如何在Java的新视频文件中串联/合并两个视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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