Skip to main content

5. Implementing a video resizing solution yourself

Prerequisites

Before reading this page, read the previous page on implementing image resizing solutions yourself (as much of the same process is required).

This page assumes you already know the steps involved in that, and focuses on specific differences you need to account for when resizing videos instead of images.

Video encoding and resizing

The main difference, predictably, is in actually resizing and re-encoding the videos themselves. The main differences you need to consider are encoding time, the library to use, video formats, and an understanding of video encoding and parameters.

Video encoding libraries

I highly recommend using FFmpeg for resizing and re-encoding videos. You will need to compileCompiling FFmpeg yourself is possible but not advised for this use case - it's awkward to make it toself-contained workand run properly -in thean pre-builtisolated binaries generally do not include support for codecsenvironment like x264 and x265, which you will need.

There is an excellent guide for compiling FFmpeg on Linux, specifically Ubuntu/Debian Linux distributions, here: https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu . Some notes on exactly how you should go about compiling this using AWS servers is below.this.

Notes on compiling FFmpeg on AWS Lightsail servers

I recommend you use the normal LAMP offering in Lightsail. The Bitnami LAMP stack that Lightsail uses runs on Debian, so it's compatible with the guide linked above.

You will need to use at least the $10 server tier - a $3.5 server will not suffice here. Lightsail servers use a burstable CPU system; they accrue CPU credits over time they can use to run at higher than normal capacity, but when operating above that capacity, they consume the credits. The baseline "performance" counted as capacity changes on which price of server you chose; the $3.5 server considers 5% CPU usage the baseline for instance, so doing anything heavy will eat your CPU credits like crazy (and you can't accumulate credits forever, they have a limit for each server).

When you start up a server, there's a small grace period where you get some extra credits that aren't displayed in the metrics screens, to stop smaller servers becoming sluggish when e.g. installation scripts are run on them. Compiling some of the FFmpeg libraries is going to exceed this, so we need to use a server with a decent baseline.

You can see in the article from Amazon here exactly how this works. Here's a screenshot of the baselines of each server type from the article:

image.png

The $20/month Linux servers don't have any benefit in this case over the $10 one, and the $40 one is likely to be overkill, so I recommend using the $10 option for this purpose. You won't actually be billed much, as you don't need to keep this server around after you finish compiling and whatnot; Lightsail charges in hourly increments, so probably a few cents. If you have trouble with your server getting throttled due to a lack of CPU credits, try again from scratch with a higher price instance.