cargo add zvidlib
let source = MemorySource::new(std::fs::read("clip.mp4")?);
let movie = block_on(Mp4Demuxer::open(&source, Mp4DemuxerOptions::default()))?;
let track = movie.tracks.iter().find(|t| t.kind == TrackKind::Video).unwrap();
let samples = block_on(track.to_encoded_video_samples(&source, &limits))?;
let mut reader = ExactFrameReader::new(&native_av1_video_decoder_factory(), config, samples, limits)?;
// Exactly presentation frame 400, never the nearest keyframe.
let frame = reader.get(FrameIndex(400), &CancellationToken::new())?;
Trim the build with Cargo features, for example default-features = false, features = ["vp9-decoder"]. The README has complete read and write programs.
npm install ./zvidlib-web-vX.Y.Z.tgz # from the latest GitHub release
import init, { CreateOptions, MediaOutput, VideoFrame } from "zvidlib";
await init();
const options = new CreateOptions("webm");
options.videoCodec = "vp9";
options.setTimeline(30, 1, 48_000);
const output = await MediaOutput.create(options);
for (let n = 0n; n < 90n; n++) {
draw(ctx, n);
const { data } = ctx.getImageData(0, 0, width, height);
await output.video(0).put(n, VideoFrame.rgba(width, height, data));
}
const webm = await output.finish(); // Blob { type: "video/webm" }
The browser package is attached to every GitHub release.