


Since the audio won’t benefit from two-pass encoding, on the first pass use -an to disable it similarly, on the first pass you can use the container format ‘rawvideo’, to save a small amount of processing on the container file. Currently libx264, the h.264 encoder, is the best quality lossy encoder for ffmpeg – and it has a fair amount of hardware support when used in an MP4 container format. For the audio you choose libfdk_aac mixing the audio down to 2 channels with -ac 2, a bit rate of 128kb/s will give good quality, which leaves 932kb/s for the video. To stay on the safe side, round this down to 1060kb/s. Let’s say you want to compress a 90-minute film down to 700MB, so that it will fit on a CD-ROM. The first pass evaluates the video and feeds information to a file ( ffmpeg2pass.log in the working directory by default this can be changed using the -passlogfile option) the second pass uses the information contained in that file to give a better-quality encode. This is a method for encoding videos, targeting a bit rate, that provides the highest quality at the target bit rate. For example: -c:a libmp3lame -b:a 192k will encode MP3 audio with a bit rate of 192kb/s. Others simulate this with a very constrained ‘variable bit rate’ mode either way, use the -b option to set the bit rate. Some codecs have a true ‘constant bit rate’ mode, where a certain number of bits are allocated to a second of the video/audio. If quality is of secondary concern to control of file size, you can target a bit rate. Unless you absolutely need the output file to be a certain size, you should generally take this approach. There are some encoders (like x264 and libfdk_aac) that use their own special option for determining quality. For example, using -c:v mpeg4 -q:v 3 will encode MPEG4 video at a very high quality. Normally, this is set with the -qscale (‘quality scale’), or -q option, with a numerical scale determined by the specific encoder (but generally between 1-31). You can target a certain ‘quality level’, letting the encoder decide what bit rate should be used to achieve that quality. For now, you can just endure the work-in-progress state: I’ve done my best to ascertain that all of this information is accurate (I’ve tested much of it myself), so no need to worry on that front. This document is a draft form I may change things around & will probably split the video & audio sections into two separate articles at some time in the future. For archiving audio I would generally recommend FLAC, but see this hydrogenaudio comparison and decide for yourself.

I am in the process of writing a guide for intermediate video codecs. This guide concentrates on some common delivery codecs, and it is not an exhaustive list.
