Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.

License

NotificationsYou must be signed in to change notification settings

ruanjx/VideoLab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README 中文版本框架设计与实现介绍

High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.

Framework design and implementation

Features

  • High-performance real-time video editing and exporting.
  • Highly free combination of video, image, audio.
  • Support audio pitch setting and volume adjustment.
  • Support CALayer vector animations, so complex text animations are supported.
  • Support keyframe animation.
  • Support After Effect-like pre-compose.
  • Support transitions.
  • Support custom effects. Such as LUT filter, zoom blur, etc.

The following are some GIFs of features(multiple layers, text animation, keyframe animation, pre compose, and transition)

Requirements

  • iOS 11.0+
  • Swift 5.0+

Installation

VideoLab is available throughCocoaPods. Specify the following in yourPodfile:

source'https://github.com/CocoaPods/Specs.git'platform:ios,'11.0'use_frameworks!target'<Your Target>'dopod'VideoLab'end

Usage

Basic Concept

RenderLayer

RenderLayer is the most basic unit in theVideoLab framework. A video, image, audio can be aRenderLayer, or even just an effect can be aRenderLayer.RenderLayer is more like the concept of the layer in After Effect.

RenderComposition

RenderComposition works as a composite, can set frame rate, canvas size, contains multipleRenderLayers, can setCALayer to support vector animations.

VideoLab

VideoLab can be considered as a lab whereAVPlayerItem,AVAssetExportSession,AVAssetImageGenerator can be generated according toRenderComposition.

Basic Usage

// 1. Layer 1varurl=Bundle.main.url(forResource:"video1", withExtension:"MOV")varasset=AVAsset(url: url!)varsource=AVAssetSource(asset: asset)source.selectedTimeRange=CMTimeRange(start:CMTime.zero, duration: asset.duration)vartimeRange= source.selectedTimeRangeletrenderLayer1=RenderLayer(timeRange: timeRange, source: source)    // 1. Layer 2url=Bundle.main.url(forResource:"video2", withExtension:"MOV")asset=AVAsset(url: url!)source=AVAssetSource(asset: asset)source.selectedTimeRange=CMTimeRange(start:CMTime.zero, duration: asset.duration)timeRange= source.selectedTimeRangetimeRange.start=CMTimeRangeGetEnd(renderLayer1.timeRange)letrenderLayer2=RenderLayer(timeRange: timeRange, source: source)    // 2. Compositionletcomposition=RenderComposition()composition.renderSize=CGSize(width:1280, height:720)composition.layers=[renderLayer1, renderLayer2]// 3. VideoLabletvideoLab=VideoLab(renderComposition: composition)// 4. Make playerItemletplayerItem= videoLab.makePlayerItem()
  1. CreateRenderLayer
  2. CreateRenderComposition, setrenderSize andlayers
  3. CreateVideoLab withrenderComposition
  4. MakeAVPlayerItem orAVAssetExportSession

More Advanced Usage

Transform

varcenter=CGPoint(x:0.25, y:0.25)vartransform=Transform(center: center, rotation:0, scale:0.5)renderLayer1.transform= transform
  1. CreateTransform withcenter,rotation andscale
  2. RenderLayer settransform

Audio Configuration

letaudioConfiguration=AudioConfiguration()letvolumeRampTimeRange=CMTimeRange(start:CMTime.zero, duration:CMTime(seconds:5, preferredTimescale:600))letvolumeRamp1=VolumeRamp(startVolume:0.0, endVolume:0.0, timeRange: volumeRampTimeRange)audioConfiguration.volumeRamps=[volumeRamp1]renderLayer2.audioConfiguration= audioConfiguration
  1. CreateAudioConfiguration
  2. CreateVolumeRamp withstartVolume,endVolume andtimeRange
  3. AudioConfiguration setvolumeRamps
  4. RenderLayer setaudioConfiguration

CALayer Animation

For exporting set your customizedCALayer forRenderComposition

composition.animationLayer=<Your customized CALayer>

For playback addAVSynchronizedLayer to your view's layer, See more detail inText Animation Demo.

Keyframe Animation

// 1. Keyframe animationletkeyTimes=[CMTime(seconds:2, preferredTimescale:600),CMTime(seconds:4, preferredTimescale:600),CMTime(seconds:6, preferredTimescale:600)]letanimation=KeyframeAnimation(keyPath:"blendOpacity",                                  values:[1.0,0.2,1.0],                                  keyTimes: keyTimes, timingFunctions:[.linear,.linear])renderLayer1.animations=[animation]vartransform=Transform.identityletanimation1=KeyframeAnimation(keyPath:"scale",                                   values:[1.0,1.3,1.0],                                   keyTimes: keyTimes, timingFunctions:[.quadraticEaseInOut,.quadraticEaseInOut])letanimation2=KeyframeAnimation(keyPath:"rotation",                                   values:[0,Float.pi/2.0,0],                                   keyTimes: keyTimes, timingFunctions:[.quadraticEaseInOut,.quadraticEaseInOut])transform.animations=[animation1, animation2]renderLayer1.transform= transform
  1. CreateKeyframeAnimation withkeyPath,values,keyTimes andtimingFunctions
  2. Setanimations for astruct orclass that implements theAnimatable protocol (e.g.Transform struct,RenderLayer class)

RenderLayerGroup (After Effect-like pre-compose)

letlayerGroup=RenderLayerGroup(timeRange: timeRange)layerGroup.layers=[renderLayer1, renderLayer2]
  1. CreateRenderLayerGroup withtimeRange
  2. Set sublayers forlayerGroup. See more detail inLayer Group Demo.

Transition

We don't have a transition layer, so instead, you can add a transform or operations to each RenderLayer to create a transition. See more detail inTransition Demo.

Custom Effects

// Filtervarfilter=LookupFilter()filter.addTexture(lutTextures[0], at:0)renderLayer.operations=[filter]// Zoom Blurvarzoomblur=ZoomBlur()animation=KeyframeAnimation(keyPath:"blurSize",                              values:[0.0,3.0],                              keyTimes: keyTimes, timingFunctions:[.quarticEaseOut])zoomblur.animations=[animation]layerGroup1.operations=[zoomblur]
  1. Create customizeOperation inherited fromBasicOperation.BasicOperation also conforms to theAnimatable protocol
  2. Setoperations forRenderLayer.

TODO

  • Support Open GL render
  • Add speed adjustment forRenderLayer.
  • Provide a more convenient way to use transitions, possibly providingTransitionLayer.
  • Add log system.

Author

License

VideoLab is available under the MIT license. See theLICENSE file for more info.

About

High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp