Skip to content
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

Implement sharpening for thumbnails & previews #6232

Open
veikk0 opened this issue Feb 19, 2024 · 3 comments
Open

Implement sharpening for thumbnails & previews #6232

veikk0 opened this issue Feb 19, 2024 · 3 comments

Comments

@veikk0
Copy link

veikk0 commented Feb 19, 2024

Describe the problem to be solved

As far as I've been able to determine, PeerTube doesn't currently sharpen the thumbnails or previews it generates.

The issues of thumbnail and preview quality have previously been raised in #5618 and #5464, and while I agree that thumbnail resolution should be increased somewhat, purely increasing the resolution isn't the only way to augment the perceived quality of thumbnails.

For websites operating at large enough scale, sharpening is a fairly common way of counteracting the reduction of detail that occurs as a consequence of downscaling images to thumbnail sizes.

Describe the solution you would like

FFmpeg includes multiple sharpening filters. unsharp is probably the most widely used.

Below are thumbnails generated with FFmpeg at 336x188 (the thumbnail resolution Youtube serves me), with sharpening and without, as well as a thumbnail generated by PeerTube currently (280x157). The FFmpeg filters used were scale=336:188,unsharp=3:3:0.6.

normal

unsharp

peertube-frontpage

(source image)

To compare the fidelity between sharpened/not-sharpened images, I recommend opening them in tabs and switching between them.

In terms of file sizes, not-sharpened image is 22.5 kb, the sharpened image is 25.1 kb, and the lower-resolution Peertube-generated thumbnail is 23.7 kb. However, the -q:v parameter can be used to change the quality and thus the file size. Even at these fairly similar file sizes, the resolution increase and sharpening haven't drastically increased the file size at -q:v 5, while the perceived quality has increased noticeably.

@Chocobozzz
Copy link
Owner

Chocobozzz commented Feb 19, 2024

Hi,

Thanks for this interesting issue. Do you have resources on what value would be best (depending on image size and ffmpeg CPU) for -q:v or unsharp?

FYI ffmpeg doesn't scale the generated image, we use jimp (and so jpeg-js) for that purpose.

@veikk0
Copy link
Author

veikk0 commented Feb 21, 2024

From my testing, -q:v 5 or 4 are a good setting for both thumbnails and the previews. In theory, the bigger the image the less noticeable the artifacts are and thus you can use higher values, but since the previews get displayed at higher than their native resolution of 850x480, keeping artifacts to a minimum is probably a good idea.

In terms of CPU usage, the impact is so minuscule that I'd have to process a large batch of images on my 15W dual-core from 2015 to even measure it. It's basically an instant operation.

@Chocobozzz
Copy link
Owner

I added the q:v option in fb2dc40

I'm a little bit more hesitant with the unsharp filter as the value seems like vodoo to me ^^ And from my tests I've noticed that sometimes it can decrease the thumbnail quality. But I'm not against adding an admin config so they can choose to enable/disable this filter if we implement it (it's just more work)./

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants