Problem/Motivation
On a 8.7.7 site I'm building, I'm using core media's video bundles, pointing to YouTube.
If I inspect the filesystem for the actual thumbnails downloaded by YouTube, I see stuff like this:
% identify *
1V7gFNbwKdw.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 102KB 0.000u 0:00.009
4b5n5PVdHpI.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 104KB 0.000u 0:00.000
55n7BFvNqFQ.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 32.2KB 0.000u 0:00.000
R0gFH3_sMGw.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 188KB 0.000u 0:00.000
S3sdd1i9pbQ.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 399KB 0.000u 0:00.000
lzkW7ngYvQo.jpg JPEG 320x180 320x180+0+0 8-bit sRGB 10.4KB 0.000u 0:00.000
n1X73ZyQroE.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 127KB 0.000u 0:00.000
pFrani050Zs.jpg JPEG 320x180 320x180+0+0 8-bit sRGB 6.08KB 0.000u 0:00.000
However, {media_field_data} has a totally different idea:
mysql> SELECT mid, thumbnail__width, thumbnail__height FROM media_field_data WHERE bundle = 'video' LIMIT 5;
+-----+------------------+-------------------+
| mid | thumbnail__width | thumbnail__height |
+-----+------------------+-------------------+
| 1 | 180 | 180 |
| 5 | 180 | 180 |
| 15 | 180 | 180 |
| 16 | 180 | 180 |
| 17 | 180 | 180 |
+-----+------------------+-------------------+
5 rows in set (0.00 sec)
Thanks to image_preprocess_image_style(), this results in thumbnail markup like so:
<img src=".../sites/default/files/styles/320x180_small/public/video_thumbnails/S3sdd1i9pbQ.jpg?itok=L8Ug7t3z" width="180" height="180" alt="" typeof="foaf:Image" class="image-style-_20x180-small">
Those width and height attributes are bogus, since the metadata in the DB thinks those are the dimensions of the thumbnail. This results in unnecessarily small thumbnails that don't truly respect the image style as I defined it.
Proposed resolution
Record accurate dimensions for the thumbnail files in the media entity metadata stored in the DB.
Remaining tasks
- Figure out why these dimensions are bogus in the DB and fix it.
- Add test coverage about this problem.
- Review
- RTBC
- Commit
User interface changes
Media thumbnails will know their accurate size/aspect ratio, hopefully resulting in better looking UI in places where media thumbnails are being displayed.
API changes
Hopefully none.
Data model changes
None.
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|
Issue fork drupal-3088168
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3088168-media-thumbnail-dimensions
changes, plain diff MR !2037
Comments
Comment #2
dwwp.s. I searched quite a bit and didn't find any existing issues about this. Apologies in advance if it's duplicate.
Thanks,
-Derek
Comment #3
dwwIn Slack, @seanB asked if this is just what YouTube is providing via the oembed service. Good question!
Sadly, that doesn't explain it.
Here's one of the videos from the site:
https://youtu.be/lzkW7ngYvQo
It lives as media ID 814
When I ask youtube, I get this:
https://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3DlzkW...
The relevant bits are:
"thumbnail_width":480and"thumbnail_height":360However, the DB thinks otherwise:
In the absence of any viable solution at #2983456: Expose triggering update of media metadata + thumbnail to end users, it's not easy to trigger a refresh of this data to see if that might solve the problem.
Anyone else seeing anything like this, or is it just me? ;)
Thanks,
-Derek
Comment #5
ambient.impactI'm seeing this as well on 8.8.0 unfortunately.
Comment #6
ambient.impactAfter a bunch of dead ends, I think I've come up with a working workaround. Assuming you have a custom module, you'll need this in that module's
.modulefile:Don't forget to replace
YOUR_MODULEwith the machine name of your module, and clear Drupal's cache. If you only have a handful ofremote_videomedia entities, you can just check them all in the admin UI and choose "Save media" from the "Action" drop-down. If you have a lot of entities you need to update, you can write a hook_update to have Drupal do them all for you.Comment #8
joegl commentedWe are also experiencing this on a 8.9.6 site using the video_embed_field module and YouTube.
Comment #11
orom commentedWe experienced this as well on 9.2.4. We have thumbnail downloads queued and as far as I can tell the 180 width/height comes from the default thumbnail image that gets referenced initially. The problem was that the updateThumbnail() did not seem to do anything for changing the stored width and height even though it fetched the correct thumbnail when cron was run.
If the thumbnail download is not queued then there is no problem (at least, presumably, until the thumbnail changes dimensions).
The workaround in #6 works fine to update the "stuck" thumbnail dimensions.
Comment #12
duaelfrThat's still there is 9.3.6
That's causing issues with the focal point module that cannot calculate an appropriate crop as it is based on the 180x180 size which is not accurate.
Comment #14
duaelfrI opened a MR with a working version.
Here is the test-only patch that should demonstrate the issue.
Comment #16
duaelfrTest on the MR are passing. Test on the test-only fail. This is the expected result.
Back to Needs review so someone can jump on this and push to forward.
Comment #17
ambient.impactGlad to see some movement on this!
Comment #19
blazey commentedThanks for the MR @DuaelFr. It looks good, works as expected, has tests, and fixes an important bug, so moving straight to RTBC.
Comment #20
wim leersI wonder if this is caused by #2966656: Negotiate max width/height of oEmbed assets more intelligently? 🤔
Comment #21
a-fro commentedIn our case, we not only wanted the width and height values to update when an image media entity was updated, but also, the alt text.
We weren't able to find a complete working solution, but by combining the patch on this issue with a bundle class for image entities (as suggested on this issue) that would update the thumbnail each time an image entity is saved, we were able to get all the important values for the thumbnail to update.
Comment #22
alexpottAdded a review to the MR in gitlab. We also need to move the MR to 9.5.x or 9.4.x. Plus getting a test run against 10.x would be useful.
Comment #23
duaelfrPatch applies to 9.5.x and 10.1.x without problem.
Uploading it here to trigger tests.
Comment #24
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.
Reviewing patch #23
Appears the threads were addressed and added to the patch.
Applied the patch locally verified without the fix the tests fail and with the fix they pass.
Code looks clean and comments make sense.
Feel comfortable marking.
Comment #25
alexpottTrying to credit @Edouard Cunibil only to realise it's @DuaelFr :)
Committed and pushed ac30a9859a to 10.1.x and 8f3a9be228 to 10.0.x and a7a492e994 to 9.5.x. Thanks!
Comment #29
duaelfrSorry for that @alexpott!
I'm too lazy to configure my git for every projects ^^
Thank you, though!
Comment #31
mjk200 commentedI use an online service to download youtube video thumbnails with correct dimensions, all these dimensions follow youtube's pre-defined algorithm. The dimension of youtube HD image is 1280X720 Pixels. it may be helpful for someone.