90.18 Video Resize


Videos files can be quite large in size and the size is not always warranted. A screencast of 30 minutes might, for example, result in a 350MB file. This can be reduced to 60MB with little or no apparent loss of quality.

To reduce the size of the video whilst retaining enough quality, try using the h.265 video (libx265) format which compresses a video stream whilst retaining good quality. Here a video is input to ffmpeg with -i, converted to the video codec H.265 using -c:v libx265 (or the alias -vcodec), with a Constant Rate Factor of 28 using -crf with a straight copy of the audio -c:a copy:

$ ffmpeg -i myvideo.webm -c:v libx265 -crf 28 -c:a copy smaller.mp4

This can be abbreviated as

$ ffmpeg -i myvideo.webm -vcodec libx265 -crf 28 smaller.mp4

For the constant rate factor 24–30 is a good range, with lower values giving better quality but larger files. A crf of 0 is lossless processing whilst at the other end of the scale a crf of 51 is quite lossy but a lot smaller files. Experiment by increasing or decreasing the crf to trade off quality against file size.

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0