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
Media Upload Queue #6541
Media Upload Queue #6541
Conversation
Size Change: +2.91 kB (0%) Total Size: 1.22 MB
ℹ️ View Unchanged
|
Codecov Report
@@ Coverage Diff @@
## main #6541 +/- ##
===========================================
+ Coverage 49.83% 82.81% +32.97%
===========================================
Files 700 1127 +427
Lines 12013 20061 +8048
===========================================
+ Hits 5987 16613 +10626
+ Misses 6026 3448 -2578
Flags with carried forward coverage won't be shown. Click here to find out more.
|
I am seeing this bug more while testing this - #6427 |
I think we need to change these lines With this PR, we are adding a state where we know that poster is going to be null. This just makes the averageColor issue worse. |
While I am not seeing the bug at the moment, I've made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a regreation and some repeated code. I also have some other feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Excited on doors this opens in the future.
Context
Videos that need to be transcoded during upload cannot be previewed in the editor/library until they have been processed by FFmpeg. In that scenario, we currently don't display anything until transcoding is finished, which means the user has to wait a long time for feedback.
For improved UX around video optimization during upload, we want to display a placeholder image first and replace it with an actual preview as soon as it gets available—all while the upload is still progressing behind the scenes.
Unfortunately, the current media upload queue is not very stateful in that regard and does not allow for such updates in the middle of the process, nor does the consumer even know what state an individual file is currently in.
Summary
This PR introduces a new hook to act as a queue for media uploads where we know the state (e.g. pending/transcoding/uploading/finished/cancelled) of each file being uploaded at all times.
Not only does this allow us to update media resources mid-progress, but we can now also do things like displaying tooltips for items still being processed (#6089).
Regular image and video uploads should not be affected by this change
The most significant change is when uploading video files that need to be transcoded, for example a MOV file from iPhone.
For such files, the process looks a bit like follows:
Relevant Technical Choices
prependMedia
action to add items to the beginning of the media library. This avoids having to replace the whole list of items withsetMedia
, which is error prone if using outdated itemsupdateMediaElement
to allow overriding the resource's ID. This is necessary because local resources (i.e. still being uploaded) now have an ID already, but after upload they will have a WordPress attachment ID.resource
now has a newisPlaceholder
property to identify whether it's a blankdeleteElementsByResourceId
action to delete elements by resource ID across all pages (deleteElementsById
only works on the current page) in case upload failed. This is needed because the user could have duplicated/copied elements/pages while upload was in progress.validateFileForUpload
anduploadFile
functionsuseTranscodeVideo
usage touseUploadMedia
because it's actually only used and needed by that.useUploader
should not be concerned with transcoding.To-do
User-facing changes
Uploading a regular image
(no visible change)
PNG.file.mov
Uploading a regular video
(no visible change)
MP4.File.mov
Uploading a video requiring additional transcoding
(see placeholder element before preview later on)
MOV.HEVC.mov
Uploading a video requiring additional transcoding but with poster
(see poster image before preview later on)
MOV.File.H264.mov
Testing Instructions
QA
Prerequisites
Download some test files here:
test files.zip
Turn on video optimization experiment and enable video optimization in settings
ZIP file, dropped on media library
ZIP file, dropped on editor
PNG image, dropped on editor
PNG image, dropped on media library
MP4 video, dropped on editor
MP4 video, dropped on media library
MOV video (H.264), dropped on editor
MOV video (H.264), dropped on media library
MOV video (HEVC), dropped on editor
MOV video (HEVC), dropped on media library
UAT
This PR can be tested by following these steps:
Reviews
Does this PR have a security-related impact?
No
Does this PR change what data or activity we track or use?
No
Does this PR have a legal-related impact?
No
Checklist
Type: XYZ
label to the PRFixes #6088
Also partially addresses #6400 by using
URL.revokeObjectURL()
as neededAlso fixes #6427