14

I see there are videos on youtube with 1080p resolution that are more than 10 minutes long and only 50-60 mb in size.

I have a video only 3 minutes long and only 720p resolution but unable to bring it down below 90mb in size.

I checked another answer here on reducing size. Tried changing bitrate using ffmpeg -i input.mp4 -b 1000000 output.mp4

also tried ffmpeg -i input.mp4 -vcodec libx265 -crf 20 output.mp4 Tried changing -crf between 18 to 24, used both libx264,265 but it all resulted in nearly same output size, sometimes it even got bigger instead of smaller.

6
  • Which codec do those very small videos use? support.google.com/youtube/troubleshooter/2888402?hl=en-GB shows HEVC (h.265) is permitted, and it is very efficient at compression. Also, typically, audio is 1/3 of file size; which audio codec with which parameters do those very small files use?
    – K7AAY
    Jul 22, 2019 at 17:50
  • No YouTube access at work, sorry. However, you can download the videos with https://www.computerhope.com/issues/ch001724.htm then open them with VLC to find the codecs used. AV1 evilmartians.com/chronicles/better-web-video-with-av1-codec is also a new codec which offers even greater compression than HEVC (h.265).
    – K7AAY
    Jul 23, 2019 at 15:24
  • 1
    Ok I found the issue, those youtube videos were using lower bitrates. After changing bitrate to 1000kb, got it to 50 mb with a slight loss of quality.
    – Sanchit
    Jul 25, 2019 at 15:09
  • You may turn that into an answer if you wish, by explaining what tool you used to find the bit rates, and how you adjusted the videos to reduce the file size, as well as the result, so others may benefit. This will elevate your standing here, and I have found I get quicker and more meaningful answers to my questions when I earned more points.
    – K7AAY
    Jul 25, 2019 at 15:50
  • 1
    try: ffmpeg -i input.mp4 -vcodec libx264 -s hd720 -crf 35 -vf output.mp4 as adjust the -crf __ value
    – KetZoomer
    Oct 5, 2020 at 19:37

1 Answer 1

12

I had a pretty good experience with the h265 codec.

The output videos were between 2-8x smaller in size, without any noticeable loss in quality.

ffmpeg -i input.mkv -c:v libx265 -vtag hvc1 -c:a copy output.mkv

If you want to further reduce the filesize, x265 supports CRF and two different target bitrate algorithms:

Similar to x264, the x265 encoder has multiple rate control algorithms, including:

  • 1-pass target bitrate (by setting -b:v)
  • 2-pass target bitrate
  • Constant Rate Factor (CRF)

CRF:

While the bitrate is variable with CRF, the quality is pretty much the same from frame to frame.

The CRF can be any value between 0 and 51, where lower values would result in higher quality. What you want to do would be to set a relatively high CRF. This of course makes the quality worse.

  • Choose a CRF. CRF affects the quality. The default is 28, and it should visually correspond to libx264 video at CRF 23, but result in about half the file size. CRF works just like in x264, so choose the highest value that provides an acceptable quality.

  • Choose a preset. The default is medium. The preset determines compression efficiency and therefore affects encoding speed. Valid presets are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, and placebo. Use the slowest preset you have patience for. Ignore placebo as it provides insignificant returns for a significant increase in encoding time.

  • Choose a tune (optional). By default, this is disabled, and it is generally not required to set a tune option. x265 supports the following -tune options: psnr, ssim, grain, zerolatency, fastdecode. They are explained in the H.264 guide.

CRF Example

ffmpeg -i input -c:v libx265 -crf 28 -preset slower -c:a copy output.mp4

Note that in the example we simply copy the audio stream. You could also transcode the audio stream to save an additional few MBs.

2
  • This answer is great! Thank very much. Do I understand it well that recording with high CRF requires more CPU resources? Is it reasonable to use ultrafast encoding and eventually post-process for smaller files? (Or should I post a separate question?:) Apr 26, 2022 at 18:40
  • 2
    @PrimoPetri Note: you should use encoding time instead of CPU load as a metric as ffmpeg will use all available resources. A lower CRF will result in more data being processed and therefore in a longer encoding duration. It is not clear what you mean by postprocessing, better create a dedicated question. You can link me there in the comments via @mashuptwice Apr 26, 2022 at 22:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .