Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am converting a video using the following command:

ffmpeg -i "input.avi" -vcodec mpeg4 -r 15 -sameq "output.avi"

However I'm only interested in the file size of output.avi. Is there a command I can give ffmpeg so that it doesn't actually write a file, but tells me how big it would be?

share|improve this question
up vote 6 down vote accepted

You can't really estimate the size the of a video file before encoding. This is not possible due to the way the codec works. It allocates a certain amount of bits to every frame, but this amount usually depends on the contents of the frame itself.

However, there are some solutions.

1. The cheap one:

Let it encode, check the file size and trash the file again

2. The "workaround":

Calculate the file size yourself using a simple calculator. This only works when using constant bit rate. Specify it with, for example, -b 500k for 500 kBit/s. You have to make sure that you specify a bit rate the codec can use. for example, there's no way to compress a 1080p video with 200k bit rate in mpeg4, because it would need much more than that.

3. The "real" solution:

The last option I had in mind was piping the output to /dev/null and measuring the piped file size. That, however, won't work for all formats, because FFmpeg needs a seekable file to produce valid output.

Still, for AVI, it works pretty well. The following command will pipe into /dev/null, thereby leaving no trace of the file itself, and finally output the encoded file size.

ffmpeg -i input.avi -vcodec mpeg4 -b 3M -f avi pipe:1 | pv > /dev/null

… for example like this:

5.42MB 0:00:10 [ 521kB/s]

What does it do?

  • You have to specify the format using -f avi. Otherwise FFmpeg won't know which format to use.
  • pipe:1 tells FFmpeg to write the output to a pipe.
  • We will feed this output into pipe viewer, short pv.
  • Pipe viewer will measure the transferred size and output your video to /dev/null.

The only minor drawback is that the output looks a bit weird until the video is finished. I haven't yet found a way to fully disable FFmpeg's output and get pv to work with this.

share|improve this answer
wow, thanks for the comprehensive answer slhck – Fidel Oct 24 '11 at 13:57

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.