getCanExtractFramesFast()
从 v4.0 开始,帧可以始终快速提取,因此此功能已被移除。本文件中的信息仅适用于旧版本的 Remotion,并为仍在使用旧版本的人保留。
自 v3.3.2 起可用,v4.0 中已移除 - @remotion/renderer 包的一部分.
🌐 Available since v3.3.2, removed in v4.0 - Part of the @remotion/renderer package.
探讨在使用 <OffthreadVideo> 时是否可以高效地提取视频的帧。
🌐 Probes whether frames of a video can be efficiently extracted when using <OffthreadVideo>.
import {getCanExtractFramesFast} from '@remotion/renderer';
const result = await getCanExtractFramesFast({
src: '/var/path/to/video.mp4',
});
console.log(result.canExtractFramesFast); // false
console.log(result.shouldReencode); // true传递一个绝对路径给 getCanExtractFramesFast()。不支持 URL。
何时使用此 API
🌐 When to use this API
如果你正在使用 <OffthreadVideo>,当视频中包含的视频没有足够的元数据以高效提取某一帧时,你可能会收到警告 ["使用慢速方法提取帧"] (/docs/slow-method-to-extract-frame)。这可能导致渲染变慢。
🌐 If you are using <OffthreadVideo>, you might get a warning "Using a slow method to extract the frame" if a video is included which does not include enough metadata to efficiently extract a certain frame of a video. This might result in the render becoming slow.
使用此 API,你可以检测此问题是否影响你的视频文件。它将尝试提取视频的最后一帧,如果成功,则说明你的视频未受影响。否则,canExtractFramesFast 将为 false。
🌐 Using this API, you can probe whether this issue affects your video file. It will try to extract the last frame of a video and if it succeeds, your video is not affected. Otherwise, canExtractFramesFast will be false.
如何根据结果采取行动
🌐 How to act on the results
当 canExtractFramesFast 是 false 时,你应该检查 shouldReencode 标志。如果它为真,你可以重新编码视频以加快渲染速度。注意,重新编码视频并不总比处理缓慢的渲染更快。
🌐 When canExtractFramesFast is false, you should check the shouldReencode flag. If it is true, you can re-encode the video to make the render faster. Note that it is not always faster to re-encode the video than it is to deal with a slow render.
使用 VP8 编解码器的视频完全不支持快速帧提取,因此即使 canExtractFramesFast 为 false,shouldReencode 也可能为 false。
🌐 Videos with a VP8 codec don't support fast frame extraction at all, and therefore shouldReencode can be false even if canExtractFramesFast is false.
重新编码视频
🌐 Reencoding a video
你可以使用 FFmpeg 对视频进行重新编码:
🌐 You can re-encode a video using FFmpeg:
ffmpeg -i inputvideo.mp4 outputvideo.mp4参数
🌐 Arguments
一个包含以下一个或多个选项的对象:
🌐 An object containing one or more of the following options:
src
指向一个视频文件。必须是绝对文件路径。
🌐 Pointing to a video file. Must be an absolute file path.
ffmpegExecutable
ffmpegExecutable在 v4.0 中移除
🌐 removed in v4.0
用于覆盖 ffmpeg 可执行文件的绝对路径。
🌐 An absolute path overriding the ffmpeg executable to use.
ffprobeExecutable
ffprobeExecutable在 v4.0 中移除
🌐 removed in v4.0
用于覆盖 ffprobe 可执行文件的绝对路径。
🌐 An absolute path overriding the ffprobe executable to use.
返回值
🌐 Return value
返回一个 promise,该 promise 解析为一个包含以下参数的对象:
🌐 Returns a promise which resolves to an object with the following parameters:
canExtractFramesFast:boolean 是否从视频中提取帧会很快。shouldReencode:boolean 视频是否可以重新编码以加快渲染速度。