gpac / mp4box.js

JavaScript version of GPAC's MP4Box tool
https://gpac.github.io/mp4box.js/
BSD 3-Clause "New" or "Revised" License
1.92k stars 325 forks source link

Quicktime reports mp4 file as having double the time it actually has #347

Open bobbydigitales opened 1 year ago

bobbydigitales commented 1 year ago

Hi!

I'm using the webCodecs API to create an mp4 file.

My encoder config looks like this:

    const config = {
        codec: "avc1.640029",
        width: width,
        height: height,
        framerate: 60,
        bitrate: 10e6,
        // hardwareAcceleration:"prefer-hardware"
    };

I add my video track like this:

 trackID = mp4.addTrack( {
                    timescale: timescale,
                    width: width,
                    height: height,
                    // nb_samples: 60 * duration,
                    media_duration: duration * fps * frameDuration,
                    avcDecoderConfigRecord: config.decoderConfig.description
                } );

And I add samples like this:

  mp4.addSample(trackID, uint8, {
                dts: chunk.timestamp,
                cts: chunk.timestamp,
                duration: frameDuration,
                is_sync: chunk.type === 'key'
            });

I've attached the resulting file which reports as 8 seconds in Quicktime and Safari. I also noticed that the resulting file cannot be uploaded to Twitter (fails to process) and it fails to preview in Slack.

Timestamps and the number of frames look correct when inspecting using https://gpac.github.io/mp4box.js/test/filereader.html

Any help would be appreciated!

https://github.com/gpac/mp4box.js/assets/1421112/11095adc-850c-408c-9bd6-8a398b5a40a5