user29356 / mp4parser

Automatically exported from code.google.com/p/mp4parser
0 stars 0 forks source link

Problem with file appending for very big files #97

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Get a sample file. I used Bick Buck Bunny 
(https://peach.blender.org/download/) for this example.

2. Append the file to itself to get a very long file using AppendTrack. Here is 
an example of the code I used.

    private static void append() throws IOException {

        String inputFile = "C:/tmp/big_buck_bunny_720p_nosound.mp4"; // The bick buck bunny video is 9m56s...
        int timesToAppend = 50; // So let's say.. 50 times to have a ~8hours video ?
        List<Track> tracksToAppend =  new ArrayList<Track>(timesToAppend);
        Movie resultMovie = new Movie();

        for(int i=0; i<timesToAppend; i++) {
            // We only consider the video in this example
            tracksToAppend.add(MovieCreator.build(inputFile).getTracks().get(0));
        }

        Track[] tracksAsArray = new Track[tracksToAppend.size()];

        resultMovie.addTrack(new AppendTrack(tracksToAppend.toArray(tracksAsArray)));
        Container out = new DefaultMp4Builder().build(resultMovie);

        FileOutputStream fos = new FileOutputStream(new File(String.format("C:/tmp/big_buck_bunny_appended.mp4")));
        out.writeContainer(fos.getChannel());
        fos.close();                
    }

3. Play the result file with VLC or ffplay

What is the expected output? What do you see instead?

The expected file is an about 8 hours long video fully playable. Instead the 
content is at first playable and then refuses to play with the following error :
h264 @ 00000000003a0280] no frame!
h264 @ 0000000007170ee0] AVC: nal size -1601875860

If I restrict to a ~1hour video (timesToAppend = 50) however it plays fine.

What version of the product are you using? On what operating system?

Tested with the 1.0-RC37 with the following correction to the AppendTrack (pb 
on sample duration).

public synchronized long[] getSampleDurations() {
    int numSamples = 0;
    for (Track track : tracks) {
        numSamples += track.getSampleDurations().length;
    }
    long[] decodingTimes = new long[numSamples];
    int index = 0;
    // should use system arraycopy but this works too (yes it's slow ...)
    for (Track track : tracks) {
        for (long l : track.getSampleDurations()) {
            decodingTimes[index] = l;
            index++;
        }
    }   
    return decodingTimes;
}

Tested with the 1.0.6. The result is not playable at all (incoherent file 
descriptor).

Platform is a windows 7 x64 with java 8.

Please provide any additional information below.

Original issue reported on code.google.com by bonnet.n...@gmail.com on 4 Jun 2015 at 8:42