-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4495 from remotion-dev/docs
- Loading branch information
Showing
10 changed files
with
155 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
id: can-copy-video-track | ||
title: canCopyVideoTrack() | ||
slug: /webcodecs/can-copy-video-track | ||
crumb: '@remotion/webcodecs' | ||
--- | ||
|
||
_Part of the [`@remotion/webcodecs`](/docs/webcodecs) package._ | ||
|
||
:::warning | ||
**Unstable API**: This package is experimental. We might change the API at any time, until we remove this notice. | ||
::: | ||
|
||
Given a `VideoTrack`, determine if it can be copied to the output without re-encoding. | ||
|
||
You can obtain a `VideoTrack` using [`parseMedia()`](/docs/media-parser/parse-media) or during the conversion process using the [`onVideoTrack`](/docs/webcodecs/convert-media#onvideotrack) callback of [`convertMedia()`](/docs/webcodecs/convert-media). | ||
|
||
## Examples | ||
|
||
```tsx twoslash title="Check if a video tracks can be copied" | ||
// @module: es2022 | ||
// @target: es2017 | ||
import {parseMedia} from '@remotion/media-parser'; | ||
import {canCopyVideoTrack} from '@remotion/webcodecs'; | ||
|
||
const {videoTracks} = await parseMedia({ | ||
src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', | ||
fields: { | ||
tracks: true, | ||
}, | ||
}); | ||
|
||
for (const track of videoTracks) { | ||
canCopyVideoTrack({ | ||
inputCodec: track.codecWithoutConfig, | ||
outputCodec: 'vp8', | ||
container: 'webm', | ||
}); // boolean | ||
} | ||
``` | ||
|
||
```tsx twoslash title="Copy a video track to VP8, otherwise drop it" | ||
// @module: es2022 | ||
// @target: es2017 | ||
|
||
import {convertMedia, canCopyVideoTrack} from '@remotion/webcodecs'; | ||
|
||
await convertMedia({ | ||
src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', | ||
container: 'webm', | ||
videoCodec: 'vp8', | ||
audioCodec: 'opus', | ||
onVideoTrack: async ({track}) => { | ||
const canCopy = canCopyVideoTrack({ | ||
inputCodec: track.codecWithoutConfig, | ||
outputCodec: 'vp8', | ||
container: 'webm', | ||
}); | ||
|
||
if (canCopy) { | ||
return {type: 'copy'}; | ||
} | ||
|
||
// In reality, you would re-encode the track here | ||
return {type: 'drop'}; | ||
}, | ||
}); | ||
``` | ||
|
||
## API | ||
|
||
### `inputCodec` | ||
|
||
_string_ <TsType type="ConvertMediaVideoCodec" source="@remotion/webcodecs" /> | ||
|
||
The codec of the input video track. | ||
|
||
### `outputCodec` | ||
|
||
_string_ <TsType type="ConvertMediaVideoCodec" source="@remotion/webcodecs" /> | ||
|
||
The codec of the output video track. | ||
|
||
### `container` | ||
|
||
_string_ <TsType type="ConvertMediaContainer" source="@remotion/webcodecs" /> | ||
|
||
The container format of the output file | ||
|
||
## Return value | ||
|
||
Returns a `boolean`. | ||
|
||
## See also | ||
|
||
- [Source code for this function on GitHub](https://github.com/remotion-dev/remotion/blob/main/packages/webcodecs/src/can-copy-video-track.ts) | ||
- [`canReencodeVideoTrack()`](/docs/webcodecs/can-reencode-video-track) | ||
- [`convertMedia()`](/docs/webcodecs/convert-media) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type {MediaParserAudioCodec} from '@remotion/media-parser'; | ||
import type {ConvertMediaAudioCodec} from './codec-id'; | ||
import type {ConvertMediaContainer} from './convert-media'; | ||
|
||
export const canCopyAudioTrack = ({ | ||
inputCodec, | ||
outputCodec, | ||
container, | ||
}: { | ||
inputCodec: MediaParserAudioCodec; | ||
outputCodec: ConvertMediaAudioCodec; | ||
container: ConvertMediaContainer; | ||
}) => { | ||
if (outputCodec === 'opus') { | ||
return inputCodec === 'opus' && container === 'webm'; | ||
} | ||
|
||
throw new Error(`Unhandled codec: ${outputCodec satisfies never}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type {MediaParserVideoCodec} from '@remotion/media-parser'; | ||
import type {ConvertMediaVideoCodec} from './codec-id'; | ||
import type {ConvertMediaContainer} from './convert-media'; | ||
|
||
export const canCopyVideoTrack = ({ | ||
inputCodec, | ||
outputCodec, | ||
container, | ||
}: { | ||
inputCodec: MediaParserVideoCodec; | ||
outputCodec: ConvertMediaVideoCodec; | ||
container: ConvertMediaContainer; | ||
}) => { | ||
if (outputCodec === 'vp8') { | ||
return inputCodec === 'vp8' && container === 'webm'; | ||
} | ||
|
||
if (outputCodec === 'vp9') { | ||
return inputCodec === 'vp9' && container === 'webm'; | ||
} | ||
|
||
throw new Error(`Unhandled codec: ${outputCodec satisfies never}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters