@contfu/media-optimizer
v0.1.10
Published
Contfu runtime Media File optimization for Contfu using the [m4k](https://m4k.dev) library.
Readme
@contfu/media-optimizer
Contfu runtime Media File optimization for Contfu using the m4k library.
Processes images, audio, and video locally inside the application boundary during Contfu runtime synchronization. Use this to generate optimized variants (resized images, transcoded video) without an external service.
Usage
Pass the optimizer to connect() from @contfu/contfu:
import { connect } from "@contfu/contfu";
import { M4kOptimizer } from "@contfu/media-optimizer";
for await (const event of connect({ mediaOptimizer: new M4kOptimizer() })) {
// Media Files are optimized automatically by the Contfu runtime
}You can also use the local m4k transform for one-off conversions through convertMedia():
import { convertMedia } from "@contfu/contfu";
import { createTransform } from "@contfu/media-optimizer";
const output = await convertMedia(
fileId,
"webp",
{ mediaType: "image", format: "webp", resize: { width: 1200 } },
createTransform(),
);Both sync-time optimization and one-off conversion honor the same image, video, and audio transform options exposed by @contfu/contfu.
For horizontally scaled deployments, use @contfu/media-optimizer-remote instead.
