Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSE live stream. sourceEnded/ half video green. #405

Open
nikolaiivanov93 opened this issue Dec 2, 2021 · 0 comments
Open

MSE live stream. sourceEnded/ half video green. #405

nikolaiivanov93 opened this issue Dec 2, 2021 · 0 comments

Comments

@nikolaiivanov93
Copy link

nikolaiivanov93 commented Dec 2, 2021

We are trying to show live video. Through the multiplexer, we transform our stream from mpegts in fmp4. We get errors when trying to play a video:

  1. When trying to play the first frame we get sourceEnded
  2. Sometimes source ended not and playing video but half video green

`

    let transmuxer = new muxjs.mp4.Transmuxer();
    mediaSource.addEventListener('sourceopen', function(e) {
                
                video.muted = true;
                video.play();
    
                websocket = new WebSocket('ws://127.0.0.1:3333');
                websocket.binaryType = 'arraybuffer';
    
                websocket.onopen = function() {
                    let resolution = 240;
                    let bin = JSON.stringify({ resolution });
                        
                    function strToAb(str) {
                        return new Uint8Array(str.split('')
                        .map(c => c.charCodeAt(0))).buffer;
                    }
                    appendFirstSegment();
                    websocket.send(strToAb(bin));
                }
    
              websocket.onmessage = function (e) {
                              websocket.send('PING');
              
                              let data = new Uint8Array(e.data);
              
                              dataBuffer.push(data);
              
                              transmuxer.push(dataBuffer.shift());
                              transmuxer.flush();
              
              }
              
              function appendFirstSegment(){
                              
                                  URL.revokeObjectURL(video.src);
                                  
                                  sourceBuffer = mediaSource.addSourceBuffer(mime);
                                  sourceBuffer.addEventListener('updateend', function(e) {
                                      appendNextSegment()
                                      if (video.duration && !video.currentTime) {
                                          video.currentTime = video.duration;
                                      }
                                  });
              
                                  transmuxer.on('data', (segment) => {
                                          let data = new Uint8Array(segment.initSegment.byteLength + segment.data.byteLength);
                                          data.set(segment.initSegment, 0);
                                          data.set(segment.data, segment.initSegment.byteLength);
                                          
                                          createInitSegment = false;
                                          sourceBuffer.appendBuffer(data);
                                  })
              
              
               }
              
              function appendNextSegment(){
                  transmuxer.off('data');
                  transmuxer.on('data', (segment) =>{
                      let data = new Uint8Array(segment.data);
    
                      sourceBuffer.appendBuffer(data);
                  })
              }
    });

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant