Page MenuHomePhabricator

Use Chroma subsampling for image thumbnails (save 17% bandwidth and save memory on mobile)
Closed, ResolvedPublic

Description

http://calendar.perfplanet.com/2015/why-arent-your-images-using-chroma-subsampling/

Looking at today's featured picture at https://en.wikipedia.org/ it seems we don't have this enabled for our thumbnails.

https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/Poecile_montanus_kleinschmidti.jpg/760px-Poecile_montanus_kleinschmidti.jpg

$ identify -format "%[jpeg:sampling-factor]" Poecile_montanus_kleinschmidti.jpg 
1x1,1x1,1x1

Which suggests 4:4:4 as opposed to 4:2:0. The difference is should be minimal visually (especially for thumbnails), and not only saves bandwidth costs and download time, but also processing memory (useful for mobile) - this contrary to some other compression features.

Event Timeline

Krinkle created this task.Dec 22 2015, 9:14 PM
Krinkle raised the priority of this task from to Needs Triage.
Krinkle updated the task description. (Show Details)
Krinkle added a subscriber: Krinkle.
Restricted Application added projects: Multimedia, Commons. · View Herald TranscriptDec 22 2015, 9:14 PM
Restricted Application added subscribers: StudiesWorld, Steinsplitter, Aklapper. · View Herald Transcript
Restricted Application added a subscriber: Matanya. · View Herald TranscriptDec 22 2015, 9:46 PM
MarkTraceur triaged this task as Normal priority.Jan 11 2016, 2:07 PM
MarkTraceur added a subscriber: MarkTraceur.
ori added a subscriber: ori.Feb 1 2016, 7:20 PM

@MarkTraceur, is this something your team could take on? The impact would be substantial.

For the record, this is a suggested improvement for all our thumbnails across the board. Not mobile-specific, or otherwise optional.

ori added a comment.Feb 29 2016, 7:52 PM

@MarkTraceur, ping -- is this something your team could take on?

Sorry about that.

At a glance, it might be something we could work on, but I'd want pretty broad buy-in from people who upload images, especially diagrams with high detail, before we took it on. I don't want to end up with ugly-looking graphs and diagrams in articles because we change the thumbnailing software.

Not really, we're Editing/Multimedia, with stress on the Editing. Someone might overrule me, but this doesn't look like something that matches the team's purpose, and it doesn't look like something that anyone on the team has experience with.

@matmarex is correct about that, also, though I wouldn't rule it out entirely, and it's not my call.

@Krinkle and I spoke about this on IRC, and I'm convinced, particularly because:

I suggest telling COM:VP and VPT about this, at least once, maybe twice. Wikitech ambassadors would probably appreciate a notice, too. I don't think we need consensus, given the performance gain it would give us compared to the tiny hit we'd take in detail.

brion added a subscriber: brion.Mar 1 2016, 10:55 PM

I coulda sworn the default on JPEGs was 4:2:0 but I've spent a lot more time working on video than with JPEG setting tweaks. :D Offhand using 4:2:0 chroma subsampling is a very good idea for nearly all photo-based thumbnails, and if we're defaulting to 4:4:4 we should definitely switch. Will look over details and comment more later.

It's probably a very simple fix when using ImageMagick thumbnailing; what's the state of the art on upcoming new stuff (thumbor?)

ori added a subscriber: Gilles.Mar 1 2016, 10:58 PM

It's probably a very simple fix when using ImageMagick thumbnailing; what's the state of the art on upcoming new stuff (thumbor?)

@Gilles' Thumbor stack for MediaWiki still uses ImageMagick behind the scenes, so it's most likely one fix that needs to be applied in two places.

Tgr added a subscriber: Tgr.Mar 2 2016, 12:21 AM

Three: JPEG media handler in core, VIPS (which we use for large JPGs), Thumbor.

VIPS doesn't seem to offer a way to set a specific chroma subsampling value. It only has an option to "disable" chroma subsampling.

As for IM, it seems like by default it's letting the JPEG library do its thing. Which seems to be either 4:4:4 or keeping the same as the original in production.

And for syntax, both of these seem to work and produce the same result:

convert -sampling-factor 4:2:0
convert -sampling-factor 2x2

I'll add that as a configuration option to Thumbor, for engines that can handle it: T129073

ori added a comment.Mar 7 2016, 7:50 PM

@brion, could you take on the task of modifying the JPEG media handler in core?

brion added a comment.Mar 7 2016, 8:02 PM

@ori can do (core JPEG handler update); do we want to assign this whole task to me or break up to subtasks so we don't forget the other bits?

brion added a comment.Mar 7 2016, 8:18 PM

@Krinkle thanks! T129128 is now assigned to me and on my short list for next couple weeks.

convert -define jpeg:sampling-factor=4:2:0

also works

Change 285669 had a related patch set uploaded (by Brion VIBBER):
[WIP] Enable 4:2:0 chroma subsampling for JPEG thumbnails

https://gerrit.wikimedia.org/r/285669

Restricted Application added a subscriber: Poyekhali. · View Herald TranscriptApr 27 2016, 4:29 PM

Removing patch tag as that patch belongs on subtask T129128.

Jdforrester-WMF closed this task as Resolved.May 11 2016, 5:45 PM
Jdforrester-WMF claimed this task.
Jdforrester-WMF added a subscriber: Jdforrester-WMF.

Turns out we don't use VIPS for JPEG thumbs in WMF production, so I removed that blocker.

Consequently, this has been done since 1.27.0-wmf.23.

brion added a comment.May 11 2016, 5:54 PM

Ah, so JPEGs *of* TIFFs, not JPEGs of JPEGs.

brion added a comment.May 11 2016, 6:07 PM

Ok, so that one also shows as 4:2:0:

jpeg:sampling-factor: 2x2,1x1,1x1

Hmm, PagedTiffHandler appears to be hardcoded to use ImageMagick:

https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FPagedTiffHandler/master/PagedTiffHandler_body.php#L318