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.
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.