THIS PAGE IS ABOUT THE OLD, MANUAL WAY OF USING X264 IN FFMPEG. IT’S RECOMMENDED TO USE THE PRESETS AS IT WILL MAKE YOUR LIFE MUCH EASIER!!!
The defaults for x264 in FFmpeg are currently significantly detrimental to the quality of the encoded video. This is due to the internal behaviour of FFmpeg with respect to codec defaults. Depending on the rate control method used, a number of different switches need applying to bring the settings into line with the x264 command line interface defaults. These are generally OK settings as they have been suggested by the author(s). The necessary switches for FFmpeg to ‘correct’ the defaults until a proper solution is completed are detailed below, however these may be altered as required.
Apply these settings for all rate control methods:
-coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0
To use one pass CQP:
-cqp <int>
To use one pass CRF:
-crf <float>
To use one pass ABR or two pass VBR:
-b BIT_RATE -bt BIT_RATE -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4
So if you wanted to encode using two-pass VBR, the command line would be something like:
ffmpeg -i INPUT -an -pass 1 -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method dia -subq 1 -trellis 0 -refs 1 -bf 16 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -threads 0 OUTPUT.mp4
ffmpeg -i INPUT -acodec libfaac -ab 128k -pass 2 -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -flags2 +dct8x8+wpred+bpyramid+mixed_refs -me_method umh -subq 7 -trellis 1 -refs 6 -bf 16 -directpred 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -threads 0 OUTPUT.mp4
Note: I’ve altered the settings from the x264 CLI defaults according to Dark Shikari’s recommendations for x264. The quality settings can be considerably reduced for the first pass of two as it has little impact on the output of the second (or nth) pass.