videojs / mux.js

Lightweight utilities for inspecting and manipulating video container formats.
Apache License 2.0
1.08k stars 211 forks source link

No way to change the duration when use transmuxer to generate mp4 #210

Open shellvon opened 5 years ago

shellvon commented 5 years ago

When I try to generate the mp4 file by use mux.js, I got wrong duration time in generated mp4 file, the result time is aways 0xffffffff => 13:15:24。 It's a default value: https://github.com/videojs/mux.js/blob/55c1d56c27001bc6d50e527db6649edd73e0f69c/lib/mp4/mp4-generator.js#L613

How to calculate the correct duration according the MPEG2-TS packets by use mux.js? Or How I change the correct duration before call the method mp4.initSegment(this.pendingTracks); in lib/mp4/transmuxer.js#L835-L842 or earlier

i added an event listener with some code like this:

transmuxer.on('data', (event) => {
    if (!remuxedInitSegment) {
      remuxedInitSegment = event.initSegment;
      // I also want to change the duration time by use remuxedInitSegment.set([xxxx], index)
      // But i don't know how to find the right index....   :'(
    }
})
gesinger commented 5 years ago

Hey @shellvon , thanks for submitting the issue. Right now the duration value for fragmented mp4s should be ignored by the browsers, which is why we haven't added it. We'll take another look at the spec though to see if we'll run into any trouble by setting it (and if it might be a good idea).

If you just want to calculate the duration outside of the normal transmuxer flow, you should be able to use inspect https://github.com/videojs/mux.js/blob/master/lib/tools/ts-inspector.js#L490 to grab start and end values of a segment.

shellvon commented 5 years ago

@gesinger Thanks for your reply. inspect is a good choice to calculate the duration. I also know the correct duration according to the m3u8 file (parsed by m3u8-parser). but i have not way to change the correct duration to the tracks data until generate the mp4 file. Is there any API for this purpose ?

gesinger commented 5 years ago

Sorry for the delay, there is not an API for this right now @shellvon .

shellvon commented 5 years ago

All right ,thank you all the same, @gesinger. Is there any discussion result now? I am still waiting for your good news.

Momo707577045 commented 3 years ago

I had fixed this problem by adding an muxjs.mp4.Transmuxer option 「duration」,can specify mp4 duration。 read PR https://github.com/videojs/mux.js/pull/354 for more detail the fixed result you can see my fork https://github.com/Momo707577045/mux.js

EternityForest commented 2 years ago

I believe that this is actually really important, because Chrome seems to use the duration as a heuristic to determine whether to enable low latency mode in MSE.

HereOrCode commented 3 months ago

Any updates?