Any suggestions on preserving grain with x265?

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
Bjomesphat
Posts: 45
Joined: Thu Sep 03, 2015 12:00 am

Any suggestions on preserving grain with x265?

Post by Bjomesphat »

The way x265 preserves grain seems very different from how it worked with x264. Using default x265 settings with no tune and most of the presets removes or smooths out grain considerably regardless of your CRF. Of course using the grain tune brings it back, however there's significant trade offs when using the very slow preset: it actually amplifies the grain and inflates the filesize without significant visual improvements. It almost has the effect that it's adding grain, but it appears to be taking fine grain detail and making it coarser. I've tested in the 20-28 CRF range, as anything outside that range doesn't fit my encoding requirements, and I get similar results across the quality levels.

Anyway, I'm not a big technical guy when it comes to encoding. I use presets and tunes and all of the user friendly settings designed to work for 99% of video encoding, but I've started digging into this a little bit because I'm not really satisfied with the grain tune for x265. Keep in mind, just because I'm changing settings doesn't mean I actually know what I'm doing, it's all trial and error, so I'm hoping someone with expert knowledge can either point out what I'm doing wrong or recommend some settings to try.

One of the first tests I did was disabling SAO and using no tune with very slow, and that immediately brought grain detail back. So that was kind of my starting point.

From there I messed around with changing psy-rdoq and psy-rd values, and that had significant effects on my output for better grain retention. I ended up being pretty happy with these settings (no-sao:rdoq=1:psy-rdoq=3:psy-rd=3) with no tune, very slow preset, and around 23-25 CRF.

From there I tried adding no-cutree, and that inflated my filesize too much so that wasn't an option.

I also tried changing aq-mode=3 which also inflated my filesize slightly, but didn't offer enough visual improvement to warrant the change.

Right now I've settle on putting this in my extra options (no-sao:rdoq=1:psy-rdoq=3:psy-rd=3), as I prefer how this looks to the grain tune, and the filesize savings are even more significant, but I'm still unable to get finer grain detail. It's better than the grain tune, but it's still slightly more amplified than my tests with x264. There's also a lot of other settings in the grain tune that aren't in my settings, so I'm a little worried I've left out something that I should be using.

Anyway, I'll post a log below so everyone can get the full picture, but I'd love any suggestions either from your own testing or just your knowledge of the encoding standard.

Code: Select all

HandBrake 1.2.0 (2018121700)
OS: Microsoft Windows NT 6.1.7601 Service Pack 1
Ram: 16309 MB, 
GPU Information:
  NVIDIA Quadro K620 - 10.18.13.6191
Screen: 1920x1080
Temp Dir: C:\Users\Bjomesphat\AppData\Local\Temp\
Install Dir: C:\Users\Bjomesphat\Downloads\HandBrake-1.2.0-x86_64-Win_GUI\HandBrake 1.2.0
Data Dir: C:\Users\Bjomesphat\AppData\Roaming\HandBrake

-------------------------------------------


# Starting Encode ...

