🎥 Make videos programmatically with React
add docs
Jonny Burger1557e8560708
diff --git a/packages/docs/docs/media-parser/parse-media.mdx b/packages/docs/docs/media-parser/parse-media.mdxindex b697589db9..8c611fa698 100644--- a/packages/docs/docs/media-parser/parse-media.mdx+++ b/packages/docs/docs/media-parser/parse-media.mdx@@ -117,6 +117,11 @@ const onAudioTrack: OnAudioTrack = ({track}) => {};```+### `selectM3uStream?`++A callback that is called when a `.m3u8` file is detected which has multiple streams.+See [Stream selection](/media-parser/stream-selection) for an example.+### `onParseProgress?`A callback that is called from time to time when bytes have been read from the media.diff --git a/packages/docs/docs/media-parser/selecting-streams.mdx b/packages/docs/docs/media-parser/selecting-streams.mdxnew file mode 100644index 0000000000..6d0ef983e5--- /dev/null+++ b/packages/docs/docs/media-parser/selecting-streams.mdx@@ -0,0 +1,75 @@+---+image: /generated/articles-docs-media-parser-selecting-streams.png+id: stream-selection+title: Stream selection+slug: /media-parser/stream-selection+crumb: '@remotion/media-parser'+---++Some containers such as `.m3u8` (and in the future `.mpd`) support multiple equivalent streams, of which you are supposed to select one.+For example, a `.m3u8` file might contain multiple video streams with different resolutions.++By default, the stream with the highest resolution is selected (sorted by width multiplied by height).++## Selecting a stream++Use the [`selectM3uStream`](/docs/media-parser/parse-media#selectm3ustream) option to select a stream.++```tsx twoslash Selecting the first stream+import {parseMedia} from '@remotion/media-parser';++const media = await parseMedia({+ src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',+ selectM3uStream: ({streams}) => {+ for (const stream of streams) {+ console.log(stream.resolution); // {width: 1920, height: 1080}+ console.log(stream.bandwidth); // 4400000+ console.log(stream.url); // "https://test-streams.mux.dev/x36xhzz/193039199_mp4_h264_aac_hd_7.m3u8"+ console.log(stream.averageBandwidth); // null+ console.log(stream.codecs); // ["avc1.640028", "mp4a.40.2"]+ }++ return streams[0].id;+ },+});+```++## Show a stream selection interface++If you want an end user to pick the quality, it is recommended that you use two passes.+You can extract the streams in the first pass and then show a UI to the user to pick the quality.++```tsx twoslash Getting the available streams+import {parseMedia} from '@remotion/media-parser';++const {m3uStreams} = await parseMedia({+ src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',+ fields: {+ m3uStreams: true,+ },+});+```++## Resorting to default behavior++If you want to resort to the default behavior (selecting the stream with the highest resolution), use the `defaultSelectM3uStreamFn` function.++```tsx twoslash Resorting to default behavior+import {parseMedia, defaultSelectM3uStreamFn} from '@remotion/media-parser';++const media = await parseMedia({+ src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',+ selectM3uStream: (params) => {+ // Add custom logic++ // ...++ // Resort to default behavior+ return defaultSelectM3uStreamFn(params);+ },+});+```++## See also++- [`parseMedia()`](/docs/media-parser/parse-media)diff --git a/packages/docs/docs/webcodecs/convert-media.mdx b/packages/docs/docs/webcodecs/convert-media.mdxindex 61f9b2b61b..af473599fb 100644--- a/packages/docs/docs/webcodecs/convert-media.mdx+++ b/packages/docs/docs/webcodecs/convert-media.mdx@@ -233,6 +233,13 @@ _Function_ <TsType type="ConvertMediaOnVideoTrackHandler" source="@remotion/webcTake control of what to do for each video track in the file: Re-encoding, copying, or dropping.See [Track Transformation](/docs/webcodecs/track-transformation) for a guide on how to use this callback.+### `selectM3uStream?`++_Function_ <TsType type="SelectM3uStreamFn" source="@remotion/media-parser"/>++A callback that is called when a `.m3u8` file is detected which has multiple streams.+See [Stream selection](/media-parser/stream-selection) for an example.+### `progressIntervalInMs?`_number_diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex bb0598c313..c9214e7456 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -934,6 +934,7 @@ module.exports = {'media-parser/pause-resume-abort','media-parser/webcodecs','media-parser/foreign-file-types',+ 'media-parser/stream-selection',],},{diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 88ad1d95ac..c7d8a04baa 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -2528,6 +2528,15 @@ export const articles = [noAi: false,slug: 'media-parser/runtime-support',},+ {+ id: 'stream-selection',+ title: 'Stream selection',+ relativePath: 'docs/media-parser/selecting-streams.mdx',+ compId: 'articles-docs-media-parser-selecting-streams',+ crumb: '@remotion/media-parser',+ noAi: false,+ slug: 'media-parser/stream-selection',+ },{id: 'tags',title: 'Extract ID3 tags and EXIF data',diff --git a/packages/docs/static/generated/articles-docs-media-parser-selecting-streams.png b/packages/docs/static/generated/articles-docs-media-parser-selecting-streams.pngnew file mode 100644index 0000000000..4e6347dca5Binary files /dev/null and b/packages/docs/static/generated/articles-docs-media-parser-selecting-streams.png differ