PDA

View Full Version : Optimal ffmpeg/x264 settings for general h264 for Flash, and some general questions


putnam
28th January 2008, 19:54
I am trying to encode a large variety of videos and want to come up with the best general-purpose x264 options (that won't require prior knowledge of the content). The target format will be MP4, to be played back in the new Flash Player with h264 support.

I started with the settings outlined in this guide (http://rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide/), which suggests the ffmpeg default options are far lower quality than the x264 CLI's defaults. The guide explains how to get ffmpeg back in line with x264's defaults.

Here are example command lines (straight from the guide linked above) for the first and second pass:

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


Things of note:

These videos will be consumed via progressive download, and it seems to me that a close-to-constant bitrate will result in the best user experience. It doesn't have to be completely constant, but can't have big spikes, either. I'm curious just how much variance there can be in VBR with x264.
This will replace On2's VP6 encoder, which for me has had very little quality gains with 2-pass vs. 1-pass. On the other hand it is pretty fast; even the most difficult videos complete their 1-pass encoding in no more than 1.5x-2x real time. However the quality gain with x264 will likely be substantial as we have much more granular control over each knob, and we are also willing to sacrifice more CPU time for every encode.
In many cases I am going to be scaling the videos down. I know there is some optimization to be had in using 8px or 16px multiples on each dimension, but this is commonly not possible while retaining aspect ratio.
I want to add more keyframes to ensure there are seek points with some frequency.
Any special encode options have to work in the Flash Player's implementation of AVC. It supports Base, Mainline, and High.
If there are any optimizations to be made for the architecture used, I'm using machines with dual Clovertown (that is, quad-core Xeon) processors and 8GB of RAM. I know that x264 has the ability to multithread encodes, but it seems simpler to have my encoding scripts spawn several individual encode jobs at the same time with one core apiece rather than run a single job occupying all eight cores.


Thanks for any suggestions or tips.

Dark Shikari
28th January 2008, 19:59
1. x264's 1-pass ratecontrol is pretty bad. Either use CRF for 1pass, or use 2pass bitrate mode.

2. It supports High Profile, so use High Profile features: i8x8 partitions, 8x8dct, etc. I'd also enable bime, raise subq to 6 or 7, enable weightb, and enable b-rdo.

3. x264's threading is extremely efficient. If you want to use it, there is no disadvantage to doing so.

putnam
29th January 2008, 02:23
2. It supports High Profile, so use High Profile features: i8x8 partitions, 8x8dct, etc. I'd also enable bime, raise subq to 6 or 7, enable weightb, and enable b-rdo.
Of these options, which ones can I skip in the first pass to save some time? I am currently running first pass with subq 1, then increase it in the second pass. Can I leave off weightb/bime/b-rdo in the first pass? I take it I need to leave partition searching the same.

Dark Shikari
29th January 2008, 02:25
Of these options, which ones can I skip in the first pass to save some time? I am currently running first pass with subq 1, then increase it in the second pass. Can I leave off weightb/bime/b-rdo in the first pass? I take it I need to leave partition searching the same.Nope, partitions can be entirely off with nearly no measurable loss. The only things that need to be the same in the first pass are B-pyramid settings, B-frame settings, Keyframe interval settings, and ratecontrol settings. I'd actually put subq to 3, as I've found for some reason that seems to give a small quality boost on the second pass.

LoRd_MuldeR
29th January 2008, 02:26
Of these options, which ones can I skip in the first pass to save some time? I am currently running first pass with subq 1, then increase it in the second pass. Can I leave off weightb/bime/b-rdo in the first pass? I take it I need to leave partition searching the same.

MEncoder suggests those:
* turbo=1 - Reduce subq, frameref and disable some inter-macroblock partition analysis modes.
* turbo=2 - Reduce subq and frameref to 1, use a diamond ME search and disable all partition analysis modes.

teddg
5th May 2008, 22:06
1. x264's 1-pass ratecontrol is pretty bad. Either use CRF for 1pass, or use 2pass bitrate mode.

2. It supports High Profile, so use High Profile features: i8x8 partitions, 8x8dct, etc. I'd also enable bime, raise subq to 6 or 7, enable weightb, and enable b-rdo.

I've applied the High Profiles settings and am happy with the results.

But I just ran into an odd thing - changing crf from 21 to 24 changed the file size by only 4KB on the last encode (598,264KB to 598,261KB). I'm used to crf having larger differences in output file sizes when switching from 24 to 21, but that was before adding the High Profile settings. The video looks fine, but I'm just wondering if something isn't working here, or if its normal for crf to sometimes do this?

Settings:
ffmpeg -i "C:\VTS_03_1.VOB" -r 29.97 -threads auto -vcodec h264 -croptop 54 -cropbottom 58 -s 704x304 -aspect 2.31578947 -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -crf 21 -bt 512k -refs 5 -bf 3 -b_strategy 1 -bidir_refine 1 -coder 1 -me umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -flags2 +brdo+mixed_refs+wpred+dct8x8+bpyramid -g 250 -keyint_min 25 -qmin 10 -qmax 51 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec aac -ab 128k -ar 48000 -ac 2 "C:\done.mp4"

nm
6th May 2008, 09:23
Try without -bt 512k

teddg
6th May 2008, 20:11
Try without -bt 512k

That seemed to fixed it, thanks.