HandBrake Workflow

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
DKqwerty
Posts: 11
Joined: Wed May 29, 2019 5:02 pm

HandBrake Workflow

Post by DKqwerty »

Description of problem or question:

I'm trying to determine the exact workflow of HandBrake related to dimensions: is cropping applied before or after resizing?

In addition, if cropping the original frames' dimensions: is HB cropping against the anamorphic storage dimension (i.e. a DVD at 720x480i) or the display dimension (DVD at 640x480p)?

And finally, does the .json for an encode determine the order in which the workflow proceeds (i.e. would flipping the cropping and resizing sections of filter 12 affect the order), or are these values simply read in any order with the workflow hard-coded into the software?

Steps to reproduce the problem (If Applicable):

Try cropping a 16:9 video out of an anamorphic DVD encoded as 4:3 letterboxing :roll: … it's maddening to keep the aspect ratio correct.


HandBrake version (e.g., 1.0.0):

1.3.1 x64 (portable)


Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):

Windows 10 Pro x64 (1909)


HandBrake Activity Log:

Code: Select all

HandBrake 1.3.1 (2020010400)
OS: Microsoft Windows NT 10.0.18363.0
CPU: Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz
Ram: 8169 MB, 
GPU Information:
  NVIDIA GeForce GTX 460M - 23.21.13.8857
Screen: 1920x1080
Temp Dir: C:\Users\David\AppData\Local\Temp\
Install Dir: X:\Installers\HandBrake-1.3.1-x86_64-Win_GUI
Data Dir: C:\Users\David\AppData\Roaming\HandBrake

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


# Starting Encode ...

[07:43:34] hb_init: starting libhb thread
[07:43:34] Starting work at: Thu Feb 20 07:43:34 2020
[07:43:34] 1 job(s) to process
[07:43:34] json job:
{
  "Audio": {
    "AudioList": [
      {
        "Bitrate": 160,
        "DRC": 0.0,
        "Encoder": "ac3",
        "Gain": 0.0,
        "Mixdown": 4,
        "NormalizeMixLevel": false,
        "Samplerate": 0,
        "Track": 0,
        "DitherMethod": 0
      },
      {
        "DRC": 0.0,
        "Encoder": "copy",
        "Gain": 0.0,
        "Mixdown": -1,
        "NormalizeMixLevel": false,
        "Samplerate": 0,
        "Track": 1,
        "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"
      },
      {
        "Name": "Chapter 10"
      },
      {
        "Name": "Chapter 11"
      },
      {
        "Name": "Chapter 12"
      },
      {
        "Name": "Chapter 13"
      },
      {
        "Name": "Chapter 14"
      },
      {
        "Name": "Chapter 15"
      },
      {
        "Name": "Chapter 16"
      }
    ],
    "ChapterMarkers": true,
    "AlignAVStart": false,
    "File": "E:\\Quick_preview.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": 12,
        "Settings": {
          "crop-bottom": "0",
          "crop-left": "0",
          "crop-right": "0",
          "crop-top": "0",
          "height": "480",
          "width": "640"
        }
      },
      {
        "ID": 6,
        "Settings": {
          "mode": "0"
        }
      }
    ]
  },
  "PAR": {
    "Num": 1,
    "Den": 1
  },
  "Metadata": {},
  "SequenceID": 0,
  "Source": {
    "Angle": 1,
    "Range": {
      "Type": "preview",
      "Start": 1,
      "End": 2700000,
      "SeekPoints": 25
    },
    "Title": 2,
    "Path": "M:\\Recordings\\Music DVD\\Quick"
  },
  "Subtitle": {
    "Search": {
      "Burn": false,
      "Default": false,
      "Enable": false,
      "Forced": false
    },
    "SubtitleList": []
  },
  "Video": {
    "Encoder": "x264",
    "Level": "auto",
    "TwoPass": false,
    "Turbo": false,
    "ColorMatrixCode": 0,
    "Options": "rc-lookahead=60:bframes=5:ref=4:merange=64",
    "Preset": "veryfast",
    "Profile": "auto",
    "Quality": 15.0,
    "Tune": "grain",
    "QSV": {
      "Decode": false,
      "AsyncDepth": 0
    }
  }
}
[07:43:34] CPU: Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz
[07:43:34]  - Intel microarchitecture Sandy Bridge
[07:43:34]  - logical processor count: 8
[07:43:34] Intel Quick Sync Video support: no
[07:43:34] hb_scan: path=M:\Recordings\Music DVD\Quick, title_index=2
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
src/libbluray/bluray.c:2585: nav_get_title_list(M:\Recordings\Music DVD\Quick\) failed
[07:43:34] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 6.0.1
libdvdread: Could not open M:\Recordings\Music DVD\Quick with libdvdcss.
libdvdread: Can't open M:\Recordings\Music DVD\Quick for reading
libdvdread: Device M:\Recordings\Music DVD\Quick inaccessible, CSS authentication not available.
libdvdnav: Unable to open device file M:\Recordings\Music DVD\Quick.
libdvdnav: vm: dvd_read_name failed
libdvdnav: DVD disk reports itself with Region mask 0x00c20000. Regions: 1 3 4 5 6
libdvdread: Could not open M:\Recordings\Music DVD\Quick with libdvdcss.
libdvdread: Can't open M:\Recordings\Music DVD\Quick for reading
libdvdread: Device M:\Recordings\Music DVD\Quick inaccessible, CSS authentication not available.
[07:43:34] scan: DVD has 12 title(s)
[07:43:34] scan: scanning title 2
[07:43:34] scan: duration is 01:33:19 (5599033 ms)
[07:43:34] pgc_id: 1, pgn: 1: pgc: 0000014D1AAAB630
[07:43:34] scan: checking audio 1
[07:43:34] scan: id=0xa0bd, lang=English (LPCM), 3cc=eng ext=0
[07:43:34] scan: checking audio 2
[07:43:34] scan: id=0x81bd, lang=English (AC3), 3cc=eng ext=0
[07:43:34] scan: title 2 has 16 chapters
[07:43:34] scan: chap 1, 119900 ms
[07:43:34] scan: chap 2, 527800 ms
[07:43:34] scan: chap 3, 477700 ms
[07:43:34] scan: chap 4, 440100 ms
[07:43:34] scan: chap 5, 205500 ms
[07:43:34] scan: chap 6, 373900 ms
[07:43:34] scan: chap 7, 514700 ms
[07:43:34] scan: chap 8, 399800 ms
[07:43:34] scan: chap 9, 489600 ms
[07:43:34] scan: chap 10, 178500 ms
[07:43:34] scan: chap 11, 508400 ms
[07:43:34] scan: chap 12, 353400 ms
[07:43:34] scan: chap 13, 577200 ms
[07:43:34] scan: chap 14, 358500 ms
[07:43:34] scan: chap 15, 73500 ms
[07:43:34] scan: chap 16, 533 ms
[07:43:34] scan: aspect = 4:3
[07:43:34] scan: decoding previews for title 2
libdvdnav: DVD disk reports itself with Region mask 0x00c20000. Regions: 1 3 4 5 6
[07:43:34] scan: title angle(s) 1
[07:43:34] scan: audio 0xa0bd: LPCM, rate=48000Hz, bitrate=1536000 English (LPCM) (2.0 ch) (1536 kbps)
[07:43:34] scan: audio 0x81bd: ac3, rate=48000Hz, bitrate=448000 English (AC3) (5.1 ch) (448 kbps)
[07:43:34] scan: 10 previews, 720x480, 29.970 fps, autocrop = 64/66/6/28, aspect 4:3, PAR 8:9
[07:43:34] Title is likely interlaced or telecined (5 out of 10 previews). You should do something about that.
[07:43:34] libhb: scan thread found 1 valid title(s)
[07:43:34] Starting Task: Encoding Pass
[07:43:34] Skipping vfr filter
[07:43:34] Auto Passthru: allowed codecs are AAC, AC3, E-AC3, TrueHD, DTS, DTS-HD, MP3, FLAC
[07:43:34] Auto Passthru: fallback is AC3
[07:43:34] Auto Passthru: using AC3 Passthru for track 2
[07:43:34] job configuration:
[07:43:34]  * source
[07:43:34]    + M:\Recordings\Music DVD\Quick
[07:43:34]    + title 2, start 00:00:0.00 stop 00:00:30.00
[07:43:34]  * destination
[07:43:34]    + E:\Quick-2_preview.mkv
[07:43:34]    + container: Matroska (libavformat)
[07:43:34]      + chapter markers
[07:43:34]  * video track
[07:43:34]    + decoder: mpeg2video
[07:43:34]      + bitrate 200 kbps
[07:43:34]    + filters
[07:43:34]      + 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)
[07:43:34]      + Decomb (mode=39)
[07:43:34]      + Crop and Scale (width=640:height=480:crop-top=0:crop-bottom=0:crop-left=0:crop-right=0)
[07:43:34]        + source: 720 * 480, crop (0/0/0/0): 720 * 480, scale: 640 * 480
[07:43:34]    + Output geometry
[07:43:34]      + storage dimensions: 640 x 480
[07:43:34]      + pixel aspect ratio: 1 : 1
[07:43:34]      + display dimensions: 640 x 480
[07:43:34]    + encoder: H.264 (libx264)
[07:43:34]      + preset:  veryfast
[07:43:34]      + tune:    grain
[07:43:34]      + options: rc-lookahead=60:bframes=5:ref=4:merange=64
[07:43:34]      + profile: auto
[07:43:34]      + level:   auto
[07:43:34]      + quality: 15.00 (RF)
[07:43:34]      + color profile: 6-1-6
[07:43:34]  * audio track 1
[07:43:34]    + decoder: English (LPCM) (2.0 ch) (1536 kbps) (track 1, id 0xa0bd)
[07:43:34]      + bitrate: 1536 kbps, samplerate: 48000 Hz
[07:43:34]    + mixdown: Stereo
[07:43:34]    + dither: none
[07:43:34]    + encoder: AC3 (libavcodec)
[07:43:34]      + bitrate: 160 kbps, samplerate: 48000 Hz
[07:43:34]  * audio track 2
[07:43:34]    + decoder: English (AC3) (5.1 ch) (448 kbps) (track 2, id 0x81bd)
[07:43:34]      + bitrate: 448 kbps, samplerate: 48000 Hz
[07:43:34]    + AC3 Passthru
libdvdnav: Using dvdnav version 6.0.1
libdvdread: Could not open M:\Recordings\Music DVD\Quick with libdvdcss.
libdvdread: Can't open M:\Recordings\Music DVD\Quick for reading
libdvdread: Device M:\Recordings\Music DVD\Quick inaccessible, CSS authentication not available.
libdvdnav: Unable to open device file M:\Recordings\Music DVD\Quick.
libdvdnav: vm: dvd_read_name failed
libdvdnav: DVD disk reports itself with Region mask 0x00c20000. Regions: 1 3 4 5 6
libdvdread: Could not open M:\Recordings\Music DVD\Quick with libdvdcss.
libdvdread: Can't open M:\Recordings\Music DVD\Quick for reading
libdvdread: Device M:\Recordings\Music DVD\Quick inaccessible, CSS authentication not available.
libdvdnav: DVD disk reports itself with Region mask 0x00c20000. Regions: 1 3 4 5 6
[07:43:34] sync: expecting 929 video frames
[07:43:34] encx264: min-keyint: 30, keyint: 300
[07:43:34] encx264: encoding at constant RF 15.000000
[07:43:34] encx264: unparsed options: rc-lookahead=60:bframes=5:ref=4:merange=64:deblock=-2,-2:weightp=1:subme=2:mixed-refs=0:trellis=0:dct-decimate=0:psy-rd=1,0.25:deadzone-inter=6:deadzone-intra=6:ipratio=1.1:qcomp=0.8:aq-strength=0.5
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
x264 [info]: profile High, level 3.0, 4:2:0, 8-bit
[07:43:34] sync: first pts audio 0xa0bd is 0
[07:43:34] sync: first pts audio 0x81bd is 5701
[07:43:34] sync: first pts video is 25827
[07:43:34] sync: "Chapter 2" (2) at frame 1 time 25827
[07:43:40] sync: reached audio 0xa0bd pts 2700450, exiting early
[07:43:40] sync: reached audio 0x81bd pts 2701381, exiting early
[07:43:40] sync: reached video pts 2701500, exiting early
[07:43:41] work: average encoding speed for job is 140.590408 fps
[07:43:41] comb detect: heavy 669 | light 114 | uncombed 108 | total 891
[07:43:41] decomb: deinterlaced 669 | blended 114 | unfiltered 108 | total 891
[07:43:41] ac3-decoder done: 1395 frames, 0 decoder errors
[07:43:41] mpeg2video-decoder done: 1336 frames, 0 decoder errors
[07:43:41] sync: got 891 frames, 929 expected
[07:43:41] sync: framerate min 29.970 fps, max 29.970 fps, avg 29.970 fps
x264 [info]: frame I:14    Avg QP:12.75  size: 65715
x264 [info]: frame P:197   Avg QP:14.01  size: 36433
x264 [info]: frame B:680   Avg QP:16.43  size: 15579
x264 [info]: consecutive B-frames:  2.9%  4.5%  9.4% 13.9% 10.7% 58.6%
x264 [info]: mb I  I16..4: 33.8%  6.3% 59.9%
x264 [info]: mb P  I16..4:  8.0%  4.7%  4.2%  P16..4: 37.0%  9.8% 12.7%  0.0%  0.0%    skip:23.6%
x264 [info]: mb B  I16..4:  1.4%  1.0%  0.1%  B16..8: 20.5%  9.8%  4.9%  direct:24.5%  skip:37.9%  L0:27.1% L1:32.2% BI:40.7%
x264 [info]: 8x8 transform intra:26.5% inter:28.9%
x264 [info]: coded y,uvDC,uvAC intra: 64.3% 65.7% 57.0% inter: 45.0% 31.0% 16.1%
x264 [info]: i16 v,h,dc,p: 56% 20% 21%  2%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 14% 36%  2%  3%  5%  2%  4%  4%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 19% 12%  6%  8%  9%  7%  8%  8%
x264 [info]: i8c dc,h,v,p: 53% 20% 22%  6%
x264 [info]: Weighted P-Frames: Y:2.5% UV:0.0%
x264 [info]: ref P L0: 67.3% 21.3% 11.2%  0.2%
x264 [info]: ref B L0: 84.9% 12.7%  2.4%
x264 [info]: ref B L1: 95.4%  4.6%
x264 [info]: kb/s:5029.55
[07:43:41] mux: track 0, 891 frames, 18690328 bytes, 4979.11 kbps, fifo 512
[07:43:41] mux: track 1, 937 frames, 599680 bytes, 159.75 kbps, fifo 1024
[07:43:41] mux: track 2, 936 frames, 1677312 bytes, 446.84 kbps, fifo 1024
[07:43:41] Finished work at: Thu Feb 20 07:43:41 2020
[07:43:41] libhb: work result = 0

