Skip to content

H265Packet: pack multi-slice HEVC access units as one unit (YouTube enhanced-RTMP) - #2223

Closed
yeheskel2016 wants to merge 1 commit into
pedroSG94:masterfrom
yeheskel2016:stadium-2.8.1
Closed

yeheskel2016 wants to merge 1 commit into
pedroSG94:masterfrom
yeheskel2016:stadium-2.8.1

Conversation

@yeheskel2016

Copy link
Copy Markdown

Fixes #2222

Problem

Since 2.8.0 (NalReader.extractNals, #2086) H265Packet writes one length-prefixed NAL per slice inside a single enhanced-RTMP video tag. On encoders that emit multiple slice segments per picture (e.g. Qualcomm SD888 c2.qti.hevc.encoder: 3 slices/AU at 1080p), YouTube's enhanced-RTMP HEVC ingest only consumes the first NAL of the tag and the broadcast stays on "preparing" forever, while the publisher reports a healthy connection. 2.7.2 shipped the whole access unit as one unit and worked.

Change

rtmp/.../flv/video/packet/H265Packet.kt only: when nals.size > 1, pack the access unit as one length-prefixed unit with 00 00 00 01 between slices (the 2.7.2 layout). Single-NAL frames keep the existing per-NAL packaging, so #2086 is unaffected for them.

Verification

Same app, 1080p60 HEVC Main, 2 s GOP, against YouTube and a local SRS 6 relay (FLV parsed per tag):

Device Slices/AU Before (2.8.1) After
Mi 11 Ultra (SD888, Android 14) 3 [(19,43267),(19,41780),(19,43012)] → YouTube "preparing" [(19,128075, 2 inner start codes)] → renders
Xiaomi 15 (SD8 Elite, Android 16) 1 [(20,30940)] → OK unchanged → OK

Both ~60 fps, IDR every 2 s, decode clean in ffmpeg/VLC.

Happy to put this behind a flag if you'd prefer strict per-NAL packaging as the default.

…nced-RTMP

YouTube's HEVC ingest only consumes the first length-prefixed NAL per video
tag. Encoders that emit one slice segment per tile (Qualcomm SD888) therefore
produce a permanently 'preparing' stream with 2.8.0+ per-NAL packaging.
Join slices with Annex-B start codes inside a single unit (2.7.2 behaviour,
verified decodable by YouTube). Single-NAL frames are byte-identical.
@yeheskel2016

Copy link
Copy Markdown
Author

*This PR was generated using AI, Claude Fable 5.1 model
Basically the issue was after I updated the libary to 2.8.1, an old phone I have (MI11 Ultra) couldnt stream anymore HEVC to Youtube (it would stuck on "Preparing video") while newer phone (MI15) did work, when downgrade back to 2.7.2 the MI11 again worked, when letting Claude diagnose both streams from both versions it discovered this change (as explained above)
When testing his suggetion of converting like what was in previous version I tested both phones and both works, I am not sure if this change may have caused other hidden regression so cant confirm it, if this PR is problematic I can open it as just a bug issue for you to check ;-)

Thanks for the amazing libary!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RTMP HEVC: multi-slice access units packed as separate NALs (2.8.0+) are not decoded by YouTube ("preparing" forever); worked in 2.7.2

1 participant