Broadway icon indicating copy to clipboard operation
Broadway copied to clipboard

play in reverse or seek to a frame?

Open hapticdata opened this issue 10 years ago • 4 comments

Hello,

I have the following function to render a frame, based off of the MP4Player

function renderFrame(){
        var video = this.reader.tracks[1];
        var units = video.getSampleNALUnits(this.currentSample);

        for( var i=0; i<units.length; i++){
            var nal = units[i];
            this.avc.decode(nal); // avc is a Player
        }
}

Everything works as expected when currentSample increases, but I would like to be able to play the video in reverse as well as jump to a specific frame. When currentSample decreases the video frags-up and is incoherent.

How can I go about playing the video in reverse? Or rendering a single frame?

hapticdata avatar Oct 21 '15 17:10 hapticdata

a straight forward way would be to decode all frames and keep them in memory. but that could use a lot of memory.

the 5th byte of the nal unit gives you the type of nal. look for the closest iframe type before the position you are seeking. in theory you should be able to decode the 1st and 2nd nal unit of your stream and then continue with the iframe nal.

soliton4 avatar Oct 21 '15 17:10 soliton4

thanks for your helpful response. Currently I've taken the approach of decoding all frames to image data in memory.

The other method you described sounds interesting but currently a little over my head. I do still wish I knew how to seek through at runtime. Is there any information you can point me towards to better understand NAL units and their types?

thanks again!

hapticdata avatar Oct 26 '15 19:10 hapticdata

here is a useful overview: http://stackoverflow.com/questions/24884827/possible-locations-for-sequence-picture-parameter-sets-for-h-264-stream

iframes are idr i believe but i am no expert myself you gotta try it out

soliton4 avatar Oct 26 '15 19:10 soliton4

@hapticdata did you manage to seek?

philipbulley avatar Nov 23 '15 10:11 philipbulley