# Encode Completed ...

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

Re: HandBrake Workflow

Post by mduell »

Cropping is applied before resizing, on the storage dimensions, regardless of ordering of preset markup.

Math should be easy in your case if it's clean with no other padding (which autocrop indicates there may be).

If autocrop is wrong: Display is 640 wide, so a 16:9 picture is 360 tall. Storage vertical dimension is the same as display vertical dimensions, so crop (480-360)/2 or 60 from each top and bottom. Leave anamorphic with same 8:9 PAR as source.

If autocrop is right about the left and right padding: Just use the autocrop values and leave it anamorphic with the same 8:9 PAR as the source.

DKqwerty
Posts: 11
Joined: Wed May 29, 2019 5:02 pm

Re: HandBrake Workflow

Post by DKqwerty »

Interesting. I'm surprised to you would say I should leave the content anamorphic. I've always assumed for modern playback devices encoding PAR 1x1 would be preferred. Plus, I normally get visually transparent results encoding at 1x1 with a ~33% savings in file size. And by deinterlacing the content I'm already heavily altering the original frames, so I'm not sure what is gained by leaving the content anamorphic. Any explanation (no matter how technical) is welcome!

I should have also specified: the source I'm working with is garbage. The letterboxing is 68px on top, 70px on bottom, plus the normal ~8px black bars on the left and right. There's also an extra swath of ~24px black pixels which—for certain cameras' angles—appear, disappear, and reappear along the right side throughout the entire program.

