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.76k stars 612 forks source link

RTMPStream resolution locked at 480x272 #981

Closed kenle closed 2 years ago

kenle commented 2 years ago

Describe the bug High, I'm following the examples on homepage and in iOS directory, but cannot get the rtmpStream.videoSettings to listen to the .width and .height parameters, it always outputs 480x272. I saw previous bugs (#360) reported on this but you said it was a framework bug. How comes the examples shows setting resolution, but it may not have any affect?

To Reproduce Steps to reproduce the behavior: For example, I tried the homepage example:

rtmpStream.videoSettings = [
    .width: 640, // video output width
    .height: 360, // video output height
    .bitrate: 160 * 1000, // video output bitrate
    .profileLevel: kVTProfileLevel_H264_Baseline_3_1, // H264 Profile require "import VideoToolbox"
    .maxKeyFrameIntervalDuration: 2, // key frame / sec
]

I am also using ReplayKit to stream to youtube with the following line:

    RPScreenRecorder.shared().startCapture(
        handler: { (cmSampleBuffer, rpSampleType, error) in
          guard error == nil else {
            return;
          }
      switch rpSampleType {
        case RPSampleBufferType.video:
...
        rtmpStream.appendSampleBuffer(cmSampleBuffer, withType: .video);

Expected behavior I expect it to stream the desired resolution, for example 640x360, or whatever I set the resolution to.

Screenshots Screenshot from youtube rtmp stream:

Screen Shot 2022-04-06 at 4 45 38 PM

Smartphone (please complete the following information):

shogo4405 commented 2 years ago

I fixed this issue https://github.com/shogo4405/HaishinKit.swift/issues/360 4years ago. Currentry, It works for me Examples. I can publish 720x1280.

Duration: 00:00:00.00, start: 10.240000, bitrate: N/A
Stream #0:0: Audio: aac (LC), 48000 Hz, mono, fltp, 32 kb/s
Stream #0:1: Video: h264 (Baseline), yuv420p(tv, progressive), 720x1280, 422 kb/s, 30 fps, 30 tbr, 1k tbn
kenle commented 2 years ago

Yes, I thought this was fixed as well, at some point I remember it was working for me.

But recently, it seems to have reverted. I've checked everything and am a bit confused at the moment.

kenle commented 2 years ago

@shogo4405 I resolved it :)

I have to call this every time before appending to the rtmpStream, and I get the resolution I desire! Thank you for your great library.

                if let description = CMSampleBufferGetFormatDescription(cmSampleBuffer) {
                    let dimensions = CMVideoFormatDescriptionGetDimensions(description)
                    self.rtmpStream?.videoSettings = [
                        .width: dimensions.width,
                        .height: dimensions.height,
                        .profileLevel: kVTProfileLevel_H264_Baseline_AutoLevel,
                        .maxKeyFrameIntervalDuration: 2,
                        .bitrate: 1200 * 1024
                    ]
                    self.rtmpStream?.captureSettings = [
                        .fps: 24
                    ]
                }

                self.rtmpStream?.appendSampleBuffer(cmSampleBuffer, withType: .video);
Andriiklymiuk commented 1 year ago

On what version changing videoSettings works? cause it still seems in 1.4.3 it randomly stops working