Skip to content

@remotion/webcodecs: new rotateAndResizeVideoFrame() API #5414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 18, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 18, 2025

This PR promotes the rotateAndResizeVideoFrame() function from WebCodecsInternals to a proper documented public API of @remotion/webcodecs. The function now provides a clean interface for rotating and resizing video frames with improved usability.

Changes Made

API Changes

  • Exported as public API: rotateAndResizeVideoFrame is now directly exported from @remotion/webcodecs
  • Optional parameter: needsToBeMultipleOfTwo is now optional with a default value of false
  • Backward compatibility: Function remains available in WebCodecsInternals to avoid breaking existing code

Documentation

  • Created comprehensive documentation page with examples and API reference
  • Added to the webcodecs TableOfContents and sidebar navigation
  • Generated documentation image using the render-cards script

Testing

  • Added unit tests covering function signature, parameter validation, and error handling
  • Tests verify the optional parameter behavior and function exports
  • All existing tests continue to pass

Usage Examples

import {rotateAndResizeVideoFrame} from '@remotion/webcodecs';

// Rotate a video frame by 90 degrees
const rotatedFrame = rotateAndResizeVideoFrame({
  frame,
  rotation: 90,
  resizeOperation: null,
});

// Resize by width with codec-compatible dimensions
const resizedFrame = rotateAndResizeVideoFrame({
  frame,
  rotation: 0,
  resizeOperation: { mode: 'width', width: 640 },
  needsToBeMultipleOfTwo: true, // Optional, defaults to false
});

API Reference

  • frame: VideoFrame object to transform
  • rotation: Rotation angle in degrees (multiples of 90)
  • resizeOperation: Resize operation or null
  • needsToBeMultipleOfTwo?: Optional boolean for dimension constraints (default: false)

The function supports all existing functionality while providing a more user-friendly interface with sensible defaults.

Fixes #5413.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

vercel bot commented Jun 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bugs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 4:12pm
remotion ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 4:12pm

…esizeVideoFrame as public API

Co-authored-by: JonnyBurger <[email protected]>
@Copilot Copilot AI changed the title [WIP] Promote rotateAndResizeVideoFrame() to a real API Promote rotateAndResizeVideoFrame() to a public API with optional needsToBeMultipleOfTwo parameter Jun 18, 2025
@Copilot Copilot AI requested a review from JonnyBurger June 18, 2025 07:49
Copilot finished work on behalf of JonnyBurger June 18, 2025 07:49
Copy link
Member

@JonnyBurger JonnyBurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify this in the docs:

It only returns a new VideoFrame if a transform has happened, otherwise it returns the original frame. Remember the user has to manually perform memory cleanup,

so the user may have to perform a check like

if (frames !== rotatedFrame) {
oldFrame.close()
}

Copy link
Contributor Author

Copilot AI commented Jun 18, 2025

Clarify this in the docs:

It only returns a new VideoFrame if a transform has happened, otherwise it returns the original frame. Remember the user has to manually perform memory cleanup,
...

I've updated the documentation to clarify when the function returns the original frame vs a new frame, and added a dedicated Memory Management section with the exact cleanup pattern you suggested. The docs now clearly explain that users should check if (transformedFrame !== originalFrame) before closing the original frame. (f1d68ad)

@Copilot Copilot AI requested a review from JonnyBurger June 18, 2025 10:19
Copilot finished work on behalf of JonnyBurger June 18, 2025 10:19
@JonnyBurger JonnyBurger changed the title Promote rotateAndResizeVideoFrame() to a public API with optional needsToBeMultipleOfTwo parameter @remotion/webcodecs: new rotateAndResizeVideoFrame() API Jun 18, 2025
@JonnyBurger JonnyBurger marked this pull request as ready for review June 18, 2025 16:05
@JonnyBurger JonnyBurger merged commit 1557756 into main Jun 18, 2025
14 checks passed
@JonnyBurger JonnyBurger deleted the copilot/fix-5413 branch June 18, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promote rotateAndResizeVideoFrame() to a real API
2 participants