附加一个.flv视频文件与另一个.flv视频文件

时间:2018-06-10 20:10:06

标签: java file video flv bytestream

我试图将两个.flv视频文件合并为一个,但即使输出文件的大小恰好是我想要合并的两个视频的总和-1,当我尝试播放新视频文件时播放第一个文件。我确定在将第一个视频读入输出流后设置了结束标记但我不确定如何解决此问题并将其删除以便视频播放全部通过。我确保两个文件的编码方式完全相同,因为我刚刚从obs录制了一些全屏颜色作为我的测试视频。无论如何我该如何解决这个问题?

package testing.space;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class TestingSpace
{

    public static void main(String args[])
    {

        final int BUFFERSIZE = 8192;
        String introFilePath = "C:\\ExampleFile1Path\\vid1.flv";
        String vodFilePath = "C:\\ExampleFile2Path\\vid2.flv";
        String outputFilePath = "C:\\ExampleOutputPath\\output.flv";

        try (
                FileInputStream intro = new FileInputStream(new File(introFilePath));
                FileInputStream vod = new FileInputStream(new File(vodFilePath));
                FileOutputStream fout = new FileOutputStream(new File(outputFilePath));
            )
        {

            byte[] introBuffer = new byte[BUFFERSIZE];
            int introBytesRead;

            while ((introBytesRead = intro.read(introBuffer)) > 0)
            {
                fout.write(introBuffer, 0, introBytesRead);
            }

            byte[] vodBuffer = new byte[BUFFERSIZE];
            int vodBytesRead;

            while ((vodBytesRead = vod.read(vodBuffer)) > 0)
            {
                fout.write(vodBuffer, 0, vodBytesRead);
            }

        }
        catch (Exception e)
        {
            System.out.println("Something went wrong! Reason: " + e.getMessage());
        }
    }
}

0 个答案:

没有答案