<p>ffmpeg has removed their x264 presets so the -vpre setting doesn't work any more.</p>

<p>Now, I have a script for converting video files to a format my Cellphone can handle.</p>

<pre><code>ffmpeg -i input.avi -sws_flags lanczos+accurate_rnd -vf "scale=320:240" -c:v libx264 -crf 20 -preset veryslow -profile:v main -tune fastdecode -c:a copy output.mkv
</code></pre>

<p>I'll explain each option</p>

<p><code>-sws_flags lanczos+accurate_rnd</code> this option is the downscaling algorithm, lanczos is recommended as it produces the least artifacts without bluring but it is slow.</p>

<p><code>-vf "scale=..."</code> is self explanatory specify the output resolution</p>

<p><code>-crf 20</code> this is the quality, 20 is a good final (don't use it before editing) output setting, this is constant quality and is the best option when file size isn't tight and will produce better quality at lowest file size than anything else, otherwise use two pass for maximum quality at a specific file size(like needing to fit it on a CD or DVD), fixed bitrate (ex. <code>-b 2000k</code>) should only be used when streaming, a special case is '0' which is lossless and range of this option is from 1 (highest quality) to 50 (lowest quality).</p>

<p>A good test for this is to run through the encode with -crf 20 take note of the bitrate, and then use that as the -b setting for a 2nd version of the file both should be the same file size, compare the two for quality differences.</p>

<p><a href="http://mewiki.project357.com/wiki/X264_Settings#Presets"><code>-preset veryslow</code></a> this chooses how much CPU you want to use, the slower it is the smaller the file size and better quality.</p>

<p><code>-profile:v main</code> this is the <a href="http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Profiles">H.264 profile</a> to use. high is the most efficient file size wise but uses lots of CPU to decode compared to the other formats, that being said its the most popular as most cellphones have a hardware decoder built in and flash player supports it, mine does not so I have to use main.</p>

<p><code>-tune fastdecode</code> my cellphone doesn't like playing the files without this option, but usually this can be left blank or set to 'film' for videos games, the main reason you use this is to get a little extra quality.</p>

<p>And last thing I would highly recommend using a modern container format .avi isn't designed to hold H.264 and from what I understand there's no standard for storing H.264 or making the file larger than 2GB, most implementations are hacks and prone to have problems, use mkv or mp4.</p>

CC BY-SA 3.0
2014-02-14T05:48:23.177Z
The presets for libx264 are now specified by `-preset` as in `-preset slow`
stib
CC BY-SA 3.0
2015-05-08T14:39:13.907Z
`-tune fastdecode` disables deblocking, and weighted B and P frames, as well as CABAC.  There are decoders that can handle B frames, but not CABAC?  I would suggest `-profile:v baseline`, if you need to target old hardware decoders.  (`fastdecode` could be useful if targetting a software decoder on a slow CPU, but not a hardware decoder.)  Main with B frames but no deblocking or CABAC might or might not look better than baseline with deblocking.   +1 for recommending not-AVI for storing h.264.  IIRC, the main is B frames, but yeah h.264 in avi is not well standardized, and it's hacky.
Peter Cordes
CC BY-SA 4.0
2018-12-05T23:46:07.603Z
I'd call `-crf 20` a high final. You can change that to 22 or even 24 and probably be fine, unless it's high motion, like a sports event.
user3643
CC BY-SA 3.0
2012-11-18T12:09:14.187Z
2012-11-18T12:09:14.187Z
Daniel Hill
<p>There are some things to make clear:</p>

<ul>
<li>A format is <strong>not</strong> a codec; you want to get a file in avi <strong>format</strong> with video encoded with <strong>h264</strong> codec. Just use <em>-vcodec libx264</em> and a filename with <em>.avi</em>. Ffmpeg should recognize a format by looking at a file extension, but you may also be specific adding <em>-f avi</em>. You definetely <strong>not</strong> want to use mpeg1, because it gives worse quality than mpeg2 or even worse comparing with mpeg4, which I reccomend.</li>
<li>Your problem was that ffmpeg just used the lowest possible quality because you didn't specify any. The -sameq option rarely seems to work for me. In fact, it is very handful to set the bitrate manually. Add, for example, <em>-vb 3000k</em> to get a file with average <em>video</em> bitrate of 3Mb/s, which gives quite good quality. I guess it would be even enough for you to have 2Mb/s for the mentioned resolution.</li>
<li>The key to lowering filesize is not resolution, but bitrate mentioned above. I would rather stick to the original resolution and just manipulate the bitrate.</li>
<li>I guess you also want to keep the audio without conversion (so without quality loss), so use <em>-acodec copy</em>.</li>
</ul>

<p>Try this:
<em>ffmpeg -i highres.avi -acodec copy -vcodec libx264 -vb 2000k lowerres.avi</em></p>

CC BY-SA 3.0
2013-04-28T08:50:16.057Z
Constant bitrate is the worst (in terms of quality vs. size) of all rate control modes in x264 and should be avoided. Use `-crf` to set a constant quality mode instead.
slhck
CC BY-SA 3.0
2012-08-15T11:24:50.210Z
2012-08-15T11:24:50.210Z
Piotr
<p>I'm trying to help. First, I don't understand why you're saying FFMPEG H.264 is not the input format? </p>

<p>I don't know the FFMPEG command line well enough (is there anyone who does? ;)  ). There's got to be a switch for multipass encoding. I know there are some built-in presets you could probably use and do almost certainly what you're aiming for. These are normally called x264 presets or x264 tune. Can you find anything like that?</p>

CC BY-SA 3.0
2012-04-29T22:04:13.110Z
Thanks.  Your talk about presets has helped me find a likely solution.  I'll edit the post to show what I did.
BigBeagle
CC BY-SA 3.0
2012-05-01T21:13:21.090Z
Nice solution. Added to my collection of snippets. Thanks.
Zettt
CC BY-SA 3.0
2012-10-22T11:13:40.340Z
@BigBeagle: When you find an answer to your question, you can post it as an answer. Editing your question is done to provide more clarity to the question. As I understand, answers go in the answer section.
Nav
CC BY-SA 3.0
2012-04-29T20:51:41.350Z
2012-04-29T20:51:41.350Z
Zettt
<p>I'm a complete noob to video editing, so forgive me if I ask for something ridiculous.</p>

<p>I'm getting video clips from a set top recorder box.  The clips are AVI files:</p>

<pre><code>Resolution: 1920 x 1080
Frames Per Second: 60
Video Format: ITU H.264
Audio Format: MPEG 1 Audio, Layer 3 (MP3)
</code></pre>

<p>The resolution and FPS are well beyond what I require, so I'm trying to run a command to scale things down:</p>

<pre><code>ffmpeg -i highres.avi -r 30 -s 960x540 lowerres.avi
</code></pre>

<p>This is successful in giving me the desired resolution, framerate and lower file size, but it also degraded the quality way more than I expected.</p>

<p>I looked at the new file, and found that for some reason FFmpeg converted the format used:</p>

<pre><code>Video Format: FFmpeg MPEG-4
Audio Format: MPEG 1 Audio, Layer 2
</code></pre>

<p>It's unclear to me why it wouldn't use the same output formats as input formats.  I tried to use this command to force it to use H.264:</p>

<pre><code>ffmpeg -i highres.avi -r 30 -s 960x540 -f h264 lowerresforceh264.avi
</code></pre>

<p>Unfortunately, it failed with the following output:</p>

<pre><code>ffmpeg version 0.7.3-4:0.7.3-0ubuntu0.11.10.1, Copyright (c) 2000-2011 the Libav developers
  built on Jan  4 2012 16:21:50 with gcc 4.6.1
  configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  WARNING: library configuration mismatch
  avutil      configuration: --extra-version='4:0.7.3ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-libopenjpeg --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdirac --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libxvid --enable-libvo-aacenc --enable-version3 --enable-libvo-amrwbenc --enable-version3 --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avcodec     configuration: --extra-version='4:0.7.3ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-libopenjpeg --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdirac --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libxvid --enable-libvo-aacenc --enable-version3 --enable-libvo-amrwbenc --enable-version3 --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avformat    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avdevice    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avfilter    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  swscale     configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  postproc    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libavutil    51.  7. 0 / 51.  7. 0
  libavcodec   53.  6. 0 / 53.  6. 0
  libavformat  53.  3. 0 / 53.  3. 0
  libavdevice  53.  0. 0 / 53.  0. 0
  libavfilter   2.  4. 0 /  2.  4. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  52.  0. 0 / 52.  0. 0
Input #0, avi, from 'highres.avi':
  Metadata:
    comment         : Quality_GOOD
    encoder         : Lavf52.64.2
    encoded_by      : AverMedia_c281_1.7.2
  Duration: 00:01:59.28, start: 0.000000, bitrate: 10263 kb/s
    Stream #0.0: Video: h264 (High), yuv420p, 1920x1080, 59.94 fps, 59.94 tbr, 59.94 tbn, 119.88 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s
[buffer @ 0x8f438a0] w:1920 h:1080 pixfmt:yuv420p
[scale @ 0x8f431e0] w:1920 h:1080 fmt:yuv420p -&gt; w:960 h:540 fmt:yuv420p flags:0x4
[libx264 @ 0x8f0fb40] broken ffmpeg default settings detected
[libx264 @ 0x8f0fb40] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0x8f0fb40] preset usage: -vpre &lt;speed&gt; -vpre &lt;profile&gt;
[libx264 @ 0x8f0fb40] speed presets are listed in x264 --help
[libx264 @ 0x8f0fb40] profile is optional; x264 defaults to high
Output #0, h264, to 'lowerresforceh264.avi':
    Stream #0.0: Video: libx264, yuv420p, 960x540, q=2-31, 200 kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0.0 -&gt; #0.0
Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height
</code></pre>

