Filesize and x264 Preset

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
-gb-
Posts: 5
Joined: Sat Mar 05, 2016 6:20 pm

Filesize and x264 Preset

Post by -gb- »

Hello,
I recently tested with which x264 Preset I will get the smallest Files. So I set RF to 20 and encoded the same input file with all different x264 Preset settings.
Ultrafast results in a very large file, superfast is around the half file size from ultrafast but still large. Veryfast is again a lot smaller. But then something strange happens, from veryfast to slower the filesize rises. just a bit but it gets larger. Then from slower to placebo the size shrings again bit just a very tiny bit. So in the end I get the smallest file at x264 Preset settung "veryfast".
This is strange so I changed the RF setting but it was always the same.
Can anyone explain this?

I encode a 1440x1080 mpeg2 .M2T to 1280x960 h264 .mkv and just changed RF and x264 Preset.
The machine is a HP Server with two Quadcore Xeons and 24GB RAM.

Thank You!
rollin_eng
Veteran User
Posts: 4854
Joined: Wed May 04, 2011 11:06 pm

Re: Filesize and x264 Preset

Post by rollin_eng »

Could you please post your logs, instructions can be found here:

viewtopic.php?f=6&t=31236
tlindgren
Bright Spark User
Posts: 260
Joined: Sun May 03, 2009 2:14 pm

Re: Filesize and x264 Preset

Post by tlindgren »

-gb- wrote:Hello,
I recently tested with which x264 Preset I will get the smallest Files. So I set RF to 20 and encoded the same input file with all different x264 Preset settings.
-gb- wrote:So in the end I get the smallest file at x264 Preset settung "veryfast".
This is strange so I changed the RF setting but it was always the same.
Can anyone explain this?
You're assuming the same RF will always give the same quality regardless of other settings, THIS IS INCORRECT ASSUMPTION. It's probably not even possible to make a value that does that!

RF is a quality approximation that attempts to give somewhat similar quality, especially if you don't change encoder settings. As you change profile and/or settings this RF/quality correspondence gets less and less "close".

It's well known that at a constant RF, the file-size will usually go up slightly between very-fast and slower, due to enabling features that uses a few extra bits but is worth it because the quality improvement can be significant. There are many options in x264 that are like that so it also happens at other encoder setting changes.

In theory they could try to compensate for this by adjusting how RF is used but the reality is that none of them are really constant, it all depends on the video being encoded. I suspect it was looked at and a decision was taken that any tweak they made wouldn't really improve things enough to be worthwhile and would likely make people even more prone to bad assumptions.

Complicating things is that there's no real good metric for "encoder quality", PSNR is often used but is total crap! (it rewards blurring), the various SSIM measures are better but even they tend go the wrong way with all of the psycho-visual options (IE, enabling them makes SSIM measure indicates that the quality went down but viewers would say that the quality went up because the choices are based on how the human eye and/or brain works).
-gb-
Posts: 5
Joined: Sat Mar 05, 2016 6:20 pm

Re: Filesize and x264 Preset

Post by -gb- »

Thank You very much! I didn't know this fact. So i will go on and choose slower preset.
nhyone
Bright Spark User
Posts: 252
Joined: Fri Jul 24, 2015 4:13 am

Re: Filesize and x264 Preset

Post by nhyone »

One question, -gb-. Is the file size from slower preset larger than that from slow preset?
-gb-
Posts: 5
Joined: Sat Mar 05, 2016 6:20 pm

Re: Filesize and x264 Preset

Post by -gb- »

Code: Select all

              16      20      24     28     32     36
veryslow  | 243,0 |  80,9 |  36,3 | 21,7 | 15,7 | 12,4
slower    | 271,0 |  91,3 |  38,8 | 22,5 | 16,1 | 12,6
slow      | 260,3 |  92,2 |  39,0 | 22,7 | 16,2 | 12,6
medium    | 256,7 |  89,4 |  38,0 | 22,3 | 16,0 | 12,4
fast      | 257,2 |  87,5 |  36,5 | 21,0 | 14,7 | 11,3
faster    | 239,9 |  78,6 |  33,4 | 20,0 | 14,2 | 11,0
veryfast  | 239,6 |  69,3 |  28,2 | 17,1 | 12,2 |  9,5
superfast | 592,4 | 230,0 |  64,3 | 25,6 | 15,5 | 11,1
ultrafast | 734,2 | 334,3 | 113,1 | 52,2 | 28,1 | 16,9
rollin_eng
Veteran User
Posts: 4854
Joined: Wed May 04, 2011 11:06 pm

Re: Filesize and x264 Preset

Post by rollin_eng »

Do you have a log for one of these?
-gb-
Posts: 5
Joined: Sat Mar 05, 2016 6:20 pm

Re: Filesize and x264 Preset

Post by -gb- »

No, sorry. But i could run one again at the same machine with the same file and same settings.

So here the Log:

Code: Select all

[16:23:39] gtkgui: HandBrake rev5474 (2014032499) - Linux x86_64 - http://handbrake.fr
[16:23:40] hb_init: starting libhb thread
[16:23:40] hb_init: starting libhb thread
libdvdread: Encrypted DVD support unavailable.
************************************************
**                                            **
**  No css library available. See             **
**  /usr/share/doc/libdvdread4/README.css     **
**  for more information.                     **
**                                            **
************************************************
[16:23:47] hb_scan: path=/media/nas/gustl/hb_bench/raw.M2T, title_index=0
libbluray/bdnav/index_parse.c:162: indx_parse(): error opening /media/nas/gustl/hb_bench/raw.M2T/BDMV/index.bdmv
libbluray/bdnav/index_parse.c:162: indx_parse(): error opening /media/nas/gustl/hb_bench/raw.M2T/BDMV/BACKUP/index.bdmv
libbluray/bluray.c:2182: nav_get_title_list(/media/nas/gustl/hb_bench/raw.M2T) failed
[16:23:47] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 4.2.1
libdvdread: Encrypted DVD support unavailable.
************************************************
**                                            **
**  No css library available. See             **
**  /usr/share/doc/libdvdread4/README.css     **
**  for more information.                     **
**                                            **
************************************************
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[16:23:47] dvd: not a dvd - trying as a stream/file instead
[16:23:47] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[16:23:47] Found the following PIDS
[16:23:47]     Video PIDS : 
[16:23:47]       0x100 type MPEG2 (0x2) (PCR)
[16:23:47]     Audio PIDS : 
[16:23:47]       0x101 type MPEG1 (0x3)
[16:23:47]     Subtitle PIDS : 
[16:23:47]     Other PIDS : 
[16:23:47] stream id 0x101 (type 0x3 substream 0x0) audio 0x101
[16:23:47] scan: decoding previews for title 1
[16:23:48] scan: audio 0x101: mp2, rate=48000Hz, bitrate=200000 Unknown (MPEG1) (2.0 ch)
[16:23:48] scan: 10 previews, 1440x1080, 25,000 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 4:3
[16:23:48] stream: 6 good frames, 0 errors (0%)
[16:23:48] libhb: scan thread found 1 valid title(s)
libdvdread: Encrypted DVD support unavailable.
************************************************
**                                            **
**  No css library available. See             **
**  /usr/share/doc/libdvdread4/README.css     **
**  for more information.                     **
**                                            **
************************************************

** (handbrake:2935): WARNING **: Inhibit failed: The name org.freedesktop.PowerManagement was not provided by any .service files
[16:24:37] hb_scan: path=/media/nas/gustl/hb_bench/raw.M2T, title_index=1
libbluray/bdnav/index_parse.c:162: indx_parse(): error opening /media/nas/gustl/hb_bench/raw.M2T/BDMV/index.bdmv
libbluray/bdnav/index_parse.c:162: indx_parse(): error opening /media/nas/gustl/hb_bench/raw.M2T/BDMV/BACKUP/index.bdmv
libbluray/bluray.c:2182: nav_get_title_list(/media/nas/gustl/hb_bench/raw.M2T) failed
[16:24:37] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 4.2.1
libdvdread: Encrypted DVD support unavailable.
************************************************
**                                            **
**  No css library available. See             **
**  /usr/share/doc/libdvdread4/README.css     **
**  for more information.                     **
**                                            **
************************************************
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[16:24:37] dvd: not a dvd - trying as a stream/file instead
[16:24:37] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[16:24:37] Found the following PIDS
[16:24:37]     Video PIDS : 
[16:24:37]       0x100 type MPEG2 (0x2) (PCR)
[16:24:37]     Audio PIDS : 
[16:24:37]       0x101 type MPEG1 (0x3)
[16:24:37]     Subtitle PIDS : 
[16:24:37]     Other PIDS : 
[16:24:37] stream id 0x101 (type 0x3 substream 0x0) audio 0x101
[16:24:37] scan: decoding previews for title 1
[16:24:37] scan: audio 0x101: mp2, rate=48000Hz, bitrate=200000 Unknown (MPEG1) (2.0 ch)
[16:24:37] scan: 10 previews, 1440x1080, 25,000 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 4:3
[16:24:37] stream: 6 good frames, 0 errors (0%)
[16:24:37] libhb: scan thread found 1 valid title(s)
[16:24:39] gtkgui: Modified Preset: Regular->Normal
[16:24:39] 1 job(s) to process
[16:24:39] starting job
[16:24:39] sync: expecting 7295 video frames
[16:24:39] job configuration:
[16:24:39]  * source
[16:24:39]    + /media/nas/gustl/hb_bench/raw.M2T
[16:24:39]    + title 1, chapter(s) 1 to 1
[16:24:39]  * destination
[16:24:39]    + /media/nas/gustl/hb_bench/20_me.mkv
[16:24:39]    + container: Matroska (.mkv)
[16:24:39]  * video track
[16:24:39]    + decoder: mpeg2
[16:24:39]      + bitrate 25000 kbps
[16:24:39]    + frame rate: same as source (around 25,000 fps)
[16:24:39]    + filters
[16:24:39]      + Framerate Shaper (0:27000000:1080000)
[16:24:39]        + frame rate: same as source (around 25,000 fps)
[16:24:39]      + Crop and Scale (1280:960:0:0:0:0)
[16:24:39]        + source: 1440 * 1080, crop (0/0/0/0): 1440 * 1080, scale: 1280 * 960
[16:24:39]    + loose anamorphic
[16:24:39]      + storage dimensions: 1280 * 960, mod 2
[16:24:39]      + pixel aspect ratio: 4 / 3
[16:24:39]      + display dimensions: 1706 * 960
[16:24:39]    + encoder: H.264 (x264)
[16:24:39]      + x264 preset: medium
[16:24:39]      + h264 profile: main
[16:24:39]      + h264 level: 4.0
[16:24:39]      + quality: 20,00 (RF)
[16:24:39]  * audio track 1
[16:24:39]    + decoder: Unknown (MPEG1) (2.0 ch) (track 1, id 0x101)
[16:24:39]      + bitrate: 200 kbps, samplerate: 48000 Hz
[16:24:39]    + mixdown: Stereo
[16:24:39]    + encoder: AC3 (ffmpeg)
[16:24:39]      + bitrate: 160 kbps, samplerate: 48000 Hz
[16:24:39] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[16:24:39] encx264: encoding with stored aspect 4/3
[16:24:39] encx264: Encoding at constant RF 20,000000
[16:24:39] reader: first SCR -1 id 0x101 DTS 126000
x264 [warning]: --psnr used with psy on: results will be invalid!
x264 [warning]: --tune psnr should be used if attempting to benchmark psnr!
x264 [info]: using SAR=4/3
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
x264 [info]: profile Main, level 4.0
[16:24:39] mpeg2: "Chapter 1" (1) at frame 0 time -1
[16:24:39] sync: audio 0x101 time went backwards 16 ms, dropped 1 frames (start 15808, next 17280)
[16:24:39] mpeg2 tag botch: pts 59727, tag pts 20127 buf (nil)
[16:24:39] mpeg2 tag botch: pts 52527, tag pts 23727 buf (nil)
[16:24:39] sync: audio 0x101 time went backwards 20 ms, dropped 1 frames (start 142844, next 144720)
[16:24:40] sync: audio 0x101 time went backwards 15 ms, dropped 1 frames (start 443607, next 444960)
[16:26:47] hb_ts_stream_decode - eof
[16:26:47] reader: done. 608 scr changes
[16:26:49] work: average encoding speed for job is 56,801605 fps
[16:26:49] sync: got 7290 frames, 7295 expected
[16:26:49] render: lost time: 0 (0 frames)
[16:26:49] render: gained time: 0 (0 frames) (0 not accounted for)
[16:26:49] mpeg2 done: 7290 frames
x264 [info]: frame I:30    Avg QP:17,00  size:154501  PSNR Mean Y:46,26 U:51,85 V:52,27 Avg:47,48 Global:47,47
x264 [info]: frame P:1846  Avg QP:19,79  size: 29872  PSNR Mean Y:43,35 U:50,29 V:50,78 Avg:44,71 Global:44,70
x264 [info]: frame B:5414  Avg QP:22,06  size:  4361  PSNR Mean Y:42,37 U:50,08 V:50,61 Avg:43,80 Global:43,78
x264 [info]: consecutive B-frames:  0,7%  0,1%  2,3% 97,0%
x264 [info]: mb I  I16..4: 16,6%  0,0% 83,4%
x264 [info]: mb P  I16..4:  0,3%  0,0%  1,1%  P16..4: 44,2% 18,1% 14,2%  0,0%  0,0%    skip:22,1%
x264 [info]: mb B  I16..4:  0,0%  0,0%  0,0%  B16..8: 39,5%  1,8%  0,4%  direct: 0,8%  skip:57,4%  L0:42,8% L1:53,6% BI: 3,6%
x264 [info]: coded y,uvDC,uvAC intra: 87,6% 73,8% 35,7% inter: 10,8% 16,3% 0,0%
x264 [info]: i16 v,h,dc,p: 24% 16% 15% 45%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 17% 12%  6%  7% 10%  6%  8%  6%
x264 [info]: i8c dc,h,v,p: 50% 18% 25%  7%
x264 [info]: Weighted P-Frames: Y:0,7% UV:0,0%
x264 [info]: ref P L0: 50,3% 13,1% 27,3%  9,3%  0,0%
x264 [info]: ref B L0: 81,3% 15,3%  3,4%
x264 [info]: ref B L1: 91,0%  9,0%
x264 [info]: SSIM Mean Y:0,9756653 (16,138db)
x264 [info]: PSNR Mean Y:42,640 U:50,141 V:50,664 Avg:44,049 Global:44,012 kb/s:2285,78
[16:26:49] mp2-decoder done: 0 frames, 0 decoder errors, 0 drops
[16:26:49] mux: track 0, 7290 frames, 83386153 bytes, 2285,18 kbps, fifo 1024
[16:26:49] mux: track 1, 9123 frames, 5838720 bytes, 160,01 kbps, fifo 2048
[16:26:49] stream: 7295 good frames, 0 errors (0%)
[16:26:49] libhb: work result = 0
mduell
Veteran User
Posts: 8198
Joined: Sat Apr 21, 2007 8:54 pm

Re: Filesize and x264 Preset

Post by mduell »

-gb- wrote:

Code: Select all

[16:23:39] gtkgui: HandBrake rev5474 (2014032499) - Linux x86_64 - http://handbrake.fr
FYI that's an ancient, unsupported, and probably intentionally broken build from your distro. I'd recommend jstebbin's PPA or compiling yourself from source if you want something up to date, supported, and/or fully functional.
-gb-
Posts: 5
Joined: Sat Mar 05, 2016 6:20 pm

Re: Filesize and x264 Preset

Post by -gb- »

Didn't know this, it was the default handbrake from Ubuntu 14.04 (with latest updates).
In a few days i will post the same results from the new handbrake.
Thank you!
Edit:
By now, with the new command "ghb" which i had to google^^ i encoded with some settlings like in the old version and ... the outcome is nearly the same. Same size and same average fps.
nhyone
Bright Spark User
Posts: 252
Joined: Fri Jul 24, 2015 4:13 am

Re: Filesize and x264 Preset

Post by nhyone »

In viewtopic.php?f=6&t=33994&p=158981#p158981, I claimed the main setting that affects video quality is trellis, hence we can group the presets as follows:

0. ultrafast, superfast, veryfast
1. faster, fast, medium, slow
2. slower, veryslow, placebo

The other settings affect encoding efficiency.

Since then, I believe subme also affects video quality, but only if they are far apart (e.g. veryfast subme 2 vs medium's 7).

You can read the rest of the post there. Hope that helps you choose the preset to use.
Deleted User 11865

Re: Filesize and x264 Preset

Post by Deleted User 11865 »

The 8x8 transform can have a large effect too, especially is your source is grainy. Generally speaking, every setting can have some effect.

That's why you must decide on an encoder preset first and only then adjust the constant RF value to your liking.
Post Reply