Coder Social home page Coder Social logo

yuanfuc / metalmergestreams Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 2.0 44.45 MB

Use Metal to merge front camera stream and video stream. Save into Photos or Live

Swift 27.32% Objective-C 45.77% Metal 0.74% CSS 1.55% HTML 3.67% JavaScript 20.67% Ruby 0.27%
metal metalperformanceshaders cvpixelbuffer ios avfoundation streaming-video live-streaming live

metalmergestreams's Introduction

Metal merge streams

Use Metal to merge CVPixelBuffers and resize CVPixelBuffer in hight performance.

Merge frames

  • Time consuming 0.2 ~ 1.5 ms can make sure the living real-time.
  • Inputs are tow CVPixelBuffers. CVPixelBuffer-A (from front camera) and CVPixelBuffer-B (from video 'rtpVideo.mp4'). Output is new CVPixelBuffers.
  • Upload pixel buffer as MTLTexture and in-frame location to GPU
  • MTLComputeCommandEncoder compute new texture

Resize frame

  • Input is CVPixelBuffers. Output is new CVPixelBuffers.
  • MPSImageBilinearScale to resize pixel buffer, support mode ScaleToFill,ScaleAspectFit,ScaleAspectFill

Tow method to create new pixel buufer.

With pixel buffer pool

  • Time consuming 1 ~ 2 ms.
  • Create output CVPixelBuffer from Pixel CVPixelBufferPool
  • Create a new MTLTexture from output CVPixelBuffer
  • Compute and wait for completion
  • Return the result CVPixelBuffer which is IOSurface-backed

Without pixel buffer pool

  • Time consuming 6 ~ 7 ms.
  • Create a texture from MTLDevice
  • Compute and wait for completion
  • MTLBlitCommandEncoder copy computed texture from GPU to CPU as MTLBuffer
  • Create output CVPixelBuffer from MTLBuffer, but the output CVPixelBuffer is not IOSurface-backed
  • Deep copy output CVPixelBuffer and config the copied output is IOSurface-backed

metalmergestreams's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

metalmergestreams's Issues

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.