Make WordPress Core

Opened 6 weeks ago

Last modified 6 weeks ago

#65998 new enhancement

Media: Sideload and clean up the web-safe companion of a transcoded video upload

Reported by: adamsilverstein Owned by:
Priority: normal Milestone: 7.2
Component: Media Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

Follow up to #65549 (animated GIF video companions) and #64915 (source-format originals).

The client-side media flow in Gutenberg can now transcode an uploaded video that is not already web-safe (a .mov or .mkv container, a non-web-safe codec, an oversized frame or a high bitrate) to MP4/H.264 or WebM/VP9 in the browser. See ​https://github.com/WordPress/gutenberg/pull/79375. The original upload is kept as the attachment, the same principle behind the -scaled image and the HEIC original, and the transcoded version is sideloaded as a companion file of that attachment. The core/video block points its playback src at the companion.

Core needs the server side of that flow:

  • Accept a video attachment as the sideload parent for a new optimized_video companion size. This is scoped to that one size; every other size still requires an image or PDF parent, since a video has no sub-sizes.
  • Record the companion under the optimized_video attachment metadata key on finalize, and treat it as a name the request is allowed to store.
  • Delete the companion alongside the attachment in wp_delete_attachment_files(), the way the animated_video companions are handled.
  • Expose a wp_video_transcoding_keep_original filter (default true) on the REST API index as video_keep_original, and preload it with the other media processing settings. When a site returns false, the editor transcodes before upload so only the optimized file is stored, trading the ability to download or regenerate from the original for lower storage use.

Patch incoming: ​https://github.com/WordPress/wordpress-develop/pull/13323

Change History (1)

This ticket was mentioned in ​PR #13323 on ​WordPress/wordpress-develop by ​@adamsilverstein.


6 weeks ago
#1

Backport of the PHP from ​https://github.com/WordPress/gutenberg/pull/79375. Follow up to #12005 / [62623], which added the animated GIF video companions this builds on.

When client-side media processing is enabled, the editor transcodes an uploaded video that is not already web-safe to MP4/WebM in the browser and sideloads the result as a companion of the original video attachment, which stays the attachment. This adds the server side of that flow:

  • Accept a video attachment as the sideload parent for the new optimized_video companion size, and only for that size. Every other size still needs an image or PDF parent.
  • Record the companion under the optimized_video metadata key on finalize, and include it in the names a request is allowed to store.
  • Delete the companion alongside the attachment in wp_delete_attachment_files().
  • Expose a wp_video_transcoding_keep_original filter (default true) on the REST index as video_keep_original, and preload it with the other media processing settings.

Note: the Gutenberg PR originally used optimized-video (hyphen) for the size token. Every other special size uses underscores, so the token was renamed to optimized_video on the Gutenberg side to match this backport.

### Testing

  • npm run test:php -- --filter 'Tests_Media_wpDeleteAttachmentOptimizedVideo|optimized_video|test_get_index_should'
  • All new tests were confirmed to fail before the source changes and pass after.

## AI Use

Code and description both written with 🤖 Claude Code. I will review and test.

Note: See TracTickets for help on using tickets.