Skip to main content

parseMediaOnWebWorker()

这个 API 的工作方式与 parseMedia() 相同,只是它在 Web Worker 上执行解析。Web Workers 仅在浏览器和 Bun 中可用。

🌐 This API works the same as parseMedia(), except that it executes the parse on a Web Worker. Web Workers are only available in Browsers and in Bun.

如果你正在处理解析过程会长时间阻塞 UI 线程的大文件,这将非常有用。

🌐 This is useful if you are processing large files which parsing process would block the UI thread for a longer time.

这个 API 抽象了主线程与工作线程之间的通信,目的是保持与 parseMedia() 相同的 API,包括支持 mediaParserController() 所有异步回调函数的功能。

🌐 This API abstracts the communication between the main thread and the worker with the goal to keep the same API as parseMedia(), including capabilities like supporting mediaParserController() all async callback functions.

API中唯一的区别是reader选项不可用。这是因为你不能将函数传递给Web Worker。

🌐 The only difference in API is that the reader option is not available. This is because you cannot pass a function to a Web Worker.

Parsing a video on a Web Worker
import {parseMediaOnWebWorker} from '@remotion/media-parser/worker'; const result = await parseMediaOnWebWorker({ src: 'https://remotion.media/video.mp4', fields: { durationInSeconds: true, dimensions: true, }, }); console.log(result.durationInSeconds); // 10 console.log(result.dimensions); // {width: 1920, height: 1080}

应用编程接口

🌐 API

parseMedia() 相同,但没有传递 reader 的选项。

🌐 Same as parseMedia(), but without the option to pass a reader.

worker 中的 reader 选项被硬编码为 webReader

🌐 The reader option in the worker is hardcoded to webReader.

另请参阅

🌐 See also