mux.js icon indicating copy to clipboard operation
mux.js copied to clipboard

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

Open shellvon opened this issue 5 years ago • 7 comments

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....   :'(
    }
})

shellvon avatar Aug 08 '18 04:08 shellvon

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.

gesinger avatar Aug 08 '18 20:08 gesinger

@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 ?

shellvon avatar Aug 09 '18 01:08 shellvon

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

gesinger avatar Nov 02 '18 19:11 gesinger

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

shellvon avatar Nov 12 '18 02:11 shellvon

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

Momo707577045 avatar Oct 13 '20 11:10 Momo707577045

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.

EternityForest avatar Feb 08 '22 14:02 EternityForest

Any updates?

HereOrCode avatar Mar 21 '24 00:03 HereOrCode