<p>I'm not sure why I can't do this.  Running "ffmpeg -formats" listed h264 as one it could use for both input and output.</p>

<p>If anyone could point me in the right direction, I'd appreciate it greatly.  Thanks.</p>

<p>PS: I'm using FFmpeg version 0.7.3-4:0.7.3-0 on Ubuntu 11.10.</p>

<p>EDIT</p>

<p>I've found a solution looking at the use of presets.  After looking for information about presets, I found the following tutorial discussing them:</p>

<p><a href="http://juliensimon.blogspot.com/2009/01/howto-ffmpeg-x264-presets.html">http://juliensimon.blogspot.com/2009/01/howto-ffmpeg-x264-presets.html</a></p>

<p>I just needed to specify the codec and the proper preset setting like so:</p>

<pre><code>ffmpeg -i highres.avi -r 30 -s 960x540 -vcodec libx264 -vpre medium lowerresforceh264vpremedium.avi
</code></pre>

<p>I still have some tweaking to do, but this is basically what I wanted.  Thanks.</p>

<conversion><ffmpeg>
How can I use FFmpeg to lower the quality of H264 video but keep it in H264 format?
BigBeagle
# How can I use FFmpeg to lower the quality of H264 video but keep it in H264 format?

(Asked by: username_0 on 2012-04-29)

