调整视频大小
你可以使用 @remotion/webcodecs 包中的 convertMedia() 函数在浏览器中调整视频大小。
🌐 You can resize a video in the browser using convertMedia() function from the @remotion/webcodecs package.
💼 重要许可免责声明
We consider a team of 4 or more people a "company".
In a future version of
@remotion/webcodecs, this package will also require the purchase of a newly created "WebCodecs Conversion Seat". Get in touch with us if you are planning to use this package.🚧 不稳定的 API
We might change the API at any time, until we remove this notice.
简单例子
🌐 Simple Example
Scale a video down to 480pimport {convertMedia } from '@remotion/webcodecs'; awaitconvertMedia ({src : 'https://remotion.media/BigBuckBunny.mp4',container : 'mp4',resize : {mode : 'max-height',maxHeight : 480, }, });
调整大小模式
🌐 Resize modes
对于 resize 值,你可以指定以下模式:
🌐 For the resize value, you can specify the following modes:
max-height
Scale a video down to 480pimport {ResizeOperation } from '@remotion/webcodecs'; constresize :ResizeOperation = {mode : 'max-height',maxHeight : 480, };
将视频缩小,使其高度最多为 maxHeight 像素。
🌐 Scales a video down so it is at most maxHeight pixels tall.
max-width
Scale a video down to 640 pixels wideimport {ResizeOperation } from '@remotion/webcodecs'; constresize :ResizeOperation = {mode : 'max-width',maxWidth : 640, };
将视频缩小,使其宽度最多为 maxWidth 像素。
🌐 Scales a video down so it is at most maxWidth pixels wide.
width
Scale a video to 640 pixels wideimport {ResizeOperation } from '@remotion/webcodecs'; constresize :ResizeOperation = {mode : 'width',width : 640, };
将视频缩放到正好 width 像素宽。
🌐 Scales a video to exactly width pixels wide.
height
Scale a video to 480 pixels tallimport {ResizeOperation } from '@remotion/webcodecs'; constresize :ResizeOperation = {mode : 'height',height : 480, };
将视频缩放到正好 height 像素高。
🌐 Scales a video to exactly height pixels tall.
max-height-width
Scale a video down to 480px height or 640 pixels widthimport {ResizeOperation } from '@remotion/webcodecs'; constresize :ResizeOperation = {mode : 'max-height-width',maxHeight : 480,maxWidth : 640, };
将视频缩小,使其高度最多为 maxHeight 像素,宽度最多为 maxWidth 像素。
视频将被缩小到同时满足这两个限制的最大尺寸。
🌐 Scales a video down so it is at most maxHeight pixels tall or maxWidth pixels wide.
The video will be scaled down to the biggest size that fits both constraints.
scale
Scale a video to 50%import {ResizeOperation } from '@remotion/webcodecs'; constresize :ResizeOperation = {mode : 'scale',scale : 0.5, };
按 scale 的比例缩放视频。比例必须大于 0。
🌐 Scales a video by a factor of scale. Factor must be greater than 0.
运算顺序
🌐 Order of operations
如果你同时应用 rotate 和 resize 操作,将会先应用 rotate 操作。
🌐 If you apply both a rotate and a resize operation, the rotate operation will be applied first.
另请参阅
🌐 See also