phoboslab / jsmpeg

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

Reverse video playback #120

Open faljse opened 7 years ago

faljse commented 7 years ago

I´d like to know how reverse playback could be achieved. Is there a way to "undo" a P-Frame calculation, or is a second (reverse) mpeg file a possible solution?

Not sure about the exact use case yet :) but it would make some accelerometer control experiments possible.

PS: Awesome work. I´m using jsmpeg for an e-learning/robotics platform for low latency live streaming where it does a great job.

andyearnshaw commented 7 years ago

You could reverse a P-frame calculation, but you couldn't do the same for an intra frame. Normal playback goes (assuming only I/P frames): I > P¹ > P² > Pⁿ > I > P¹ > P² > Pⁿ. In reverse, once you get to an I-frame, you'd have to jump to the previous I-frame, decode all the P-frames up to the one that leads to the current frame and then start working backwards again.

That's potentially a lot of processing (depending on compression) to squeeze into ~40ms. That's why video players generally just jump between I-frames when the user is rewinding.