[16:42:33] hb_init: starting libhb thread
[16:42:33] 1 job(s) to process
[16:42:33] json job:
{
  "Audio": {
    "AudioList": [
      {
        "Bitrate": 448,
        "DRC": 0.0,
        "Encoder": "ac3",
        "Gain": 0.0,
        "Mixdown": 7,
        "NormalizeMixLevel": false,
        "Samplerate": 48000,
        "Track": 0,
        "DitherMethod": 0
      }
    ],
    "CopyMask": [
      "copy:aac",
      "copy:ac3",
      "copy:dtshd",
      "copy:dts",
      "copy:eac3",
      "copy:flac",
      "copy:mp3",
      "copy:truehd"
    ],
    "FallbackEncoder": "ac3"
  },
  "Destination": {
    "ChapterList": [
      {
        "Name": "Chapter 1"
      },
      {
        "Name": "Chapter 2"
      },
      {
        "Name": "Chapter 3"
      },
      {
        "Name": "Chapter 4"
      },
      {
        "Name": "Chapter 5"
      },
      {
        "Name": "Chapter 6"
      },
      {
        "Name": "Chapter 7"
      },
      {
        "Name": "Chapter 8"
      },
      {
        "Name": "Chapter 9"
      }
    ],
    "ChapterMarkers": true,
    "AlignAVStart": false,
    "File": "C:\\Users\\Bjomesphat\\Downloads\\FIN\\The_Wire_Season_1_Disc_1_t01.mkv",
    "Mp4Options": {
      "IpodAtom": false,
      "Mp4Optimize": false
    },
    "Mux": "mkv"
  },
  "Filters": {
    "FilterList": [
      {
        "ID": 4,
        "Settings": {
          "mode": "7"
        }
      },
      {
        "ID": 3,
        "Settings": {
          "block-height": "16",
          "block-thresh": "40",
          "block-width": "16",
          "filter-mode": "2",
          "mode": "3",
          "motion-thresh": "1",
          "spatial-metric": "2",
          "spatial-thresh": "1"
        }
      },
      {
        "ID": 11,
        "Settings": {
          "crop-bottom": "0",
          "crop-left": "0",
          "crop-right": "0",
          "crop-top": "0",
          "height": "1080",
          "width": "1920"
        }
      },
      {
        "ID": 6,
        "Settings": {
          "mode": "0"
        }
      }
    ]
  },
  "PAR": {
    "Num": 1,
    "Den": 1
  },
  "Metadata": {},
  "SequenceID": 0,
  "Source": {
    "Angle": 1,
    "Range": {
      "Type": "chapter",
      "Start": 1,
      "End": 9
    },
    "Title": 1,
    "Path": "C:\\Users\\Bjomesphat\\Downloads\\The_Wire_Season_1_Disc_1_t01.mkv"
  },
  "Subtitle": {
    "Search": {
      "Burn": false,
      "Default": false,
      "Enable": false,
      "Forced": false
    },
    "SubtitleList": []
  },
  "Video": {
    "Encoder": "x265",
    "Level": "auto",
    "TwoPass": false,
    "Turbo": false,
    "ColorMatrixCode": 0,
    "Options": "no-sao:rdoq=1:psy-rdoq=3:psy-rd=3",
    "Preset": "veryslow",
    "Profile": "auto",
    "Quality": 25.0,
    "QSV": {
      "Decode": false,
      "AsyncDepth": 0
    }
  }
}
[16:42:33] CPU: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
[16:42:33]  - Intel microarchitecture Skylake
[16:42:33]  - logical processor count: 8
[16:42:33] Intel Quick Sync Video support: no
[16:42:33] hb_scan: path=C:\Users\Bjomesphat\Downloads\The_Wire_Season_1_Disc_1_t01.mkv, title_index=1
udfread ERROR: ECMA 167 Volume Recognition failed
src/libbluray/disc/disc.c:323: failed opening UDF image C:\Users\Bjomesphat\Downloads\The_Wire_Season_1_Disc_1_t01.mkv
src/libbluray/disc/disc.c:424: error opening file BDMV\index.bdmv
src/libbluray/disc/disc.c:424: error opening file BDMV\BACKUP\index.bdmv
[16:42:33] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 6.0.0
libdvdread: Encrypted DVD support unavailable.
libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdread: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:42:33] dvd: not a dvd - trying as a stream/file instead
Input #0, matroska,webm, from 'C:\Users\Bjomesphat\Downloads\The_Wire_Season_1_Disc_1_t01.mkv':
  Metadata:
    title           : The Wire Season 1 Disc 1
    encoder         : libmakemkv v1.10.9 (1.3.5/1.4.7) win(x64-release)
    creation_time   : 2018-01-25T04:35:40.000000Z
  Duration: 01:02:06.97, start: 0.000000, bitrate: 25340 kb/s
    Chapter #0:0: start 0.000000, end 267.600667
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 267.600667, end 765.806708
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 765.806708, end 1266.306708
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 1266.306708, end 1824.280792
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 1824.280792, end 2382.380000
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 2382.380000, end 2883.797583
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 2883.797583, end 3316.646667
    Metadata:
      title           : Chapter 07
    Chapter #0:7: start 3316.646667, end 3658.154500
    Metadata:
      title           : Chapter 08
    Chapter #0:8: start 3658.154500, end 3726.973250
    Metadata:
      title           : Chapter 09
    Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc
    Metadata:
      BPS-eng         : 21895054
      DURATION-eng    : 01:02:06.973250000
      NUMBER_OF_FRAMES-eng: 89358
      NUMBER_OF_BYTES-eng: 10200284835
      SOURCE_ID-eng   : 001011
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.10.9 win(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2018-01-25 04:35:40
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
    Stream #0:1(eng): Audio: dts (DTS-HD MA), 48000 Hz, 5.1(side), s32p (24 bit) (default)
    Metadata:
      title           : Surround 5.1
      BPS-eng         : 3441686
      DURATION-eng    : 01:02:06.976000000
      NUMBER_OF_FRAMES-eng: 349404
      NUMBER_OF_BYTES-eng: 1603385576
      SOURCE_ID-eng   : 001100
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.10.9 win(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2018-01-25 04:35:40
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
[16:42:33] scan: decoding previews for title 1
[16:42:33] scan: audio 0x1: dca, rate=48000Hz, bitrate=1 English (DTS-HD MA) (5.1 ch)
[16:42:34] scan: 10 previews, 1920x1080, 23.976 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 1:1
[16:42:34] scan: supported video decoders: avcodec qsv
[16:42:34] libhb: scan thread found 1 valid title(s)
[16:42:34] starting job
[16:42:34] decomb filter thread started for segment 0
[16:42:34] decomb filter thread started for segment 1
[16:42:34] decomb filter thread started for segment 2
[16:42:34] decomb filter thread started for segment 3
[16:42:34] decomb filter thread started for segment 4
[16:42:34] decomb filter thread started for segment 5
[16:42:34] decomb filter thread started for segment 6
[16:42:34] decomb filter thread started for segment 7
[16:42:34] decomb check thread started for segment 0
[16:42:34] decomb check thread started for segment 1
[16:42:34] decomb check thread started for segment 2
[16:42:34] decomb check thread started for segment 3
[16:42:34] decomb check thread started for segment 4
[16:42:34] decomb check thread started for segment 5
[16:42:34] decomb check thread started for segment 6
[16:42:34] decomb check thread started for segment 7
[16:42:34] mask filter thread started for segment 0
[16:42:34] mask filter thread started for segment 1
[16:42:34] mask filter thread started for segment 2
[16:42:34] mask filter thread started for segment 3
[16:42:34] mask filter thread started for segment 4
[16:42:34] mask filter thread started for segment 5
[16:42:34] mask filter thread started for segment 6
[16:42:34] mask filter thread started for segment 7
[16:42:34] mask erode thread started for segment 0
[16:42:34] mask erode thread started for segment 1
[16:42:34] mask erode thread started for segment 2
[16:42:34] mask erode thread started for segment 3
[16:42:34] mask erode thread started for segment 4
[16:42:34] mask erode thread started for segment 5
[16:42:34] mask erode thread started for segment 6
[16:42:34] mask erode thread started for segment 7
[16:42:34] mask dilate thread started for segment 0
[16:42:34] mask dilate thread started for segment 1
[16:42:35] mask dilate thread started for segment 2
[16:42:35] mask dilate thread started for segment 3
[16:42:35] mask dilate thread started for segment 4
[16:42:35] mask dilate thread started for segment 5
[16:42:35] mask dilate thread started for segment 6
[16:42:35] mask dilate thread started for segment 7
[16:42:35] yadif thread started for segment 0
[16:42:35] yadif thread started for segment 1
[16:42:35] yadif thread started for segment 2
[16:42:35] yadif thread started for segment 3
[16:42:35] yadif thread started for segment 4
[16:42:35] yadif thread started for segment 5
[16:42:35] yadif thread started for segment 6
[16:42:35] yadif thread started for segment 7
[16:42:35] job configuration:
[16:42:35]  * source
[16:42:35]    + C:\Users\Bjomesphat\Downloads\The_Wire_Season_1_Disc_1_t01.mkv
[16:42:35]    + title 1, chapter(s) 1 to 9
[16:42:35]    + container: matroska,webm
[16:42:35]    + data rate: 25340 kbps
[16:42:35]  * destination
[16:42:35]    + C:\Users\Bjomesphat\Downloads\FIN\The_Wire_Season_1_Disc_1_t01.mkv
[16:42:35]    + container: Matroska (libavformat)
[16:42:35]      + chapter markers
[16:42:35]  * video track
[16:42:35]    + decoder: h264
[16:42:35]    + filters
[16:42:35]      + Comb Detect (mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2:block-thresh=40:block-width=16:block-height=16)
[16:42:35]      + Decomb (mode=39)
[16:42:35]      + Framerate Shaper (mode=0)
[16:42:35]        + frame rate: same as source (around 23.976 fps)
[16:42:35]      + Crop and Scale (width=1920:height=1080:crop-top=0:crop-bottom=0:crop-left=0:crop-right=0)
[16:42:35]        + source: 1920 * 1080, crop (0/0/0/0): 1920 * 1080, scale: 1920 * 1080
[16:42:35]    + Output geometry
[16:42:35]      + storage dimensions: 1920 x 1080
[16:42:35]      + pixel aspect ratio: 1 : 1
[16:42:35]      + display dimensions: 1920 x 1080
[16:42:35]    + encoder: H.265 (libx265)
[16:42:35]      + preset:  veryslow
[16:42:35]      + options: no-sao:rdoq=1:psy-rdoq=3:psy-rd=3
[16:42:35]      + profile: auto
[16:42:35]      + quality: 25.00 (RF)
[16:42:35]      + color profile: 1-1-1
[16:42:35]  * audio track 1
[16:42:35]    + decoder: English (DTS-HD MA) (5.1 ch) (track 1, id 0x1)
[16:42:35]      + samplerate: 48000 Hz
[16:42:35]    + mixdown: 5.1 Channels
[16:42:35]    + dither: none
[16:42:35]    + encoder: AC3 (libavcodec)
[16:42:35]      + bitrate: 448 kbps, samplerate: 48000 Hz
[16:42:35] sync: expecting 89357 video frames
x265 [info]: HEVC encoder version 2.9
x265 [info]: build info [Windows][GCC 7.1.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 3 inter / 3 intra
x265 [info]: ME / range / subpel / merge         : star / 57 / 4 / 4
x265 [info]: Keyframe min / max / scenecut / bias: 24 / 240 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 40 / 8 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 1
x265 [info]: References / ref-limit  cu / depth  : 5 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 1 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-25.0 / 0.60
x265 [info]: tools: rect amp limit-modes rd=6 psy-rd=3.00 rdoq=1 psy-rdoq=3.00
x265 [info]: tools: rskip limit-tu=4 signhide tmvp b-intra
x265 [info]: tools: strong-intra-smoothing deblock
[16:42:35] sync: first pts video is 0
[16:42:35] sync: "Chapter 1" (1) at frame 1 time 0
[16:42:35] sync: first pts audio 0x1 is 0
[17:40:19] sync: "Chapter 2" (2) at frame 6417 time 24084060
[19:39:31] sync: "Chapter 3" (3) at frame 18362 time 68922603
[21:22:46] sync: "Chapter 4" (4) at frame 30362 time 113967603
[22:57:54] sync: "Chapter 5" (5) at frame 43740 time 164185271
[00:54:56] sync: "Chapter 6" (6) at frame 57121 time 214414200
[02:33:25] sync: "Chapter 7" (7) at frame 69143 time 259541782
[03:46:53] sync: "Chapter 8" (8) at frame 79521 time 298498200
[04:50:25] sync: "Chapter 9" (9) at frame 87709 time 329233905
[04:52:46] reader: done. 1 scr changes
[04:53:49] work: average encoding speed for job is 2.038473 fps
[04:53:49] comb detect: heavy 6923 | light 22206 | uncombed 60229 | total 89358
[04:53:49] decomb: deinterlaced 6923 | blended 22206 | unfiltered 60229 | total 89358
[04:53:49] vfr: lost time: 0 (0 frames)
[04:53:49] vfr: gained time: 0 (0 frames) (0 not accounted for)
[04:53:49] dca-decoder done: 349404 frames, 0 decoder errors
[04:53:49] h264-decoder done: 89358 frames, 0 decoder errors
[04:53:49] sync: got 89358 frames, 89357 expected
[04:53:49] sync: framerate min 23.981 fps, max 23.981 fps, avg 23.976 fps
x265 [info]: frame I:    980, Avg QP:25.40  kb/s: 18307.49
x265 [info]: frame P:  16066, Avg QP:25.92  kb/s: 7982.31
x265 [info]: frame B:  72312, Avg QP:30.62  kb/s: 2115.99
x265 [info]: Weighted P-Frames: Y:2.0% UV:1.5%
x265 [info]: Weighted B-Frames: Y:2.6% UV:1.9%
x265 [info]: consecutive B-frames: 7.9% 1.9% 23.1% 6.4% 10.1% 18.1% 11.0% 11.4% 10.0%
encoded 89358 frames in 43874.40s (2.04 fps), 3348.29 kb/s, Avg QP:29.72
[04:53:49] mux: track 0, 89358 frames, 1560230698 bytes, 3349.02 kbps, fifo 2048
[04:53:49] mux: track 1, 116468 frames, 208710656 bytes, 448.00 kbps, fifo 4096
[04:53:49] libhb: work result = 0

# Encode Completed ...


mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: Any suggestions on preserving grain with x265?

Post by mduell »

Use the grain tune with something faster than veryslow.
Post Reply