phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.35k stars 1.43k forks source link

Streaming latency at high FPS. #313

Closed ollydev closed 4 years ago

ollydev commented 5 years ago

Hi, I recently updated jsmpeg-vnc to use the latest jsmpeg but have found increasing steaming latency the higher fps & bitrate. This also occurred in the jsmpeg used in jsmpeg-vnc 0.2 however was improved in later commits but seems to be a problem again since the rewrite.


Using the last commit before the rewrite

test

I think it drops frames to keep up with the socket input here? Would it be possible to get this option added?


Using jsmpeg in jsmpeg-vnc 0.2. The same also happens when using latest jsmpeg:

test

ollydev commented 5 years ago

For anyone curious, here's encoder.c that outputs a valid video stream for the latest jsmpeg!

https://pastebin.com/kkdwX5zt https://pastebin.com/MUavLJ05

HenkHull commented 5 years ago

Wow fantastic thanks! Anyway you can post the whole source code as a zip?

industriousonesoft commented 4 years ago

@ollydev Wow, Can you post the source code to us?

ollydev commented 4 years ago

The fix and what older jsmpeg-vnc was something like this in socket.onmessage.

if (!this.currentPictureDecoded) {
    this.video.decode(true); // Skip drawing. Only decode.
} else {    
    this.currentPictureDecoded = false;
    setTimeout(function(){
        this.video.decode(false); // Decode and draw.
        this.currentPictureDecoded = true;
    }.bind(this));
}

I've been reworking jsmpeg-vnc for Linux here It's now in a working state with a lot of new features.

However, I haven't ran into this issue so far on my fork and the latency may return when I add Windows support.

I'm closing this for now, if I run into the issue again I will make a PR with the fix (and another minor changes I've made here)