Extracting Frames from an HTMLVideoElement

Refresh

March 2019

Views

128 time

1

So here's my JavaScript code:

// Convert Frame to Image
Object.defineProperty(HTMLVideoElement.prototype, 'convertFrameToImage', {
    value: function convertFrameToImage() {
        // Create the Image.
        let image = new Image();

        // Create a Canvas to draw the chosen frame.
        let canvas= document.createElement('canvas'),
            canvasContext = metadata.getContext('2d');

        // Draw the frame.
        canvasContext.drawImage(this, 0, 0, this.offset.height, this.offset.width);

        // Modify the Source of the Image to the Canvas's Data URL.
        image.src = canvas.toDataURL();

        // Return the Image.
        return image
    }
})

and with this i was hoping I could create an Image out of a specified frame from an HTMLVideoElement by setting the src of that element to the chosen frame's screen.

I know the code above looks incomplete, but I'm not sure where to go from here.

Any help would be greatly appreciated.

1 answers

2

Вы можете просто определить HTMFooBarElementкласс расширений с HTMLElement:

class HTMLFooBarElement extends HTMLElement {
    connectedCallback () {
        this.innerHTML = "Foo-Bar"
    }
}

Затем расширить HTMLFooBarELementкласс:

class FoobBar extends HTMLFooBarElement

customElements.define( "foo-bar", FooBar )

class HTMLFooBarElement extends HTMLElement {
  connectedCallback() {
    this.innerHTML = "FooBar Element"
  }
};

class FooBar extends HTMLFooBarElement {};

customElements.define("foo-bar", FooBar);
<foo-bar></foo-bar>