FFmpeg x264 Encoding Guide

Source: Internet
Author: User
Tags subq
FFmpeg x264 Encoding Guide

Encoding H.264 in FFMPEG

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 hex -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1

Rate Control methods available:

  • Constant quantisation Parameter
  • Constant rate factor
  • One pass average bit rate
  • Two Pass Variable Bit Rate

CQP mode is mostly deprecated by CRF as CRF maintains more constant quality which was usually the aim of someone using CQP mode. if you care more about quality than bit rate then I wocould recommend using one pass CRF to save yourself a bit of time. evaluate various rate factors between about 25 and 15 (a lower value is higher quality and higher bit rate) until you find a quality level/approximate bit rate with which you're happy and then you can use that value forever more.

One pass average bit rate is good if you need to aim for an approximate bit rate but don't have time to run two passes, but if you have the time then two passes are recommended as the bits will be better distributed to maintain constant quality.

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 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4

So if you wanted to encode using two-pass VBR, the command line wocould be something like:

ffmpeg -i INPUT -an -pass 1 -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me epzs -subq 1 -trellis 0 -refs 1 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 OUTPUT.mp4

ffmpeg -i INPUT -acodec libfaac -ab 128k -pass 2 -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 OUTPUT.mp4

Note: I 've altered the settings from the x264 CLI ults. the quality settings can be considerably forced CED for the first pass of two as it has little impact on the output of the second (or NTH) Pass.

Some general notes for x264 options in FFMPEG that are not self-explanatory:

* Me methods {for-me name}: EPZs (also known as Dia but called EPZs in FFMPEG), Hex, umh, full (also known as ESA)
* Entropy coders {name (N for-coder n)}: cavlc (0), cabac (1)
* I _qfactor = I _frame_qp/p_frame_qp = 1/ipratio (note that this is not the same as 'ipratio 'from the x264 cli)
* Bit rate tolerance: bt = bit_rate * ratetol ('ratetol 'is the related parameter from the x264 cli)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.