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_videocompanion 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_videoattachment 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 theanimated_videocompanions are handled. - Expose a
wp_video_transcoding_keep_originalfilter (defaulttrue) on the REST API index asvideo_keep_original, and preload it with the other media processing settings. When a site returnsfalse, 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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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:
optimized_videocompanion size, and only for that size. Every other size still needs an image or PDF parent.optimized_videometadata key on finalize, and include it in the names a request is allowed to store.wp_delete_attachment_files().wp_video_transcoding_keep_originalfilter (defaulttrue) on the REST index asvideo_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 tooptimized_videoon the Gutenberg side to match this backport.### Testing
npm run test:php -- --filter 'Tests_Media_wpDeleteAttachmentOptimizedVideo|optimized_video|test_get_index_should'## AI Use
Code and description both written with 🤖 Claude Code. I will review and test.