Empower your welcome screen video with CIFilter

Many of us like our app look trendy. How to be "trendy"? Put a video on the welcome our signup screen is quite a good answer.
I am going to share my small class to enable easy video looping and block style CIFilter applying.
Before I share the repo, let's talk about it first, may be you don't want to clone it but build yourself one!

There are two obviously goal I wanted to achieve at the beginning:

  • First, looping between the video I assigned.
  • Second, can apply CIFilter so I don't have to render and render and render different video for slightly changing.
  • Ok, there are still a few reason I did it but why don't we talk about it later?

How it work?

User:

  • User initiate an instance
  • call playVideos(_:[NSURL]) (default setting, there are some options like FPS, Loop, CompletionBlock to set)
  • Apply a filter: CIImage->CIImage to the instance if needed.
  • Add subview and play!

Class:

  • Some internal functions to control the playing status
  • Use AVAssetReader to manually decode the video
  • Use GCD to control the rendering the assets, looping and ofcoz to make it async:
    • A rendering queue to preform dispatch_block that read the buffer then convert it to CIImage
    • dispatch_source to manage the dispatch job interval(So we don't need to read add frame but a frame per need) Use a GLView to present contents:
    • draw the CIImage on the view.
The view use fewer computing and space resources than GIF, more flexible and convenient. But it's far away from perfect, just good enough for my own (or a little others) need.
See you soon.
https://github.com/matthewlui/FSVideoView
 

Original post from my previous site: http://povoq.blogspot.com/2017/04/empower-your-welcome-screen-video-with.html