Skip to main content

调整视频大小

你可以使用 @remotion/webcodecs 包中的 convertMedia() 函数在浏览器中调整视频大小。

🌐 You can resize a video in the browser using convertMedia() function from the @remotion/webcodecs package.

💼 重要许可免责声明
This package is licensed under the Remotion License.
We consider a team of 4 or more people a "company".

For "companies": A Remotion Company license needs to be obtained to use this package.
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.

For individuals and teams up to 3: You can use this package for free.

This is a short, non-binding explanation of our license. See the License itself for more details.
🚧 不稳定的 API
This package is experimental.
We might change the API at any time, until we remove this notice.

简单例子

🌐 Simple Example

Scale a video down to 480p
import {convertMedia} from '@remotion/webcodecs'; await convertMedia({ 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 480p
import {ResizeOperation} from '@remotion/webcodecs'; const resize: 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 wide
import {ResizeOperation} from '@remotion/webcodecs'; const resize: 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 wide
import {ResizeOperation} from '@remotion/webcodecs'; const resize: ResizeOperation = { mode: 'width', width: 640, };

将视频缩放到正好 width 像素宽。

🌐 Scales a video to exactly width pixels wide.

height

Scale a video to 480 pixels tall
import {ResizeOperation} from '@remotion/webcodecs'; const resize: 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 width
import {ResizeOperation} from '@remotion/webcodecs'; const resize: 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'; const resize: 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

如果你同时应用 rotateresize 操作,将会先应用 rotate 操作。

🌐 If you apply both a rotate and a resize operation, the rotate operation will be applied first.

另请参阅

🌐 See also