To avoid this annoyance, I'm "overcropping" the content. I'm attempting to encode both just the true, "safe" visible dimensions (i.e free aspect ratio), plus another which "overcrops" the top and bottom to create true 16:9 frames. Either way, they look like garbage, but I need to know which ends up looking like better garbage (at least to my eye).

To get a handle on all of this, I ended up just grabbing a single frame at original storage dimensions, cropped out the black borders in GIMP, then just used those crops in HandBrake. To verify I was at the correct storage dimension to keep aspect for my output, I scale the original frame's 720px width to 640px in GIMP and verify that the cropped frames are going to be stored correctly (sometimes HB's math gets wonky).

There's undoubtly an easier way, but since the preview window for "Anamorphic > None" isn't displayed at the correct output dimensions for some reason, it's much harder.

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

Re: HandBrake Workflow

Post by mduell »

DKqwerty wrote:
Fri Feb 21, 2020 12:55 am
Interesting. I'm surprised to you would say I should leave the content anamorphic. I've always assumed for modern playback devices encoding PAR 1x1 would be preferred. Plus, I normally get visually transparent results encoding at 1x1 with a ~33% savings in file size. And by deinterlacing the content I'm already heavily altering the original frames, so I'm not sure what is gained by leaving the content anamorphic. Any explanation (no matter how technical) is welcome!
There's two ways to get from anamorpic to 1:1 PAR - more pixels (a waste of space to store) or less pixels ([Censored] away some image quality).
Modern playback devices have no problem with anamorphic, so why would you choose either of the above over retaining anamorphic? Sure anamorphic is kinda gross, and I wouldn't advocate it for any new content, but it works just fine on modern devices.

