0

I'm trying to combine two .flv video files together into one, but even though the output file's size is exactly the sum of the two videos I am trying to combine -1, when I try to play the new video file it plays the first file. I'm sure it has to do with an end flag being set after the first video has been read into the output stream but I'm not exactly sure how to fix this and remove it so that the video plays all the way through. I made sure both files were exactly the same encoding wise as I had just recorded some full screen color's from obs as my test videos. Anyways how would I go about fixing this?

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());
        }
    }
}
  • 1
    why are you so sure that just low-level appending two video files would produce one? – Chisko Jun 10 '18 at 20:50
  • How did you "make sure both files were exactly the same encoding wise"? Did you remove the flv header in the second file? Did you remove the aac/avc sequence headers (assuming avc/aac codecs). did you rewrite time stamps? How are you sure there is an "end flag"? – szatmary Jun 11 '18 at 03:45
  • I had recorded both videos as a simple OBS output of a 1920 by 1080 full screen color. The encoding type is set through OBS and nothing would've changed from the first file to the second. I didn't do anything special to the files, as I'm not that experienced with video file formats. Based on the output file being the sum of the two file sizes -1 but playing only the first clip, I assumed it had to do with a byte somewhere that represents the end of the file – Blank Smash Jun 11 '18 at 21:14

0 Answers0