samirkumardas / jmuxer

jMuxer - a simple javascript mp4 muxer that works in both browser and node environment.
Other
549 stars 108 forks source link

How to re-fetch PPS and SPS based on the size change dynamically? #47

Closed jithingangadharan closed 3 years ago

jithingangadharan commented 4 years ago

Hello @samirkumardas ,

Thanks for the great library. I am facing some issue in resolution change dynamically. How to re-fetch PPS and SPS based on the size(height X width <==> width X height) change dynamically?

samirkumardas commented 4 years ago

Please check this method https://github.com/samirkumardas/jmuxer/blob/ea877d6ada2106432f835fd3a0ac558df95458f4/src/parsers/h264.js#L249

I do not re-check SPS/PPS once I got it. Anyways, to carry out a simple test, you can try removing the conditional statement in lines 261 and 270. For example, for line 261

You have to remove

if (!this.track.pps) {

and its ending bracket but NOT the lines in between.

samirkumardas commented 3 years ago

Can you try latest build if it fixes the issue?

psande commented 3 years ago

I have the same issue. I will test the latest build @samirkumardas and let you know how it goes in the following weeks.

tzah4748 commented 3 years ago

Same issue, tested the latest build and it does not work for me. I am streaming an Android device, on orientation change there is a new SPS/PPS pair coming through. Once i rotate my screen i see stuttered images.

Also i tried adding the following line in order to reset : Under the ParseNAL function :

case NALU.SPS:
            // Reset track to support changing SPS/PPS
            this.remuxer.readyToDecode = false;
            this.track.sps = null;
            this.track.pps = null;

Sadly the above didn't work as well.

samirkumardas commented 3 years ago

@tzah4748 Can you provide a portion of the h264 so I test. Please try playing in this player https://samirkumardas.github.io/jmuxer/h264_player.html

tzah4748 commented 3 years ago

I've found how to fix this (in my case the SPS NAL U size is 22) Before i feed the new SPS i call jmuxer.remuxController.reset(); and it works.

So in order to support new SPS you basically need to detect NAL U type at the start of your jmuxer.feed function and call this remuxController.reset()

EDIT: Uploading a file for you right now

jmuxer.zip

EDIT 2: The file seems to work in the live h264_player.html link you gave above.

samirkumardas commented 3 years ago

@tzah4748 as it plays fine in h264 player, it might be related to https://github.com/samirkumardas/jmuxer/issues/35#issuecomment-665638671

Regarding SPS/PPS, I will have to refresh it when it finds a new value. Will do when I get some time