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

Change Active Storage’s video preview format from PNG to JPG #32967

merged 1 commit into from May 23, 2018


None yet
3 participants

javan commented May 23, 2018

PNG is not an ideal format for storing video previews for the same reason it’s not ideal for storing photos. We don’t need lossless compression or the associated extra bytes. Switching to JPG results in files that are ~90% smaller and have a negligible difference in image quality.


$ ffmpeg -i beach.m4v -y -vcodec png -vf thumbnail -vframes 1 -f image2 beach.png

$ mediainfo beach.png
Format      : PNG
File size   : 1.78 MiB
Width       : 1 920 pixels
Height      : 1 080 pixels
Bit depth   : 24 bits
Compression : Lossless


$ ffmpeg -i beach.m4v -y -vframes 1 -f image2 beach.jpg

$ mediainfo beach.jpg
Format      : JPEG
File size   : 82.2 KiB
Width       : 1 920 pixels
Height      : 1 080 pixels
Bit depth   : 8 bits
Compression : Lossy

beach.m4v details
$ mediainfo beach.m4v
Format    : MPEG-4
Codec ID  : M4V  (M4V /M4A /mp42/isom)
File size : 37.4 MiB
Duration  : 20 s 860 ms
Width     : 1 920 pixels
Height    : 1 080 pixels

@javan javan added the activestorage label May 23, 2018

@javan javan requested a review from georgeclaghorn May 23, 2018

@javan javan merged commit 78a9de5 into rails:master May 23, 2018

2 checks passed

codeclimate All good!
continuous-integration/travis-ci/pr The Travis CI build passed

@javan javan deleted the javan:ast/jpg-video-previews branch May 23, 2018

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