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 29MBveryfast
: output bitrate 3050kbps, encoding speed 34 fps, file size 25MBWhich 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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With