Small files

See ffmpeg-commands for other ffmpeg commands.

To drop the quality to a constant level, use -crf. Higher values = lower quality. For h265 the default is 28, for h264 (standard MP4) it's 23 and for both it maxes at 51 (unless the video is 10-bit h264, in which case it can go to 63). Then set a preset for encoding/decoding time. Slower preset = higher compression but slower to encode and more CPU to decode. The default for both is "medium", other values are:

CPU intensity for encoding can be increased with the -threads option (e.g. -threads 8) if it isn't choosing the right number by default; this may speed up encoding time.

h264 can be tuned to a variety of values for different uses: see

h264 Tune

AV1

AV1 is a powerful codec for compression, when paired with Opus audio. This is the master command I crib most commands from:

ffmpeg -i input.mp4 -c:v libaom-av1 -strict -2 -threads 8 -cpu-used 8 -filter:v "fps=12,scale=-2:240" -crf 52 -c:a libopus -b:a 10k -ac 1 output.webm

Note that it's 12 fps and 240p - change those parameters as needed. Similarly, 10kbps audio is tolerable for speech, but usually should be at least 64kbps for music or anything already distorted, though Opus seems to be great with that as well!

Taken from Andrew Roach's article.

Opus Audio

Opus audio is good for small music files.

See Andrew's post on that.

The main commands from it, though, are:

ffmpeg -i input.flac -c:a libopus -b:a 16k -map_channel 0.0.0 output.opus

(For 16kbps mono audio using ffmpeg. Don't go lower than 8kbps for music or 6kbps for speech or it'll sound *really* bad).

And:

opusenc --bitrate 16 --music --downmix-mono input.wav output.opus

(For 16kbps mono audio using opusenc, supposedly a better quality than ffmpeg?)