Encoding options for difficult scene

HandBrake for Mac support
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
GreenT
Posts: 2
Joined: Thu Oct 13, 2022 9:56 pm

Encoding options for difficult scene

Post by GreenT »

Background:
I've been using HandBrake to encode my video library for years. Most of my content is sourced from blu-ray. My preferred settings work well for the bulk of my movies, reducing file size while still delivering pleasing video quality. When my preferred settings have left something unattractive or distracting in the file, I've been able to tweak x264 settings appropriately to eliminate the issue.

Description of problem or question:
The opening few seconds of the 2016 movie Arrival is giving me fits. It starts completely black, and then a dimly lit ceiling comes into focus as the camera tilts down/forward toward some windows.

On the original blu-ray, the ceiling appears first as expanding arcs of light, which seem to flash due to the way the encoding handles the brightening image. It's probably not what the director/cinematographer intended, but that's what the original blu-ray encoding did to it. I know that aspect of it can't be fixed in Handbrake.

However, after a few seconds the brightness level steadies, and the camera continues tilting, revealing more of the ceiling (and the windows at the end of the room). On the original blu-ray, the ceiling is rendered fairly well, with the brightness gradient reasonably smooth and well resolved, and with no noticeable banding. In my Handbrake encodes, ceiling is rendered poorly, with the brightness gradient blocky and poorly dithered. It looks pretty bad, and as these are literally the opening moments of the film, it's especially distracting.

Steps to reproduce the problem:
Rip the blu-ray of Arrival. Try using Handbrake to encode the first chapter, or if you'd prefer to wait less time, encode from 00:01:08 to 00:01:38. Those thirty seconds are all you need.

HandBrake version:
1.5.1

Operating system and version:
MacOS 10.14 Mojave

HandBrake Activity Log ***required***

I don't believe posting the activity log would be helpful, due to the sheer number of different settings/combinations I've tried, but as the forum insists it's required, I have posted the activity log for one of the recent attempts below.

I've tried dozens of different encodes with various options. I've tried CQ levels between 10 and 20; messed with adaptive quantization values (between 1 and 2); tried presets between medium and placebo; adjusted deblock values; tried using the Deblock filter at various strengths and tunes; and tried most of these things in various combinations with each other.

The only thing that seems to help in a significant way is adjusting CQ level REALLY low. But this results in a really large file size, which is pointless given that I already have the unmodified blu-ray version, and even the highest quality encodes I've done fall well short of the unmodified scene.

Activity Log:

Code: Select all

HandBrake Activity Log for Session: 2022-10-13T23:16:59Z
Handbrake Version: 1.5.1 (2022011000)
Arrival (2016) clip.mkv
Preset: Blu_HQ (Modified)
[19:16:59] Compile-time hardening features are enabled
[19:16:59] hb_init: starting libhb thread
[19:16:59] macgui: fr.handbrake.HandBrakeXPCService scanning specifically for title: 1
[19:16:59] CPU: Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
[19:16:59]  - logical processor count: 24
Input #0, matroska,webm, from '/Volumes/Blu_rips/Arrival (2016).mkv':
  Metadata:
    title           : Arrival
    encoder         : libmakemkv v1.16.7 (1.3.10/1.5.2) darwin(x64-release)
    creation_time   : 2022-10-10T17:52:47.000000Z
  Duration: 01:56:22.98, start: 0.000000, bitrate: 33767 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 589.755833
      Metadata:
        title           : Chapter 01
    Chapter #0:1: start 589.755833, end 1053.635917
      Metadata:
        title           : Chapter 02
    Chapter #0:2: start 1053.635917, end 1408.281875
      Metadata:
        title           : Chapter 03
    Chapter #0:3: start 1408.281875, end 2033.990292
      Metadata:
        title           : Chapter 04
    Chapter #0:4: start 2033.990292, end 2461.500708
      Metadata:
        title           : Chapter 05
    Chapter #0:5: start 2461.500708, end 3146.101292
      Metadata:
        title           : Chapter 06
    Chapter #0:6: start 3146.101292, end 3454.534417
      Metadata:
        title           : Chapter 07
    Chapter #0:7: start 3454.534417, end 3786.449333
      Metadata:
        title           : Chapter 08
    Chapter #0:8: start 3786.449333, end 4169.206708
      Metadata:
        title           : Chapter 09
    Chapter #0:9: start 4169.206708, end 4569.398167
      Metadata:
        title           : Chapter 10
    Chapter #0:10: start 4569.398167, end 5121.533083
      Metadata:
        title           : Chapter 11
    Chapter #0:11: start 5121.533083, end 5736.981250
      Metadata:
        title           : Chapter 12
    Chapter #0:12: start 5736.981250, end 6326.320000
      Metadata:
        title           : Chapter 13
    Chapter #0:13: start 6326.320000, end 6982.976000
      Metadata:
        title           : Chapter 14
  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         : 27341256
      DURATION-eng    : 01:56:22.976000000
      NUMBER_OF_FRAMES-eng: 167424
      NUMBER_OF_BYTES-eng: 23865416837
      SOURCE_ID-eng   : 001011
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.16.7 darwin(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2022-10-10 17:52:47
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:1(eng): Audio: dts (DTS-HD MA), 48000 Hz, 7.1, s32p (24 bit) (default)
    Metadata:
      title           : Surround 7.1
      BPS-eng         : 4207353
      DURATION-eng    : 01:56:22.976000000
      NUMBER_OF_FRAMES-eng: 654654
      NUMBER_OF_BYTES-eng: 3672480936
      SOURCE_ID-eng   : 001100
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.16.7 darwin(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2022-10-10 17:52:47
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:2(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s
    Metadata:
      title           : Surround 5.1
      BPS-eng         : 1509000
      DURATION-eng    : 01:56:22.976000000
      NUMBER_OF_FRAMES-eng: 654654
      NUMBER_OF_BYTES-eng: 1317163848
      SOURCE_ID-eng   : 001100
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.16.7 darwin(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2022-10-10 17:52:47
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:3(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb/s
    Metadata:
      title           : Surround 5.1
      BPS-eng         : 640000
      DURATION-eng    : 01:56:22.976000000
      NUMBER_OF_FRAMES-eng: 218218
      NUMBER_OF_BYTES-eng: 558638080
      SOURCE_ID-eng   : 001103
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.16.7 darwin(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2022-10-10 17:52:47
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:4(eng): Subtitle: hdmv_pgs_subtitle
    Metadata:
      BPS-eng         : 32796
      DURATION-eng    : 01:48:58.469437500
      NUMBER_OF_FRAMES-eng: 2444
      NUMBER_OF_BYTES-eng: 26804982
      SOURCE_ID-eng   : 001200
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.16.7 darwin(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2022-10-10 17:52:47
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:5(eng): Subtitle: hdmv_pgs_subtitle
    Metadata:
      BPS-eng         : 36145
      DURATION-eng    : 01:48:58.677979166
      NUMBER_OF_FRAMES-eng: 2878
      NUMBER_OF_BYTES-eng: 29542793
      SOURCE_ID-eng   : 001201
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.16.7 darwin(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2022-10-10 17:52:47
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
[19:16:59] scan: decoding previews for title 1
[19:16:59] scan: audio 0x1: dca, rate=48000Hz, bitrate=1 English (DTS-HD MA) (7.1 ch)
[19:16:59] scan: audio 0x2: dca, rate=48000Hz, bitrate=1536000 English (DTS) (5.1 ch) (1536 kbps)
[19:16:59] scan: audio 0x3: ac3, rate=48000Hz, bitrate=640000 English (AC3) (5.1 ch) (640 kbps)
[19:17:00] scan: 10 previews, 1920x1080, 23.976 fps, autocrop = 138/138/0/0, aspect 16:9, PAR 1:1, color profile: 1-1-1, chroma location: left
[19:17:00] libhb: scan thread found 1 valid title(s)
[19:17:00] macgui: fr.handbrake.HandBrakeXPCService scan done
[19:17:00] macgui: fr.handbrake.HandBrakeXPCService started encoding Arrival (2016) clip.mkv
[19:17:00] macgui: fr.handbrake.HandBrakeXPCService with preset Blu_HQ (Modified)
[19:17:00] Starting work at: Thu Oct 13 19:17:00 2022

[19:17:00] 1 job(s) to process
[19:17:00] Starting Task: Encoding Pass
[19:17:00] Skipping vfr filter
[19:17:00] job configuration:
[19:17:00]  * source
[19:17:00]    + /Volumes/Blu_rips/Arrival (2016).mkv
[19:17:00]    + title 1, start 00:01:8.00 stop 00:01:38.00
[19:17:00]    + container: matroska,webm
[19:17:00]    + data rate: 33767 kbps
[19:17:00]  * destination
[19:17:00]    + /Volumes/Plex/Movies/Arrival (2016) clip.mkv
[19:17:00]    + container: Matroska (libavformat)
[19:17:00]      + chapter markers
[19:17:00]  * video track
[19:17:00]    + decoder: h264 8-bit (yuv420p)
[19:17:00]    + filters
[19:17:00]      + Crop and Scale (width=1920:height=804:crop-top=138:crop-bottom=138:crop-left=0:crop-right=0)
[19:17:00]        + source: 1920 * 1080, crop (138/138/0/0): 1920 * 804, scale: 1920 * 804
[19:17:00]    + Output geometry
[19:17:00]      + storage dimensions: 1920 x 804
[19:17:00]      + pixel aspect ratio: 1 : 1
[19:17:00]      + display dimensions: 1920 x 804
[19:17:00]    + encoder: H.264 (libx264)
[19:17:00]      + preset:  slower
[19:17:00]      + tune:    film
[19:17:00]      + options: aq=1.8:deblock=-3,-3
[19:17:00]      + profile: auto
[19:17:00]      + level:   auto
[19:17:00]      + quality: 17.00 (RF)
[19:17:00]      + color profile: 1-1-1
[19:17:00]      + chroma location: left
[19:17:00]  * audio track 1
[19:17:00]    + name: Surround 5.1
[19:17:00]    + decoder: English (DTS) (5.1 ch) (1536 kbps) (track 2, id 0x2)
[19:17:00]      + bitrate: 1536 kbps, samplerate: 48000 Hz
[19:17:00]    + DTS Passthru
[19:17:00]  * audio track 2
[19:17:00]    + name: Surround 5.1
[19:17:00]    + decoder: English (DTS) (5.1 ch) (1536 kbps) (track 2, id 0x2)
[19:17:00]      + bitrate: 1536 kbps, samplerate: 48000 Hz
[19:17:00]    + mixdown: Dolby Pro Logic II
[19:17:00]    + encoder: AAC (Apple AudioToolbox)
[19:17:00]      + bitrate: 160 kbps, samplerate: 48000 Hz
[19:17:00] sync: expecting 743 video frames
[19:17:01] x264 options: Unknown suboption aq
[19:17:01] encx264: min-keyint: 24, keyint: 240
[19:17:01] encx264: encoding at constant RF 17.000000
[19:17:01] encx264: unparsed options: aq=1.8:deblock=-3,-3:ref=8:b-adapt=2:direct=auto:analyse=all:me=umh:subme=9:trellis=2:psy-rd=1,0.15:rc-lookahead=60
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
x264 [info]: profile High, level 5.0, 4:2:0, 8-bit
[19:17:01] sync: first pts audio 0x2 is 0
[19:17:01] sync: first pts audio 0x2 is 0
[19:17:01] sync: first pts video is 1393
[19:17:16] sync: reached audio 0x2 pts 2700480, exiting early
[19:17:16] sync: reached audio 0x2 pts 2700480, exiting early
[19:17:17] sync: reached video pts 2700339, exiting early
[19:17:23] work: average encoding speed for job is 46.314545 fps
[19:17:24] dca-decoder done: 9416 frames, 0 decoder errors
[19:17:24] dca-decoder done: 9416 frames, 0 decoder errors
[19:17:24] h264-decoder done: 2388 frames, 0 decoder errors
[19:17:24] sync: got 719 frames, 743 expected
[19:17:24] sync: framerate min 23.976 fps, max 23.976 fps, avg 23.976 fps
x264 [info]: frame I:4     Avg QP: 6.40  size: 39886
x264 [info]: frame P:236   Avg QP:10.59  size: 12261
x264 [info]: frame B:479   Avg QP:11.28  size:  4108
x264 [info]: consecutive B-frames:  4.5%  6.4% 41.3% 47.8%
x264 [info]: mb I  I16..4: 53.3% 45.3%  1.4%
x264 [info]: mb P  I16..4:  4.6%  2.7%  0.2%  P16..4: 28.7%  7.6%  8.1%  0.0%  0.0%    skip:48.1%
x264 [info]: mb B  I16..4:  0.3%  0.1%  0.0%  B16..8: 23.9%  3.2%  0.3%  direct: 1.0%  skip:71.3%  L0:50.0% L1:48.7% BI: 1.3%
x264 [info]: 8x8 transform intra:37.0% inter:82.4%
x264 [info]: direct mvs  spatial:74.1% temporal:25.9%
x264 [info]: coded y,uvDC,uvAC intra: 17.3% 58.3% 51.8% inter: 3.2% 7.6% 0.7%
x264 [info]: i16 v,h,dc,p: 92%  4%  3%  1%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  6%  3% 58%  6%  6%  5%  5%  5%  6%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24%  5% 25% 11%  9%  6%  6%  6%  8%
x264 [info]: i8c dc,h,v,p: 72% 15%  8%  4%
x264 [info]: Weighted P-Frames: Y:5.1% UV:0.8%
x264 [info]: ref P L0: 41.1%  0.4% 22.2% 11.1%  8.9%  7.0%  5.7%  3.1%  0.4%
x264 [info]: ref B L0: 55.5% 18.4% 11.9%  5.7%  4.3%  3.2%  1.0%
x264 [info]: ref B L1: 96.7%  3.3%
x264 [info]: kb/s:1339.38
[19:17:24] mux: track 0, 719 frames, 5020547 bytes, 1335.62 kbps, fifo 1024
[19:17:24] mux: track 1, 2813 frames, 5659756 bytes, 1505.67 kbps, fifo 4096
[19:17:24] mux: track 2, 1409 frames, 677514 bytes, 180.24 kbps, fifo 2048
[19:17:24] Finished work at: Thu Oct 13 19:17:24 2022

[19:17:24] libhb: work result = 0

So after all that description, I guess here's what I'm asking:

1. Is there some set of variables I should adjust that I haven't thought of yet, which might result in a reasonable encode that doesn't look like crap in those first thirty seconds?

2. Barring that, I'd be happy to just use the unmodified blu-ray sourced file for that 30-60 second clip, and merge it into a different encode that is perfectly acceptable in all scenes other than that one. But I don't know if it's possible to merge one scene encoded one way with other scenes encoded a different way. I tried using MKVToolnix to do this, but because the scenes I'm trying to merge were encoded with different settings, it doesn't work, freezing when the video gets to the part where a 'boundary' between the encodes exists. Is there a way to have Handbrake encode one scene or chapter with one set of encoding values (or none at all), and other scenes or chapters with different values?

Thank you,
GreenT
tlindgren
Bright Spark User
Posts: 260
Joined: Sun May 03, 2009 2:14 pm

Re: Encoding options for difficult scene

Post by tlindgren »

Not sure if it'd make any difference but I'd try doing a 10-bit encode and/or try the no-dct-decimate option.
IIRC both can sometimes help with situations that sounds a BIT like your issue, so definitely not guaranteeing it'll help but... worth testing given that you should be able to just encode the start and see if it helps, so even trying all three won't take long.
mduell
Veteran User
Posts: 8207
Joined: Sat Apr 21, 2007 8:54 pm

Re: Encoding options for difficult scene

Post by mduell »

The best way I can think of to address this scene would be a 2 pass encode with a different QP target for those 30 seconds. You can do this by editing the stats file between the first and second encodes to adjust quality for that critical time range. Easier to do with other tools like ffmpeg that require seperate commends for the first and second pass rather than HB that runs them sequentially.
GreenT
Posts: 2
Joined: Thu Oct 13, 2022 9:56 pm

Re: Encoding options for difficult scene

Post by GreenT »

Thanks for the replies to both of you. I will try those options, tlindgren, to see if they help. If they don't, I'll try what mduell suggests, though I have to say upfront I'm not sure how that would work. Each pass applies to the entire movie, right? Or am I just misunderstanding, and there's a way to have one set of encoding options for a small segment of the file, with different encoding options for everything else?
mduell
Veteran User
Posts: 8207
Joined: Sat Apr 21, 2007 8:54 pm

Re: Encoding options for difficult scene

Post by mduell »

The first pass writes a stats file that the second pass uses to make better decisions. Adjust the section of that file related to the difficult scene to have the encoder throw more bits at only that scene.
Post Reply