Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将多个视频文件合并到一个文件中_Java_Android_Video - Fatal编程技术网

Java 将多个视频文件合并到一个文件中

Java 将多个视频文件合并到一个文件中,java,android,video,Java,Android,Video,我用相同的帧速率和分辨率录制了多个视频。我想将两个视频合并为一个视频,这样结果文件将是大视频。 我正在使用MP4解析器api并使用以下代码- Movie countVideo = new MovieCreator().build(Channels.newChannel(MuxExample.class.getResourceAsStream("/count-video.mp4"))); Movie countAudioDeutsch = new MovieCreator().build(Chan

我用相同的帧速率和分辨率录制了多个视频。我想将两个视频合并为一个视频,这样结果文件将是大视频。 我正在使用MP4解析器api并使用以下代码-

Movie countVideo = new MovieCreator().build(Channels.newChannel(MuxExample.class.getResourceAsStream("/count-video.mp4")));
Movie countAudioDeutsch = new MovieCreator().build(Channels.newChannel(MuxExample.class.getResourceAsStream("/count-deutsch-audio.mp4")));
Movie countAudioEnglish = new MovieCreator().build(Channels.newChannel(MuxExample.class.getResourceAsStream("/count-english-audio.mp4")));
并使用jar-isoviewer-1.0-RC-35.jar。但它给出了一个错误-

Movie countVideo = new MovieCreator().build(Channels.newChannel(MuxExample.class.getResourceAsStream("/count-video.mp4")));
at build method。它表示MovieCreator类型中的方法build(字符串)不适用于参数(FileChannel)

jar有什么问题吗?那么我要用哪个jar呢。 或者任何其他的方法。 请帮我解决这一点。

试试这个:

我用了两个视频文件

 public static void main(String[] args)
  {

    String filenamevideo = "f:/testvidfol/video.mp4"; //video file on your disk
    String filenameaudio = "f:/testvidfol/audio.wav"; //audio file on your disk


    IMediaWriter mWriter = ToolFactory.makeWriter("f:/testvidfol/videowriter.flv"); //output file

    IContainer containerVideo = IContainer.make();
    IContainer containerAudio = IContainer.make();

    if (containerVideo.open(filenamevideo, IContainer.Type.READ, null) < 0)
        throw new IllegalArgumentException("Cant find " + filenamevideo);

    if (containerAudio.open(filenameaudio, IContainer.Type.READ, null) < 0)
        throw new IllegalArgumentException("Cant find " + filenameaudio);

    int numStreamVideo = containerVideo.getNumStreams();
    int numStreamAudio = containerAudio.getNumStreams();

    System.out.println("Number of video streams: "+numStreamVideo + "\n" + "Number of audio streams: "+numStreamAudio );

int videostreamt = -1; //this is the video stream id
int audiostreamt = -1;

IStreamCoder  videocoder = null;

    for(int i=0; i<numStreamVideo; i++){
        IStream stream = containerVideo.getStream(i);
        IStreamCoder code = stream.getStreamCoder();

        if(code.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO)
        {
            videostreamt = i;
            videocoder = code;
            break;
        }

    }

    for(int i=0; i<numStreamAudio; i++){
        IStream stream = containerAudio.getStream(i);
        IStreamCoder code = stream.getStreamCoder();

        if(code.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO)
        {
            audiostreamt = i;
            break;
        }

    }

    if (videostreamt == -1) throw new RuntimeException("No video steam found");
    if (audiostreamt == -1) throw new RuntimeException("No audio steam found");

    if(videocoder.open()<0 ) throw new RuntimeException("Cant open video coder");
    IPacket packetvideo = IPacket.make();

    IStreamCoder audioCoder = containerAudio.getStream(audiostreamt).getStreamCoder();

    if(audioCoder.open()<0 ) throw new RuntimeException("Cant open audio coder");
    mWriter.addAudioStream(0, 0, audioCoder.getChannels(), audioCoder.getSampleRate());

    mWriter.addVideoStream(1, 1, videocoder.getWidth(), videocoder.getHeight());

    IPacket packetaudio = IPacket.make();

    while(containerVideo.readNextPacket(packetvideo) >= 0 ||
            containerAudio.readNextPacket(packetaudio) >= 0){

        if(packetvideo.getStreamIndex() == videostreamt){

            //video packet
            IVideoPicture picture = IVideoPicture.make(videocoder.getPixelType(),
                    videocoder.getWidth(),
                    videocoder.getHeight());
            int offset = 0;
            while (offset < packetvideo.getSize()){
                int bytesDecoded = videocoder.decodeVideo(picture, 
                        packetvideo, 
                        offset);
                if(bytesDecoded < 0) throw new RuntimeException("bytesDecoded not working");
                offset += bytesDecoded;

                if(picture.isComplete()){
                    System.out.println(picture.getPixelType());
                    mWriter.encodeVideo(1, picture);

                }
            }
        } 

        if(packetaudio.getStreamIndex() == audiostreamt){   
        //audio packet

            IAudioSamples samples = IAudioSamples.make(512, 
                    audioCoder.getChannels(),
                    IAudioSamples.Format.FMT_S32);  
            int offset = 0;
            while(offset<packetaudio.getSize())
            {
                int bytesDecodedaudio = audioCoder.decodeAudio(samples, 
                        packetaudio,
                        offset);
                if (bytesDecodedaudio < 0)
                    throw new RuntimeException("could not detect audio");
                offset += bytesDecodedaudio;

                if (samples.isComplete()){
                     mWriter.encodeAudio(0, samples);

        }
            }

    }

  }
}
publicstaticvoidmain(字符串[]args)
{
String filenamevideo=“f:/testvidfol/video.mp4”;//磁盘上的视频文件
String filenameaudo=“f:/testvidfol/audio.wav”;//磁盘上的音频文件
IMediaWriter mWriter=ToolFactory.makeWriter(“f:/testvidfol/videowriter.flv”);//输出文件
IContainer containerVideo=IContainer.make();
IContainer容器audio=IContainer.make();
if(containerVideo.open(filenamevideo,IContainer.Type.READ,null)<0)
抛出新的IllegalArgumentException(“找不到”+filenamevideo);
if(containerAudio.open(filenameaudio,IContainer.Type.READ,null)<0)
抛出新的IllegalArgumentException(“找不到”+filenameaudio);
int numStreamVideo=containerVideo.getNumStreams();
int numStreamAudio=containerAudio.getNumStreams();
System.out.println(“视频流的数量:+numStreamVideo+”\n“+”音频流的数量:+numstreamudio);
int videostreamt=-1;//这是视频流id
int audiostreamt=-1;
IStreamCoder videocoder=null;
对于(inti=0;i,build()方法使用String,因为它接受文件路径,如

Movie countVideo = new MovieCreator().build(Channels.newChannel("c:/video/count-video.mp4"));

谢谢你的回答。我必须为它添加哪个jar。你能提供它的下载链接吗。它也在同一个类下
com.xuggle.xuggler.ICodec.class
在-IMediaWriter mWriter=ToolFactory.makeWriter(path+“videowriter.flv”);//输出文件行运行代码时发现一些错误。请检查我编辑的问题是什么代码中的“ICodec.Type.CODEC\u Type\u VIDEO”并对其进行赋值?IAudioSamples samples=IAudioSamples.make(512,audioCoder.getChannels(),IAudioSamples.Format.FMT\u S32);方法仅生成2个参数,但您有3个参数。因此它出错请同时检查此链接-您的问题是否已解决?