🎥 Make videos programmatically with React
copy audio track
Jonny Burger3b3aba3a4b21
diff --git a/packages/docs/docs/webcodecs/can-copy-audio-track.mdx b/packages/docs/docs/webcodecs/can-copy-audio-track.mdxnew file mode 100644index 0000000000..9d761a87bd--- /dev/null+++ b/packages/docs/docs/webcodecs/can-copy-audio-track.mdx@@ -0,0 +1,100 @@+---+id: can-copy-audio-track+title: canCopyAudioTrack()+slug: /webcodecs/can-copy-audio-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 an `AudioTrack`, determine if it can be copied to the output without re-encoding.++You can obtain an `AudioTrack` using [`parseMedia()`](/docs/media-parser/parse-media) or during the conversion process using the [`onAudioTrack`](/docs/webcodecs/convert-media#onaudiotrack) callback of [`convertMedia()`](/docs/webcodecs/convert-media).++## Examples++```tsx twoslash title="Check if an audio track can be copied"+// @module: es2022+// @target: es2017++import {parseMedia} from '@remotion/media-parser';+import {canCopyAudioTrack} from '@remotion/webcodecs';++const {audioTracks} = await parseMedia({+ src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',+ fields: {+ tracks: true,+ },+});++for (const track of audioTracks) {+ canCopyAudioTrack({+ inputCodec: track.codecWithoutConfig,+ outputCodec: 'opus',+ container: 'webm',+ }); // boolean+}+```++```tsx twoslash title="Copy an audio track to Opus, otherwise drop it"+// @module: es2022+// @target: es2017++import {convertMedia, canCopyAudioTrack} from '@remotion/webcodecs';++await convertMedia({+ src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',+ container: 'webm',+ videoCodec: 'vp8',+ audioCodec: 'opus',+ onAudioTrack: async ({track}) => {+ const canCopy = canCopyAudioTrack({+ inputCodec: track.codecWithoutConfig,+ outputCodec: 'opus',+ container: 'webm',+ });++ if (canCopy) {+ return {type: 'copy'};+ }++ // Just to keep the example brief, in reality, you would re-encode the track here+ return {type: 'drop'};+ },+});+```++## API++### `inputCodec`++_string_ <TsType type="MediaParserAudioCodec" source="@remotion/media-parser" />++The codec of the input audio track.++### `outputCodec`++_string_ <TsType type="ConvertMediaAudioCodec" source="@remotion/webcodecs" />++The codec of the output audio track.++### `container`++_string_ <TsType type="ConvertMediaContainer" source="@remotion/webcodecs" />++The container format of the output media.++## 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-audio-track.ts)+- [`canCopyVideoTrack()`](/docs/webcodecs/can-copy-video-track)+- [`canReencodeAudioTrack()`](/docs/webcodecs/can-reencode-audio-track)+- [`convertMedia()`](/docs/webcodecs/convert-media)diff --git a/packages/docs/docs/webcodecs/can-copy-video-track.mdx b/packages/docs/docs/webcodecs/can-copy-video-track.mdxindex 13c49ee61c..b1f9e21ac1 100644--- a/packages/docs/docs/webcodecs/can-copy-video-track.mdx+++ b/packages/docs/docs/webcodecs/can-copy-video-track.mdx@@ -71,7 +71,7 @@ await convertMedia({### `inputCodec`-_string_ <TsType type="ConvertMediaVideoCodec" source="@remotion/webcodecs" />+_string_ <TsType type="MediaParserVideoCodec" source="@remotion/media-parser" />The codec of the input video track.@@ -85,7 +85,7 @@ The codec of the output video track._string_ <TsType type="ConvertMediaContainer" source="@remotion/webcodecs" />-The container format of the output file+The container format of the output media.## Return valuediff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex adf0baeefd..e049a23f54 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -575,8 +575,9 @@ module.exports = {items: ['webcodecs/index','webcodecs/convert-media',- 'webcodecs/can-reencode-video-track','webcodecs/can-reencode-audio-track',+ 'webcodecs/can-reencode-video-track',+ 'webcodecs/can-copy-audio-track','webcodecs/can-copy-video-track',],},