Skip to main content

canCopyVideoTrack()

属于 @remotion/webcodecs 软件包的一部分.

🌐 Part of the @remotion/webcodecs package.

🚧 不稳定的 API
This package is experimental.
We might change the API at any time, until we remove this notice.

给定一个 VideoTrack,确定它是否可以在不重新编码的情况下复制到输出。

🌐 Given a VideoTrack, determine if it can be copied to the output without re-encoding.

你可以使用 parseMedia() 获取 VideoTrack,或者在使用 convertMedia()onVideoTrack 回调的转换过程中获取。

🌐 You can obtain a VideoTrack using parseMedia() or during the conversion process using the onVideoTrack callback of convertMedia().

示例

🌐 Examples

Check if a video tracks can be copied
import {parseMedia} from '@remotion/media-parser'; import {canCopyVideoTrack} from '@remotion/webcodecs'; const {tracks, container} = await parseMedia({ src: 'https://remotion.media/BigBuckBunny.webm', fields: { tracks: true, container: true, }, }); const videoTracks = tracks.filter((t) => t.type === 'video'); for (const track of videoTracks) { canCopyVideoTrack({ outputContainer: 'webm', inputTrack: track, inputContainer: container, rotationToApply: 0, resizeOperation: null, outputVideoCodec: null, }); // boolean }
Copy a video track to VP8, otherwise drop it
import {convertMedia, canCopyVideoTrack} from '@remotion/webcodecs'; await convertMedia({ src: 'https://remotion.media/BigBuckBunny.webm', container: 'webm', videoCodec: 'vp8', audioCodec: 'opus', onVideoTrack: async ({track, inputContainer, outputContainer}) => { const canCopy = canCopyVideoTrack({ outputContainer, inputTrack: track, inputContainer, rotationToApply: 0, resizeOperation: null, outputVideoCodec: null, }); if (canCopy) { return {type: 'copy'}; } // In reality, you would re-encode the track here return {type: 'drop'}; }, });

应用编程接口

🌐 API

inputTrack

字符串 VideoTrack

🌐 string VideoTrack

输入视频轨道。

🌐 The input video track.

rotationToApply

number

旋转视频轨道的角度数。

🌐 The number of degrees to rotate the video track.

inputContainer

字符串 MediaParserContainer

🌐 string MediaParserContainer

输入媒体的容器格式。

🌐 The container format of the input media.

outputContainer

字符串 ConvertMediaContainer

🌐 string ConvertMediaContainer

输出媒体的容器格式。

🌐 The container format of the output media.

resizeOperation

字符串 ResizeOperation

🌐 string ResizeOperation

要应用于视频轨道的调整大小操作

🌐 The resize operation to apply to the video track.

outputVideoCodec

字符串 | 空 ConvertMediaVideoCodec

🌐 string | null ConvertMediaVideoCodec

输出媒体所需的视频编码。如果是null,则表示只要可以复制视频编码,本身不在意视频编码类型。

🌐 The desired video codec of the output media. If null, it means you don't care about the video codec as long as it can be copied.

旋转行为

🌐 Rotation behavior

任何 rotationToApply 都是在默认应用的自动旋转之外,用于修复视频轨道的方向。

🌐 Any rotationToApply is in addition to an auto-rotation that is applied by default to fix the orientation of the video track.

如果 rotationToApplyinputRotation 的旋转量不同,此函数将始终返回 false,因为在不重新编码的情况下无法进行旋转。

🌐 If rotationToApply is not the same amount of rotation as inputRotation, this function will always return false, because rotation cannot be performed without re-encoding.

参见:旋转视频

🌐 See: Rotating a video

返回值

🌐 Return value

返回一个 boolean

🌐 Returns a boolean.

另请参阅

🌐 See also