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

Stream is always portrait in Broadcast Upload Extension #481

Closed arslan2012 closed 5 years ago

arslan2012 commented 5 years ago

Stream is always portrait in Broadcast Upload Extension

I used the exact copy of Examples/iOS/Screencast

When I enter games that are landscape I expect the output to be landscape as well. But it's not.

I tried

broadcaster.stream.syncOrientation = true
// And
broadcaster.stream.orientation = .landscapeLeft

both does not work

shogo4405 commented 5 years ago

Yes. Always portrait :( It seems this behavior is a specification.

arslan2012 commented 5 years ago

Isn't there anyway that can rotate the stream?

arslan2012 commented 5 years ago

ok I made it work by adding a custom effect

final class RotationEffect: VisualEffect {
    override func execute(_ image: CIImage, info: CMSampleBuffer?) -> CIImage {
        guard #available(iOS 11.0, *),
              let info = info,
              let orientationAttachment = CMGetAttachment(info, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber,
              let orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value) else {
            return image
        }
        switch orientation {
        case .left:
            return image.oriented(.right)
        case .right:
            return image.oriented(.left)
        default:
            return image
        }
    }
}

but because RPVideoSampleOrientationKey is only available in ios11 or newer. this does not work on ios10, is there any other way we can get orientation in an VisualEffect? @shogo4405

locorocoo commented 5 years ago

@shogo4405 Any update on this? I'm also experiencing similar issues

shogo4405 commented 5 years ago

@locorocoo No. I won't fix this issue.

Ankush-Redapple commented 4 years ago

@shogo4405 Any update on this? We many developers love this library. It's truly great and save lots of time. Could please help out regarding orientation?

mooncatventures-group commented 4 years ago

@locorocoo No. I won't fix this issue.

The fact that this library doesn't handle orientation changes to landscape, and freezes when you rotate the device makes it unusable for replaykit 2.

joshuadiezmo commented 4 years ago

ok I made it work by adding a custom effect

final class RotationEffect: VisualEffect {
    override func execute(_ image: CIImage, info: CMSampleBuffer?) -> CIImage {
        guard #available(iOS 11.0, *),
              let info = info,
              let orientationAttachment = CMGetAttachment(info, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber,
              let orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value) else {
            return image
        }
        switch orientation {
        case .left:
            return image.oriented(.right)
        case .right:
            return image.oriented(.left)
        default:
            return image
        }
    }
}

but because RPVideoSampleOrientationKey is only available in ios11 or newer. this does not work on ios10, is there any other way we can get orientation in an VisualEffect? @shogo4405

I try this one but my stream become green after I open a landscape app :(

joshuadiezmo commented 4 years ago

@mooncatventures-group do you have any solution for this?

hoifloware commented 4 years ago

Modify AVCaptureVideoDataOutput.connection.videoOrientation worked for me

Can you describe more detail ?

quangphap208 commented 4 years ago

Modify AVCaptureVideoDataOutput.connection.videoOrientation worked for me

Can you describe more detail ?

zungx commented 4 years ago

Modify AVCaptureVideoDataOutput.connection.videoOrientation worked for me

Can you describe more detail ?

Modify AVCaptureVideoDataOutput.connection.videoOrientation worked for me

Can you describe more detail ?

Sorry, I'm wrong. But maybe can you try with this one is make a singleton to hold videoDataOutput. And while device rotate we can modified this output. At the line 328 https://github.com/shogo4405/HaishinKit.swift/blob/master/Sources/Media/VideoIOComponent.swift#L328 put: SingletonX.shared.addVideoOutput(output) Device rotate:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
       coordinator.animate(alongsideTransition: nil, completion: { [weak self] _ in
            guard let self = self else { return }
            guard let orientation = DeviceUtil.videoOrientation(by: UIApplication.shared.statusBarOrientation)
                else { return }
            SingletonX.shared.videoDataOutputs.values.forEach { (output) in
                output.connections.forEach { (connection) in
                    connection.videoOrientation = orientation
                }
            }
        })
    }
nvhnam94 commented 3 years ago

ok I made it work by adding a custom effect

final class RotationEffect: VisualEffect {
    override func execute(_ image: CIImage, info: CMSampleBuffer?) -> CIImage {
        guard #available(iOS 11.0, *),
              let info = info,
              let orientationAttachment = CMGetAttachment(info, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber,
              let orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value) else {
            return image
        }
        switch orientation {
        case .left:
            return image.oriented(.right)
        case .right:
            return image.oriented(.left)
        default:
            return image
        }
    }
}

but because RPVideoSampleOrientationKey is only available in ios11 or newer. this does not work on ios10, is there any other way we can get orientation in an VisualEffect? @shogo4405

I try this one but my stream become green after I open a landscape app :(

you should create CIContext at VideoIOComponent

phamngochai123 commented 1 year ago

ok I made it work by adding a custom effect

final class RotationEffect: VisualEffect {
    override func execute(_ image: CIImage, info: CMSampleBuffer?) -> CIImage {
        guard #available(iOS 11.0, *),
              let info = info,
              let orientationAttachment = CMGetAttachment(info, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber,
              let orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value) else {
            return image
        }
        switch orientation {
        case .left:
            return image.oriented(.right)
        case .right:
            return image.oriented(.left)
        default:
            return image
        }
    }
}

but because RPVideoSampleOrientationKey is only available in ios11 or newer. this does not work on ios10, is there any other way we can get orientation in an VisualEffect? @shogo4405

I get the error EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=50 MB) when using this? Do you have a solution for that?