Skip to content

How to extract a frame from HtmlVideoElement ? #3894

Closed Answered by astariul
astariul asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the answer.

After more research, I could make it work.

The solution is not to use the HtmlVideoElement but the canvas.

So in the JS code, I draw the frame from the HtmlVideoElement into the canvas, and then I retrieve the frame from the canvas. Then I just pass this image to my Rust fucntion:

canvasCtx.drawImage(video, -canvasElement.width, 0, canvasElement.width, canvasElement.height);
const img = canvasCtx.getImageData(0, 0, canvasElement.width, canvasElement.height);
my_fn(img);

The Rust code :

use wasm_bindgen::prelude::*;
use web_sys::{console, ImageData};

#[wasm_bindgen]
pub fn my_fn(frame: ImageData) {
    let pixels = frame.data();
    let size = pixels.len();
    let

Replies: 2 comments

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by astariul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants