shogo4405 / HaishinKit.swift

Camera and Microphone streaming library via RTMP and SRT for iOS, macOS, tvOS and visionOS.
BSD 3-Clause "New" or "Revised" License
2.78k stars 615 forks source link

rtmp stream to Wowza server, but playback doesn't work on Safari (and iOS devices) #532

Closed alexwooten closed 5 years ago

alexwooten commented 5 years ago

Describe the bug I have been using HaishinKit on my mac app, for a long time to stream rtmp to my Wowza server, and then playback the hls video (created by Wowza) on iOS devices, but ever since I have updated the HaishinKit and have switched to swift 5, iOS devices and safari refuse to playback the hls, and I cannot update my application now :(

Safari simply displays: "Unsupported Plug-in"

I did a test with Wowza's GoCoder which also publishes rtmp streams, and all goes fine with that (the hls could be played back anywhere), but when streamed with Haishinkit, the playback is broken. Something must have been changed in the recent updates because all other parts of my system are exact same. Help/guidance is much appreciated.

Expected behavior Being able to publish rtmp streams with Haishinkit to Wowza, and then playing back the hls.

shogo4405 commented 5 years ago

@alexwooten Can I see your settings?

print(rtmpStream.captureSettings)
print(rtmpStream.audioSettings)
print(rtmpStream.videoSettings)
alexwooten commented 5 years ago

Here they are:

["continuousAutofocus": 1, "continuousExposure": 1, "sessionPreset": AVCaptureSessionPresetHigh, "fps": 29.97000002997]

["sampleRate": 44100, "bitrate": 32768, "actualBitrate": 32768, "muted": 0]

["scalingMode": Trim, "enabledHardwareEncoder": 1, "muted": 0, "width": 360, "bitrate": 1048576, "dataRateLimits": <Swift.__SwiftDeferredNSArray 0x600000248ec0>(
0,
0
)
, "profileLevel": H264_Baseline_AutoLevel, "maxKeyFrameIntervalDuration": 1, "height": 640]

Thanks a lot.

shogo4405 commented 5 years ago

Try this one.

rtmpStream.captureSettings["profileLevel"] = kVTProfileLevel_H264_Baseline_3_1
MG-Han commented 5 years ago

Hello, @shogo4405 Thanks for the great library!

I have a similar issue. When I broadcast to Wowza streaming engine, the result HLS playlist file couldn't be played on Safari(PC and mobile), AVPlayer, Exoplayer(Android).

There's something unusual. Wowza streaming engine misinterprets the bitrate of the stream. For example, when I set the video bitrate to 3Mbps, in Wowza output HLS shows the bitrate 10 ~ 30 times larger(10 ~ 30Mbps). But in Wowza console, input stream bitrate is 3Mbps, same as I set in Haishinkit.

After end streaming, the recorded video is normal. I can play those recorded videos in any player.

I'm using Xcode 10.2.1(latest version, currently), and Swift 5.

My settings are below.

["sessionPreset": AVCaptureSessionPreset1280x720, "fps": 30, "continuousExposure": 1, "continuousAutofocus": 1]
["bitrate": 32768, "muted": 0, "sampleRate": 0, "actualBitrate": 32768]
["muted": 0, "maxKeyFrameIntervalDuration": 1, "dataRateLimits": <Swift.__SwiftDeferredNSArray 
0x280a79420>(
0,
0
)
, "bitrate": 3145728, "width": 720, "profileLevel": H264_Baseline_3_1, "enabledHardwareEncoder": 1, "scalingMode": Trim, "height": 1280]

Thank you.

alexwooten commented 5 years ago

@shogo4405 I tried with kVTProfileLevel_H264_Baseline_3_1, and same issue still exists.

I have an older version of the HaishinKit framework from a few months ago, running on an older laptop on Swift 4, and when publishing RTMP from there (to the exact same Wowza server), everything is fine and Safari/AVPlayer do the playback fine.

Here are the settings I see on the older version of the HaishinKit with Swift 4 (Note there's a additional profile key on the audio settings compared to the settings we've posted above):

["continuousAutofocus": 1, "fps": 30, "continuousExposure": 1, "sessionPreset": AVCaptureSessionPresetHigh]

["profile": 2, "actualBitrate": 32768, "bitrate": 32768, "muted": 0, "sa1mpleRate": 44100]

["scalingMode": Trim, "maxKeyFrameIntervalDuration": 1, "profileLevel": H264_Baseline_AutoLevel, "dataRateLimits": <Swift._SwiftDeferredNSArray 0x60000003d8a0>(
0,
0
)
, "height": 640, "width": 360, "bitrate": 1048576, "enabledHardwareEncoder": 1, "muted": 0]

Thanks a lot again.

shogo4405 commented 5 years ago

@alexwooten Well... works for me. Please send me .ts file? I reproduced. OK. I will fix. Thank u.

alexwooten commented 5 years ago

Thanks a lot @shogo4405.