Savings in filesize are a mutli-dimension tradeoff against quality and encoding time. Most users talking about visually transparent results are picking excessively high quality targets anyway.

Deinterlacing doesn't change the number of pixels you end up with (unless you use some real dumb methods), you've still got the same horizontal resolution.

With the DVD source, plus cropping to eliminate the border crap, you're already real low on pixels. Why [Censored] away another 10% (or try to invent 10% from whole cloth) trying to deanamorph when contemporary playback environments are fine with it?
DKqwerty wrote:
Fri Feb 21, 2020 12:55 am
I should have also specified: the source I'm working with is garbage. The letterboxing is 68px on top, 70px on bottom, plus the normal ~8px black bars on the left and right. There's also an extra swath of ~24px black pixels which—for certain cameras' angles—appear, disappear, and reappear along the right side throughout the entire program.

To avoid this annoyance, I'm "overcropping" the content. I'm attempting to encode both just the true, "safe" visible dimensions (i.e free aspect ratio), plus another which "overcrops" the top and bottom to create true 16:9 frames. Either way, they look like garbage, but I need to know which ends up looking like better garbage (at least to my eye).

To get a handle on all of this, I ended up just grabbing a single frame at original storage dimensions, cropped out the black borders in GIMP, then just used those crops in HandBrake. To verify I was at the correct storage dimension to keep aspect for my output, I scale the original frame's 720px width to 640px in GIMP and verify that the cropped frames are going to be stored correctly (sometimes HB's math gets wonky).

There's undoubtly an easier way, but since the preview window for "Anamorphic > None" isn't displayed at the correct output dimensions for some reason, it's much harder.
You should be rescaling to the storage width in GIMP before figuring out your crops. That would solve your math problems (assuming you stay anamorphic per above).

Don't worry about the exact AR of the output. It will be correct (neither stretched nor squished) and reflect what content you have left after cropping out the garbage.

Post Reply