Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twitch stream stutters on key frames when using H264 main profile with Safari. #1676

Open
finnvoor opened this issue Jan 29, 2025 · 4 comments
Milestone

Comments

@finnvoor
Copy link

finnvoor commented Jan 29, 2025

Observed behavior

When using the recommended Twitch settings of:

  • 4,500kbps bitrate
  • 1920x1080 video
  • kVTProfileLevel_H264_Main_AutoLevel

The stream stutters every 2 seconds, presumably when a key frame is sent. I'm not 100% sure, but I believe this is because the video encoder takes longer to encode the key frames, and P frames are sent before the key frame is sent. They have correct timestamps, but it seems like Twitch doesn't like how far apart they are, and drops frames. Streaming with the exact same settings to YouTube works fine.

Expected behavior

The video should be smooth and not drop any frames.

To Reproduce

This can be reproduced in the iOS example project by adding:

await stream?.setVideoSettings(.init(
    videoSize: CGSize(width: 1080, height: 1920),
    bitRate: 4_500_000,
    profileLevel: kVTProfileLevel_H264_Main_AutoLevel as String
))

in the HKStreamSwitcher and commenting out the slider code where the bitrate is set. Then streaming to Twitch drops frames.

Version

2.0.3

Smartphone info.

iPhone 16 Pro
iOS 18.3

Additional context

  • Default Twitch URL: rtmp://ingest.global-contribute.live-video.net/app
  • Twitch EU URL: rtmp://ams02.contribute.live-video.net/app
@shogo4405
Copy link
Owner

shogo4405 commented Feb 2, 2025

Thank u feedback. I thought it was caused by the 2.0.0 series, but the same issue occurred in the 1.9.x series as well. Since it's the main profile, I believe it's related to the handling of compositionTimeStamp, so I'll take a look.

MAIN PROFILE

2.0.x

  • 🆖 macOS + Safari
  • 🆗 macOS + Chrome

1.9.x

  • 🆖 macOS + Safari
  • 🆗 macOS + Chrome

BASE PROFILE

1.9.x

  • 🆗 macOS + Safari
  • 🆗 macOS + Chrome

@finnvoor
Copy link
Author

finnvoor commented Feb 4, 2025

Great, thanks. We're currently working on implementing live streaming in the Detail iOS app and so far everything else is working great, we're testing YouTube/Instagram/LinkedIn streaming on a variety of devices. Just having some trouble with Twitch. Let us know if we can help test on any devices/platforms!

@shogo4405
Copy link
Owner

Hello, and thank you for your long-term support.

As expected, it seemed to be an issue related to the calculation of compositionTimeStamp.
I still need to conduct some more testing, but I plan to proceed in this direction.
https://github.com/shogo4405/HaishinKit.swift/pull/1680/files

@shogo4405 shogo4405 added this to the 2.0.4 milestone Feb 9, 2025
@shogo4405
Copy link
Owner

I believe it was fixed in 52c707b. Please try.

@shogo4405 shogo4405 changed the title Twitch stream stutters on key frames when using high bitrate/resolution Twitch stream stutters on key frames when using H264 main profile with Safari. Feb 10, 2025
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

No branches or pull requests

2 participants