Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do FFMPEG H264 compression presets affect the video quality? [closed]

Tags:

ffmpeg

I am definitely not an FFMPEG expert, but according to this document:

A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). General usage is to use the slowest preset that you have patience for. Current presets in descending order of speed are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo.

So as I understand it, the ffmpeg presets should not affect the quality of the output video, but should only determine the compression ratio / output file size. Consequently, assuming the same quality setting (I will use -crf 24), the files should be larger for e.g., faster preset than for the slower preset. That would be the only reason to use a slower preset - to get a smaller file size.

This turns out not to be the case. I encode a HD stream from a handycam using different presets, everything else is the same:

ffmpeg -y -i "$fname" -vf yadif=1,scale=-1:720 -acodec aac -ab 128k -ac 2 -strict experimental -vcodec libx264 -vpre slow -threads 2 -crf 24 "$outp"

Surprisingly, I get the smallest file size for veryfast preset! For example:

  • slower: output bitrate 3500kbps, encoding speed 17 fps, file size 29MB
  • veryfast: output bitrate 3050kbps, encoding speed 34 fps, file size 25MB

Which I think is not as it should be. Now I wonder, is that due to a worse encoding quality for the veryfast preset? Or in my case using slower does simply not make sense for some reason?

like image 562
angainor Avatar asked Jan 13 '13 17:01

angainor


People also ask

What is preset in ffmpeg?

FFmpeg preset is the value in which speed the media encode will traverse at, At the slower spectrum you get more quality at the sacrifice of time, more quicker and you get larger file sizes.

What is the best CRF for video?

Choose a CRF value Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn't technically lossless. The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate.

What does CRF do Ffmpeg?

The Constant Rate Factor or CRF is an option available in the libx264 encoder to set our desired output quality. It enables us to specify a target value that maps to a specific quality by adjusting the bitrates automatically based on the input video.


2 Answers

Yes, quality may vary slightly depending on the preset used, but it should not be a significant amount. Here's an excerpt from a discussion on #x264. Similar question to yours with answers provided by one of the x264 developers:

verb3k | Do different presets have an effect on quality when used with CRF?
@Dark_Shikari | verb3k: yes, but not too much.
@Dark_Shikari | a 0th-order approximation is that they have no effect.
@Dark_Shikari | The main reason there's a difference is because the preset affects how x264 itself measures quality
@Dark_Shikari | that is, it uses better, more accurate methods of measuring quality
@Dark_Shikari | obviously, this will affect the definition of what -crf does!
@Dark_Shikari | It's just not too much, so we can mostly ignore it.
@Dark_Shikari | specifically, there are three big things that can affect the definition of quality
@Dark_Shikari | 1) AQ being on/off
@Dark_Shikari | jump: ultrafast to superfast
@Dark_Shikari | 2) mbtree being on/off
@Dark_Shikari | jump: superfast to veryfast
@Dark_Shikari | 3) psy-rd being on/off
@Dark_Shikari | jump: faster to fast
@Dark_Shikari | above fast there are no more big jumps.

This means that a slower preset with the same CRF value will improve quality per bitrate, but might make both quality and bitrate higher or lower.

like image 58
llogan Avatar answered Sep 23 '22 02:09

llogan


If it helps here is a git diff from slower to veryfast. Even if you just consider the ref value you can see how veryfast could be lower quality.

ref
In short, this value is the number of previous frames each P-frame can use
as references.

source

--- a/slower
+++ b/veryfast
@@ -1,20 +1,20 @@
 cabac=1
-ref=8
+ref=1
 deblock=1:0:0
-analyse=0x3:0x133
-me=umh
-subme=9
+analyse=0x3:0x113
+me=hex
+subme=2
 psy=1
 psy_rd=1.00:0.00
-mixed_ref=1
+mixed_ref=0
 me_range=16
 chroma_me=1
-trellis=2
+trellis=0
 8x8dct=1
 cqm=0
 deadzone=21,11
 fast_pskip=1
-chroma_qp_offset=-2
+chroma_qp_offset=0
 threads=12
 lookahead_threads=2
 sliced_threads=0
@@ -25,17 +25,17 @@ bluray_compat=0
 constrained_intra=0
 bframes=3
 b_pyramid=2
-b_adapt=2
+b_adapt=1
 b_bias=0
-direct=3
+direct=1
 weightb=1
 open_gop=0
-weightp=2
+weightp=1
 keyint=250
 keyint_min=23
 scenecut=40
 intra_refresh=0
-rc_lookahead=60
+rc_lookahead=10
 rc=crf
 mbtree=1
 crf=23.0
like image 31
Zombo Avatar answered Sep 22 '22 02:09

Zombo