I'm a complete noob to video editing, so forgive me if I ask for something ridiculous.
I'm getting video clips from a set top recorder box.  The clips are AVI files:
Resolution: 1920 x 1080
Frames Per Second: 60
Video Format: ITU H.264
Audio Format: MPEG 1 Audio, Layer 3 (MP3)

The resolution and FPS are well beyond what I require, so I'm trying to run a command to scale things down:
ffmpeg -i highres.avi -r 30 -s 960x540 lowerres.avi

This is successful in giving me the desired resolution, framerate and lower file size, but it also degraded the quality way more than I expected.
I looked at the new file, and found that for some reason FFmpeg converted the format used:
Video Format: FFmpeg MPEG-4
Audio Format: MPEG 1 Audio, Layer 2

It's unclear to me why it wouldn't use the same output formats as input formats.  I tried to use this command to force it to use H.264:
ffmpeg -i highres.avi -r 30 -s 960x540 -f h264 lowerresforceh264.avi

Unfortunately, it failed with the following output:
ffmpeg version 0.7.3-4:0.7.3-0ubuntu0.11.10.1, Copyright (c) 2000-2011 the Libav developers
  built on Jan  4 2012 16:21:50 with gcc 4.6.1
  configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  WARNING: library configuration mismatch
  avutil      configuration: --extra-version='4:0.7.3ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-libopenjpeg --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdirac --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libxvid --enable-libvo-aacenc --enable-version3 --enable-libvo-amrwbenc --enable-version3 --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avcodec     configuration: --extra-version='4:0.7.3ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-libopenjpeg --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdirac --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libxvid --enable-libvo-aacenc --enable-version3 --enable-libvo-amrwbenc --enable-version3 --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avformat    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avdevice    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  avfilter    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  swscale     configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  postproc    configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=i386 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libavutil    51.  7. 0 / 51.  7. 0
  libavcodec   53.  6. 0 / 53.  6. 0
  libavformat  53.  3. 0 / 53.  3. 0
  libavdevice  53.  0. 0 / 53.  0. 0
  libavfilter   2.  4. 0 /  2.  4. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  52.  0. 0 / 52.  0. 0
