Take the 2-minute tour ×
Video Production Stack Exchange is a question and answer site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation. It's 100% free, no registration required.

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':
    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 <speed> -vpre <profile>
[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.


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


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.

share|improve this question
Sure some folks simply want to know how to convert Avermedia .avi files .mp4 so they play on Mountain Lion/Mavericks <pre> ffmpeg -i 140203-1229.avi -vcodec copy -acodec copy fromavermedia_cog.mp4 </pre> –  user5544 Feb 6 '14 at 20:26

3 Answers 3

up vote 3 down vote accepted

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?

share|improve this answer
Thanks. Your talk about presets has helped me find a likely solution. I'll edit the post to show what I did. –  BigBeagle Apr 29 '12 at 22:04
Nice solution. Added to my collection of snippets. Thanks. –  Zettt May 1 '12 at 21:13
@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 Oct 22 '12 at 11:13

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.

share|improve this answer
The presets for libx264 are now specified by -preset as in -preset slow –  stib Feb 14 '14 at 5:48
-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 May 8 at 14:39

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

share|improve this answer
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 Apr 28 '13 at 8:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.