Skip to content

libhb: signal stereo 3d frame packing in the x264 encoder - #8100

Merged
galad87 merged 1 commit into
HandBrake:masterfrom
Sparky-OS:stereo3d-x264-frame-packing
Sep 16, 2026
Merged

galad87 merged 1 commit into
HandBrake:masterfrom
Sparky-OS:stereo3d-x264-frame-packing

Conversation

@danielcamposramos

Copy link
Copy Markdown
Contributor

Before Posting:

Description of Change:

Commit 1d20876 preserves stereo 3D metadata at the container level. This adds the elementary stream half: when the source is side-by-side or top-bottom, map job->stereo_3d.type to x264's i_frame_packing so x264 writes the frame_packing_arrangement SEI (payload type 45) before each keyframe.

Twelve lines in libhb/encx264.c, no new dependency:

  • the value is already available — job->stereo_3d is populated at libhb/common.c:4970 and the detected layout is already logged at libhb/work.c:719;
  • only HB_STEREO3D_SIDEBYSIDE → 3 and HB_STEREO3D_TOPBOTTOM → 4 are mapped, the two layouts that map unambiguously to the H.264 arrangement types;
  • the SEI is ignorable metadata, so players that do not parse it are unaffected.

As noted in the issue, this only applies to x264: it is the one H.264 encoder in HandBrake exposing frame packing (x264.h, int i_frame_packing). VideoToolbox, QSV, NVENC and AMF have no equivalent parameter, and x265 defines the payload type without a writer. FFmpeg's libx264 wrapper has done the same mapping since 2013 (09cb75cd).

Why it matters: hardware that auto-engages 3D — 2011/2012 era 3D TVs, verified live on Sony BRAVIA sets — reads the SEI from the elementary stream and ignores the container tag. Without this, a HandBrake re-encode of an SBS source plays flat on those displays; with it, they switch to 3D automatically. In a 44 title 3D MKV library surveyed for the issue, 43/44 carried the container tag and 0/44 carried the SEI.

Tested on:

  • Windows 10+ (via MinGW)
  • macOS 10.13+
  • Ubuntu Linux

Not yet build-tested by me — the change is a straight parameter assignment alongside the existing VUI setup, but I am happy to build and verify on Ubuntu (or adjust placement/style) before merge if you prefer.

Screenshots (If relevant): n/a

Log file output (If relevant): n/a

Map the stereo 3d layout detected by the demuxer to x264's
i_frame_packing, so the frame_packing_arrangement SEI (payload type 45)
is written into the H.264 elementary stream in addition to the container
level metadata preserved by 1d20876.

Only side-by-side and top-bottom are mapped; x264 is the only H.264
encoder in HandBrake that exposes this parameter.

Re HandBrake#5826

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@galad87

galad87 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Please test it, no one here has got a 3D TV.

@danielcamposramos

Copy link
Copy Markdown
Contributor Author

Please test it, no one here has got a 3D TV.

I've tested in two Sony BRAVIA 3D from the 2011 2012 era - working. This is following up on this issue: #5826

What I could not test is with other makers, but since is the same standard for DVB 3D transmissions, they also should work.

@galad87
galad87 merged commit b0145ad into HandBrake:master Sep 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants