Changes between Version 56 and Version 57 of Encode/H.264
- Timestamp:
- Nov 18, 2016, 9:07:40 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Encode/H.264
v56 v57 82 82 As with CRF, choose the slowest preset you can tolerate. 83 83 84 In pass 1 specify a output format (with "-f") that matches the output format in pass 2. Also in pass 1, specify the audio codec used in pass 2; in many cases "-an" in pass 1 will not work. 84 In pass 1 specify a output format with `-f` that matches the output format in pass 2. Also in pass 1, specify the audio codec used in pass 2; in many cases `-an` in pass 1 will not work. 85 86 {{{#!comment 87 In which cases is the above true? 88 }}} 85 89 86 90 See [http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-dvd-mpeg4.html Making a high quality MPEG-4 ("DivX") rip of a DVD movie]. It is an MEncoder guide, but it will give you an insight about how important it is to use two-pass when you want to efficiently use every bit when you're constrained with storage space. … … 90 94 == Lossless H.264 == 91 95 92 You can use `-qp 0` or `-crf 0` to encode a lossless output. Use of `-qp` is recommended over `-crf` for lossless because 8-bit and 10-bit x264 use different `-crf` values for lossless. Two useful presets for this are `ultrafast` or `veryslow` since either a fast encoding speed or best compression are usually the most important factors. Most non-FFmpeg based players will not be able to decode lossless (but !YouTube can), so if compatibility is an issue you should not use lossless. 96 You can use `-crf 0` to encode a lossless output. Two useful presets for this are `ultrafast` or `veryslow` since either a fast encoding speed or best compression are usually the most important factors. Most non-FFmpeg based players will not be able to decode lossless (but !YouTube can), so if compatibility is an issue you should not use lossless. 97 98 Note that lossless output files will likely be huge. 93 99 94 100 === Lossless Example (fastest encoding) === 95 101 96 102 {{{ 97 ffmpeg -i input -c:v libx264 -preset ultrafast - qp0 output.mkv103 ffmpeg -i input -c:v libx264 -preset ultrafast -crf 0 output.mkv 98 104 }}} 99 105 … … 102 108 103 109 {{{ 104 ffmpeg -i input -c:v libx264 -preset veryslow - qp0 output.mkv110 ffmpeg -i input -c:v libx264 -preset veryslow -crf 0 output.mkv 105 111 }}} 106 112 … … 121 127 == Additional Information & Tips == 122 128 123 === ABR (Average Bit Rate) ===124 125 {{{126 ffmpeg -i input -c:v libx264 -b:v 1000k output.mp4127 }}}128 129 This provides something of a "running average" target, with the end goal that the final file match this number "overall on average" (so basically, if it gets a lot of black frames, which cost very little, it will encode them with less than the requested bitrate, but then the next few seconds of (non-black) frames it will encode at very high quality, to bring the average back in line). Using 2-pass can help this method to be more effective. You can also use this in combination with a "max bit rate" setting in order to prevent some of the swings.130 131 129 === CBR (Constant Bit Rate) === 132 130 … … 143 141 === CRF with maximum bit rate === 144 142 145 You can also also use a crf with a maximum bit rate by specifying both crf *and* maxrate settings, like143 You can also also use `-crf` with a maximum bit rate by specifying both `-crf` and `-maxrate`: 146 144 {{{ 147 145 ffmpeg -i input -c:v libx264 -crf 20 -maxrate 400k -bufsize 1835k output.mp4 148 146 }}} 149 147 150 This will effectively "target" crf 20, but if the output exceeds 400kb/s, it will degrade to something less than crf 20in that case.148 This will effectively "target" `-crf 20`, but if the output exceeds 400kb/s, it will degrade to something less than `-crf 20` in that case. 151 149 152 150 === Low Latency === … … 158 156 ==== All devices ==== 159 157 160 If you want your videos to have highest compatibility with target devices (older iOS versions or all Android devices):158 If you want your videos to have highest compatibility with older devices: 161 159 162 160 {{{ … … 164 162 }}} 165 163 166 This disables some advanced features but provides for better compatibility. Typically you may not need this setting (and therefore avoid using `-profile:v` and `-level`), but if you do use this setting it may increase the bit rate quite a bitcompared to what is needed to achieve the same quality in higher profiles.164 This disables some advanced features but provides for better compatibility. Typically you may not need this setting (and therefore avoid using `-profile:v` and `-level`), but if you do use this setting it may increase the bit rate compared to what is needed to achieve the same quality in higher profiles. 167 165 168 166 ==== iOS ==== … … 180 178 {{{ 181 179 #!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;" 182 * This table does not include any additional restrictions which may be required by your device. 183 * `-level` may not set the correct number of reference frames (`-refs`) if you're using an older build. See ticket #3307. 184 }}} 185 186 ==== Apple Quicktime ==== 187 188 Apple !QuickTime only supports YUV planar color space with 4:2:0 chroma subsampling (use `-pix_fmt yuv420p`) for H.264 video. For information on additional restrictions see [http://mewiki.project357.com/wiki/X264_Encoding_Suggestions#QuickTime-compatible_Encoding QuickTime-compatible Encoding]. 180 '''Note:''' This table does not include any additional restrictions which may be required by your device. 181 }}} 182 183 ==== !QuickTime ==== 184 185 !QuickTime only supports YUV planar color space with 4:2:0 chroma subsampling (use `-vf format=yuv420p` or `-pix_fmt yuv420p`) for H.264 video. 189 186 190 187 ==== Blu-ray ==== … … 194 191 === Pre-testing your settings === 195 192 196 Encode a random section instead of the whole video with the `-ss` and `-t` options to quickly get a general idea of what the output will look like. 193 Encode a random section instead of the whole video with the `-ss` and `-t`/`-to` options to quickly get a general idea of what the output will look like. 194 197 195 * `-ss`: Offset time from beginning. Value can be in seconds or HH:MM:SS format. 198 * `-t`: Output duration. Value can be in seconds or HH:MM:SS format. 196 * `-t`: Duration. Value can be in seconds or HH:MM:SS format. 197 * `-to`: Stop writing the output at specified position. Value can be in seconds or HH:MM:SS format. 199 198 200 199 === `faststart` for web video === … … 203 202 204 203 === Custom preset file === 205 Add `-fpre or -vpre` output option. 206 207 First ffmpeg searches for a file named arg.ffpreset in the directories `$FFMPEG_DATADIR` (if set), and `$HOME/.ffmpeg`, and in the datadir defined at configuration time (usually PREFIX/share/ffmpeg) or in a ffpresets folder along the executable on win32, in that order. For example, if the argument is libx264-1080p, it will search for the file libx264-1080p.ffpreset. 204 205 Refer to the `-vpre` output option in the [https://ffmpeg.org/ffmpeg.html#Preset-files documentation]. 206 208 207 ---- 209 208 … … 211 210 212 211 === Will two-pass provide a better quality than CRF? === 212 213 213 [http://web.archive.org/web/20140206073211/http://doom10.org/index.php?PHPSESSID=okj08qe73ictdtv532augv8nu7&topic=267.msg2071#msg2071 No], though it does allow you to target a file size more accurately. 214 214 … … 223 223 === Will a graphics card make x264 encode faster? === 224 224 225 Not necessarily. [http://git.videolan.org/?p=x264.git;a=commit;h=3a5f6c0aeacfcb21e7853ab4879f23ec8ae5e042 x264 supports OpenCL] for some lookahead operations. There are also some proprietary encoders that utilize the GPU, but that does not mean they are well optimized, though encoding time may be faster; and they might be [http://phoronix.com/forums/showthread.php?50697-Test-tool-for-snb-h264-encoder-in-libva-git&p=205580#post205580 worse than vanilla x264], and possibly slower. Regardless, FFmpeg today doesn't support any means of GPU encoding, outside of libx264. 225 For x264 specifically, probably not. [http://git.videolan.org/?p=x264.git;a=commit;h=3a5f6c0aeacfcb21e7853ab4879f23ec8ae5e042 x264 supports OpenCL] for some lookahead operations. 226 227 See [[HWAccelIntro]] for information on supported hardware based H.264 encoders and decoders. 226 228 227 229 === Encoding for dumb players === 228 230 229 You may need to use `- pix_fmt yuv420p` for your output to work in !QuickTime and most other players. These players only supports the YUV planar color space with 4:2:0 chroma subsampling for H.264 video. Otherwise, depending on your source, ffmpegmay output to a pixel format that may be incompatible with these players.231 You may need to use `-vf format=yuv420p` (or the alias `-pix_fmt yuv420p`) for your output to work in !QuickTime and most other players. These players only supports the YUV planar color space with 4:2:0 chroma subsampling for H.264 video. Otherwise, depending on your source, `ffmpeg` may output to a pixel format that may be incompatible with these players. 230 232 231 233 ---- … … 233 235 == Additional Resources == 234 236 235 * [http://en.wikibooks.org/wiki/MeGUI/x264_Settings x264 Settings - MeWiki] (outdated, doesn't even mention presets)236 * [http://en.wikibooks.org/wiki/MeGUI/x264_Settings/x264_Encoding_Suggestions x264 Encoding Suggestions - MeWiki]237 237 * [http://slhck.info/articles/crf Constant Rate Factor Guide]