Search code examples
videoffmpegbitrate

ffmpeg: How to limit bit rate of video output?


To a 2GB raw video file taken in front of a greenscreen I want to add the alpha channel.

My problem is: the output files appear much too large to me (about 20-fold the size of the input), and OpenShot, the video editor, seems unable to handle such huge files. Comparing file properties of input and output shows bitrates of about 15k in the infiles, and 150k-250k in the result files, which seems to pinpoint the problem.

(By the way, I also want to discard the first part of the clip as well as its audio channel and reduce the frame rate from 30 to 24 fps in the process, which all works fine.)

This is my command:

ffmpeg.exe -i <in.MOV> -vf chromakey=0x007d06:0.15:0.0 -ss 40.420 -r 24 -b:v 15840k -maxrate 15840k -bufsize 15840k -an -c:v <encoder> <out.mov>

The parameters as I understand them:

-i <in.mov> ... infile
-vf chromakey=0x007d06:0.15:0.0 ... chroma, tolerance & blend of greenscreens
-ss 40.420 ... skip before second 40.420 (this works)
-r 24 ... frame rate (this works, too)
-b:v 15804k ... bitrate (seemingly no effect)
-maxrate 15840k ... maximum BitRate (seemingly no effect)
-bufzise 15840k ... Buffer size (can't tell)
-an ... no audio channel (works fine)
-c:v <encoder> ... Video Encoder (ffvhuff, png, qtrle and tiff were tried, all to the same result)
<out.mov> ... outfile

b, maxrate and bufsize are described as global options. No matter what setting, during the process bitrates of up to some 3000000kbits/s (tiff) are reported.

(I also added -pixel_format argb, but this, too, seemed to be ignored, ffmpeg always reports to write yuva420p.)

What am I missing?


Solution

  • All the encoders you tried are lossless. You can't set a bitrate for a lossless encoder.

    Try VP8/9 i.e. -c:v libvpx or libvpx-vp9 with a pixel format of -pix_fmt yuva420p. Remove the bitrate/maxrate/bufsize and set -crf N -b:v 0 where N can range from 0 to 63. Try with a value of 20. Go up/down for smaller/better video stream respectively.