Giter Club home page Giter Club logo

Comments (5)

shogo4405 avatar shogo4405 commented on May 18, 2024

https://github.com/shogo4405/lf.swift/blob/master/Application/Application/LiveViewController.swift#L99

// 1st step:  Comment-out line
// rtmpStream.attachCamera(AVMixer.deviceWithPosition(.Back))
// 2nd step: Remove Comment-out Line
rtmpStream.attachScreen(ScreenCaptureSession())

from haishinkit.swift.

pzs7602 avatar pzs7602 commented on May 18, 2024

thanks! it works. can rtmpStream attach both camera and screen capture?

from haishinkit.swift.

shogo4405 avatar shogo4405 commented on May 18, 2024

library has no this feature.
I think can create this feature. custom VIsualEffect Plugin.

// example Custom VisualEffect
final class CameraMixEffect: VisualEffect, AVCaptureVideoDataOutputSampleBufferDelegate {
    let filter:CIFilter? = CIFilter(name: "CISourceOverCompositing")
    var camera:CIImage?
    var lockQueue:dispatch_queue_t? dispatch_queue_create(
         "CameraMixEffect.lock", DISPATCH_QUEUE_SERIAL
   )

    override init() {
        super.init()
    }

    override func execute(image: CIImage) -> CIImage {
        guard let filter:CIFilter = filter else {
            return image
        }
        dispatch_async(lockQueue) {
            self.filter.setValue(camera, forKey: "inputImage")
            self.filter.setValue(image, forKey: "inputBackgroundImage")
        }
        return filter.outputImage!
    }

    func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
        guard let image:CVImageBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer) else {
            return
        }
        camera = CIImage(CVPixelBuffer:  image)
    }
}

// next 
var session = AVCaptureSession()
var videoOutput =  AVCaptureVideoDataOutput()
session.addInput(try! AVCaptureDeviceInput(device: camera))
session.addOutput(videoDataOutput)

var effect = CameraMixEffect()
videoOutput.setSampleBufferDelegate(effect, queue: effect.lockQueue)

var stream:RTMPStream = RTMPStream()
stream.registerEffect(effect)

from haishinkit.swift.

pzs7602 avatar pzs7602 commented on May 18, 2024

I try this, but the camera image does not shown over the device screen, perhaps the camera image's position or size must be set properly?
I can get the image data from didOutputSampleBuffer method and display it on the screen, that also what I need.
anyway, thank you very much!

from haishinkit.swift.

tatuanfpt avatar tatuanfpt commented on May 18, 2024

Is this solution still work?
Consider about adding some UIView from screen as a layer to Device Camera for a better quality in comparison with recording screen (which result in high CPU + low FPS).

from haishinkit.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.