Input #0, avi, from 'highres.avi':
  Metadata:
    comment         : Quality_GOOD
    encoder         : Lavf52.64.2
    encoded_by      : AverMedia_c281_1.7.2
  Duration: 00:01:59.28, start: 0.000000, bitrate: 10263 kb/s
    Stream #0.0: Video: h264 (High), yuv420p, 1920x1080, 59.94 fps, 59.94 tbr, 59.94 tbn, 119.88 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s
[buffer @ 0x8f438a0] w:1920 h:1080 pixfmt:yuv420p
[scale @ 0x8f431e0] w:1920 h:1080 fmt:yuv420p -> w:960 h:540 fmt:yuv420p flags:0x4
[libx264 @ 0x8f0fb40] broken ffmpeg default settings detected
[libx264 @ 0x8f0fb40] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0x8f0fb40] preset usage: -vpre  -vpre 
[libx264 @ 0x8f0fb40] speed presets are listed in x264 --help
[libx264 @ 0x8f0fb40] profile is optional; x264 defaults to high
Output #0, h264, to 'lowerresforceh264.avi':
    Stream #0.0: Video: libx264, yuv420p, 960x540, q=2-31, 200 kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

I'm not sure why I can't do this.  Running "ffmpeg -formats" listed h264 as one it could use for both input and output.
If anyone could point me in the right direction, I'd appreciate it greatly.  Thanks.
PS: I'm using FFmpeg version 0.7.3-4:0.7.3-0 on Ubuntu 11.10.
EDIT
I've found a solution looking at the use of presets.  After looking for information about presets, I found the following tutorial discussing them:
http://juliensimon.blogspot.com/2009/01/howto-ffmpeg-x264-presets.html
I just needed to specify the codec and the proper preset setting like so:
ffmpeg -i highres.avi -r 30 -s 960x540 -vcodec libx264 -vpre medium lowerresforceh264vpremedium.avi

I still have some tweaking to do, but this is basically what I wanted.  Thanks.

**Tags:** conversion, ffmpeg


---

## 3 answers

### Answer by username_7 on 2012-04-29. Score: 3 | Accepted answer

I'm trying to help. First, I don't understand why you're saying FFMPEG H.264 is not the input format?

I don't know the FFMPEG command line well enough (is there anyone who does? ;) ). There's got to be a switch for multipass encoding. I know there are some built-in presets you could probably use and do almost certainly what you're aiming for. These are normally called x264 presets or x264 tune. Can you find anything like that?

> **Comments:**
> **username_0**: Thanks.  Your talk about presets has helped me find a likely solution.  I'll edit the post to show what I did.  
> **username_7**: Nice solution. Added to my collection of snippets. Thanks.  
> **username_8**: @username_0: When you find an answer to your question, you can post it as an answer. Editing your question is done to provide more clarity to the question. As I understand, answers go in the answer section.  

---

### Answer by username_1 on 2012-11-18. Score: 9

ffmpeg has removed their x264 presets so the -vpre setting doesn't work any more.
Now, I have a script for converting video files to a format my Cellphone can handle.
ffmpeg -i input.avi -sws_flags lanczos+accurate_rnd -vf "scale=320:240" -c:v libx264 -crf 20 -preset veryslow -profile:v main -tune fastdecode -c:a copy output.mkv

I'll explain each option
-sws_flags lanczos+accurate_rnd this option is the downscaling algorithm, lanczos is recommended as it produces the least artifacts without bluring but it is slow.
-vf "scale=..." is self explanatory specify the output resolution
-crf 20 this is the quality, 20 is a good final (don't use it before editing) output setting, this is constant quality and is the best option when file size isn't tight and will produce better quality at lowest file size than anything else, otherwise use two pass for maximum quality at a specific file size(like needing to fit it on a CD or DVD), fixed bitrate (ex. -b 2000k) should only be used when streaming, a special case is '0' which is lossless and range of this option is from 1 (highest quality) to 50 (lowest quality).
A good test for this is to run through the encode with -crf 20 take note of the bitrate, and then use that as the -b setting for a 2nd version of the file both should be the same file size, compare the two for quality differences.
-preset veryslow this chooses how much CPU you want to use, the slower it is the smaller the file size and better quality.
-profile:v main this is the H.264 profile to use. high is the most efficient file size wise but uses lots of CPU to decode compared to the other formats, that being said its the most popular as most cellphones have a hardware decoder built in and flash player supports it, mine does not so I have to use main.
-tune fastdecode my cellphone doesn't like playing the files without this option, but usually this can be left blank or set to 'film' for videos games, the main reason you use this is to get a little extra quality.
And last thing I would highly recommend using a modern container format .avi isn't designed to hold H.264 and from what I understand there's no standard for storing H.264 or making the file larger than 2GB, most implementations are hacks and prone to have problems, use mkv or mp4.

> **Comments:**
> **username_2**: The presets for libx264 are now specified by `-preset` as in `-preset slow`  
> **username_3**: `-tune fastdecode` disables deblocking, and weighted B and P frames, as well as CABAC.  There are decoders that can handle B frames, but not CABAC?  I would suggest `-profile:v baseline`, if you need to target old hardware decoders.  (`fastdecode` could be useful if targetting a software decoder on a slow CPU, but not a hardware decoder.)  Main with B frames but no deblocking or CABAC might or might not look better than baseline with deblocking.   +1 for recommending not-AVI for storing h.264.  IIRC, the main is B frames, but yeah h.264 in avi is not well standardized, and it's hacky.  
> **username_4**: I'd call `-crf 20` a high final. You can change that to 22 or even 24 and probably be fine, unless it's high motion, like a sports event.  

---

### Answer by username_5 on 2012-08-15. Score: 2

There are some things to make clear:

* A format is **not** a codec; you want to get a file in avi **format** with video encoded with **h264** codec. Just use *-vcodec libx264* and a filename with *.avi*. Ffmpeg should recognize a format by looking at a file extension, but you may also be specific adding *-f avi*. You definetely **not** want to use mpeg1, because it gives worse quality than mpeg2 or even worse comparing with mpeg4, which I reccomend.
* Your problem was that ffmpeg just used the lowest possible quality because you didn't specify any. The -sameq option rarely seems to work for me. In fact, it is very handful to set the bitrate manually. Add, for example, *-vb 3000k* to get a file with average *video* bitrate of 3Mb/s, which gives quite good quality. I guess it would be even enough for you to have 2Mb/s for the mentioned resolution.
* The key to lowering filesize is not resolution, but bitrate mentioned above. I would rather stick to the original resolution and just manipulate the bitrate.
* I guess you also want to keep the audio without conversion (so without quality loss), so use *-acodec copy*.

Try this:
*ffmpeg -i highres.avi -acodec copy -vcodec libx264 -vb 2000k lowerres.avi*

> **Comments:**
> **username_6**: Constant bitrate is the worst (in terms of quality vs. size) of all rate control modes in x264 and should be avoided. Use `-crf` to set a constant quality mode instead.  

---

