One of the most commonly asked questions on Freenode/#ffmpeg is how to use it to encode videos for YouTube in accordance to Googles Recommended upload encoding settings. Conforming to the guideline is rather simple, but not straightforward for the newcomer.

1. Get newish ffmpeg

Get decently new and updated ffmpeg - the current stable release is 2.7.


brew install ffmpeg


Get a 64-bit static build from Zeranoe’s site.


Get a 64-bit static build from Linux static build site.

2. The command line

ffmpeg -i <input file> -codec:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart <output_name>.mp4

This should suffice for full conformity. Explanation of parameters used:

-codec:v libx264set video codec to H.264
-crf 21set video quality. Lower number means higher quality. 21 is a reasonable default which will create videos with bitrates as per guideline.
-bf 2maximum 2 B-frames as per guideline
-flags +cgopclosed GOP as per guideline
-pix_fmt yuv420pchroma subsampling 4:2:0 as per guideline
-codec:a aac -strict -2set audio codec to AAC
-b:a 384set audio bitrate to 348k, set this to 512k if you have 5.1 audio
-r:a 48000set audio samplerate to 48000Hz as per guideline
-movflags faststartput MOOV atom at the front of the file

If any of the parameters don’t work properly, check your ffmpeg version. Especially Ubuntu 12.04/14.04 and other Debian based distros package obsolete ffmpeg as part of their apt repositories.