🎥 Make videos programmatically with React
alright
Jonny Burger743392db8f98
diff --git a/packages/docs/docs/webcodecs/rotate-and-resize-video-frame.mdx b/packages/docs/docs/webcodecs/rotate-and-resize-video-frame.mdxindex 7732facea1..7739e8e75a 100644--- a/packages/docs/docs/webcodecs/rotate-and-resize-video-frame.mdx+++ b/packages/docs/docs/webcodecs/rotate-and-resize-video-frame.mdx@@ -6,7 +6,7 @@ slug: /webcodecs/rotate-and-resize-video-framecrumb: '@remotion/webcodecs'----# rotateAndResizeVideoFrame()<AvailableFrom v="4.0.315"/>+# rotateAndResizeVideoFrame()<AvailableFrom v="4.0.316"/>_Part of the [`@remotion/webcodecs`](/docs/webcodecs) package._@@ -17,7 +17,8 @@ import {LicenseDisclaimer} from './LicenseDisclaimer';<LicenseDisclaimer /></details>-Rotates and resizes a [`VideoFrame`](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame) object. Returns a new [`VideoFrame`](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame) object with the applied transformations.+Resizes and/or rotates a [`VideoFrame`](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame) object.+Returns a new [`VideoFrame`](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame) object with the applied transformations, or the original frame if no transformations are applied.```tsx twoslash title="Rotating a video frame by 90 degrees"import {rotateAndResizeVideoFrame} from '@remotion/webcodecs';@@ -82,13 +83,16 @@ The rotation angle in degrees. Only multiples of 90 degrees are supported (0, 90### `resizeOperation`-A resize operation to apply to the frame, or `null` if no resizing is needed. See [`ResizeOperation`](/docs/webcodecs/resizing) for available options.+A resize operation to apply to the frame, or `null` if no resizing is needed.+See: [Resize modes](/docs/webcodecs/resize-a-video#resize-modes) for available options.### `needsToBeMultipleOfTwo?`_optional, default: `false`_-Whether the resulting dimensions should be multiples of 2. This is often required for certain video codecs. If `true`, the dimensions will be rounded down to the nearest even number.+Whether the resulting dimensions should be multiples of 2.+This is often required if encoding to a codec like H.264.+If `true`, the dimensions will be rounded down to the nearest even number.## Behavior@@ -134,13 +138,6 @@ if (transformedFrame !== originalFrame) {// transformedFrame.close();```-## Error handling--- Throws an error if the rotation is not a multiple of 90 degrees.-- Throws an error if the 2D rendering context cannot be created.-## See also-- [`ResizeOperation`](/docs/webcodecs/resizing) - Available resize operations-- [Rotate a video](/docs/webcodecs/rotate-a-video) - Guide on rotating videos-- [`convertMedia()`](/docs/webcodecs/convert-media) - Convert entire videos with rotation and resizing+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/webcodecs/src/rotate-and-resize-video-frame.ts)diff --git a/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx b/packages/studio/src/components/Timeline/TimelineVideoInfo.tsxindex 9d9702fa14..df6ad61d1d 100644--- a/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx+++ b/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx@@ -1,5 +1,5 @@import {hasBeenAborted, WEBCODECS_TIMESCALE} from '@remotion/media-parser';-import {extractFrames, WebCodecsInternals} from '@remotion/webcodecs';+import {extractFrames, rotateAndResizeVideoFrame} from '@remotion/webcodecs';import React, {useEffect, useMemo, useRef, useState} from 'react';import {useVideoConfig} from 'remotion';import {TIMELINE_LAYER_HEIGHT} from '../../helpers/timeline-layout';@@ -245,7 +245,7 @@ export const TimelineVideoInfo: React.FC<{onFrame: (frame) => {const scale = HEIGHT / frame.displayHeight;- const transformed = WebCodecsInternals.rotateAndResizeVideoFrame({+ const transformed = rotateAndResizeVideoFrame({frame,resizeOperation: {mode: 'scale',diff --git a/packages/webcodecs/src/rotate-and-resize-video-frame.ts b/packages/webcodecs/src/rotate-and-resize-video-frame.tsindex f07a528d89..20be876955 100644--- a/packages/webcodecs/src/rotate-and-resize-video-frame.ts+++ b/packages/webcodecs/src/rotate-and-resize-video-frame.ts@@ -16,8 +16,8 @@ export const rotateAndResizeVideoFrame = ({}: {frame: VideoFrame;rotation: number;- needsToBeMultipleOfTwo?: boolean;resizeOperation: ResizeOperation | null;+ needsToBeMultipleOfTwo?: boolean;}) => {const normalized = ((rotation % 360) + 360) % 360;diff --git a/packages/webcodecs/src/test/rotate-and-resize-video-frame.test.ts b/packages/webcodecs/src/test/rotate-and-resize-video-frame.test.tsdeleted file mode 100644index 21868f3161..0000000000--- a/packages/webcodecs/src/test/rotate-and-resize-video-frame.test.ts+++ /dev/null@@ -1,65 +0,0 @@-import {expect, test} from 'bun:test';-import {rotateAndResizeVideoFrame} from '../rotate-and-resize-video-frame';--// Test that focuses on API structure and parameter validation-test('rotateAndResizeVideoFrame - function exists and has correct signature', () => {- expect(typeof rotateAndResizeVideoFrame).toBe('function');-});--test('rotateAndResizeVideoFrame - throws error for invalid rotation', () => {- // Mock VideoFrame that's sufficient for this test- const mockFrame = {- displayWidth: 100,- displayHeight: 200,- timestamp: 0,- duration: 1000000,- close: () => {},- } as unknown as VideoFrame;-- expect(() => {- rotateAndResizeVideoFrame({- frame: mockFrame,- rotation: 45, // Not a multiple of 90- resizeOperation: null,- });- }).toThrow('Only 90 degree rotations are supported');-});--test('rotateAndResizeVideoFrame - accepts optional needsToBeMultipleOfTwo parameter', () => {- // Mock VideoFrame that's sufficient for this test- const mockFrame = {- displayWidth: 100,- displayHeight: 200,- timestamp: 0,- duration: 1000000,- close: () => {},- } as unknown as VideoFrame;-- // Should not throw when needsToBeMultipleOfTwo is omitted- expect(() => {- rotateAndResizeVideoFrame({- frame: mockFrame,- rotation: 0,- resizeOperation: null,- });- }).not.toThrow();-- // Should not throw when needsToBeMultipleOfTwo is explicitly provided- expect(() => {- rotateAndResizeVideoFrame({- frame: mockFrame,- rotation: 0,- resizeOperation: null,- needsToBeMultipleOfTwo: true,- });- }).not.toThrow();-- expect(() => {- rotateAndResizeVideoFrame({- frame: mockFrame,- rotation: 0,- resizeOperation: null,- needsToBeMultipleOfTwo: false,- });- }).not.toThrow();-});