├── LayerVideoCompositor.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── LayerVideoCompositor ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── LayerVideoCompositionInstruction.swift ├── LayerVideoCompositor.swift ├── ViewController.swift └── video.mov └── README.md /LayerVideoCompositor.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7B426ABB1DDD559D002E94E7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B426ABA1DDD559D002E94E7 /* AppDelegate.swift */; }; 11 | 7B426ABD1DDD559D002E94E7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B426ABC1DDD559D002E94E7 /* ViewController.swift */; }; 12 | 7B426AC01DDD559D002E94E7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7B426ABE1DDD559D002E94E7 /* Main.storyboard */; }; 13 | 7B426AC21DDD559D002E94E7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B426AC11DDD559D002E94E7 /* Assets.xcassets */; }; 14 | 7B426AC51DDD559D002E94E7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7B426AC31DDD559D002E94E7 /* LaunchScreen.storyboard */; }; 15 | 7B426ACE1DDD5647002E94E7 /* LayerVideoCompositionInstruction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B426ACC1DDD5647002E94E7 /* LayerVideoCompositionInstruction.swift */; }; 16 | 7B426ACF1DDD5647002E94E7 /* LayerVideoCompositor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B426ACD1DDD5647002E94E7 /* LayerVideoCompositor.swift */; }; 17 | 7B426AD11DDD5739002E94E7 /* video.mov in Resources */ = {isa = PBXBuildFile; fileRef = 7B426AD01DDD5739002E94E7 /* video.mov */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 7B426AB71DDD559D002E94E7 /* LayerVideoCompositor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LayerVideoCompositor.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 7B426ABA1DDD559D002E94E7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 7B426ABC1DDD559D002E94E7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 7B426ABF1DDD559D002E94E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 7B426AC11DDD559D002E94E7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 7B426AC41DDD559D002E94E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 7B426AC61DDD559D002E94E7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 7B426ACC1DDD5647002E94E7 /* LayerVideoCompositionInstruction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LayerVideoCompositionInstruction.swift; sourceTree = ""; }; 29 | 7B426ACD1DDD5647002E94E7 /* LayerVideoCompositor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LayerVideoCompositor.swift; sourceTree = ""; }; 30 | 7B426AD01DDD5739002E94E7 /* video.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = video.mov; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 7B426AB41DDD559D002E94E7 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 7B426AAE1DDD559D002E94E7 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 7B426AB91DDD559D002E94E7 /* LayerVideoCompositor */, 48 | 7B426AB81DDD559D002E94E7 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | 7B426AB81DDD559D002E94E7 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 7B426AB71DDD559D002E94E7 /* LayerVideoCompositor.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | 7B426AB91DDD559D002E94E7 /* LayerVideoCompositor */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 7B426AD01DDD5739002E94E7 /* video.mov */, 64 | 7B426ACC1DDD5647002E94E7 /* LayerVideoCompositionInstruction.swift */, 65 | 7B426ACD1DDD5647002E94E7 /* LayerVideoCompositor.swift */, 66 | 7B426ABA1DDD559D002E94E7 /* AppDelegate.swift */, 67 | 7B426ABC1DDD559D002E94E7 /* ViewController.swift */, 68 | 7B426ABE1DDD559D002E94E7 /* Main.storyboard */, 69 | 7B426AC11DDD559D002E94E7 /* Assets.xcassets */, 70 | 7B426AC31DDD559D002E94E7 /* LaunchScreen.storyboard */, 71 | 7B426AC61DDD559D002E94E7 /* Info.plist */, 72 | ); 73 | path = LayerVideoCompositor; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | 7B426AB61DDD559D002E94E7 /* LayerVideoCompositor */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = 7B426AC91DDD559D002E94E7 /* Build configuration list for PBXNativeTarget "LayerVideoCompositor" */; 82 | buildPhases = ( 83 | 7B426AB31DDD559D002E94E7 /* Sources */, 84 | 7B426AB41DDD559D002E94E7 /* Frameworks */, 85 | 7B426AB51DDD559D002E94E7 /* Resources */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = LayerVideoCompositor; 92 | productName = LayerVideoCompositor; 93 | productReference = 7B426AB71DDD559D002E94E7 /* LayerVideoCompositor.app */; 94 | productType = "com.apple.product-type.application"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | 7B426AAF1DDD559D002E94E7 /* Project object */ = { 100 | isa = PBXProject; 101 | attributes = { 102 | LastSwiftUpdateCheck = 0810; 103 | LastUpgradeCheck = 0810; 104 | ORGANIZATIONNAME = "Guru Logic"; 105 | TargetAttributes = { 106 | 7B426AB61DDD559D002E94E7 = { 107 | CreatedOnToolsVersion = 8.1; 108 | DevelopmentTeam = X45WPY5JFZ; 109 | LastSwiftMigration = 0810; 110 | ProvisioningStyle = Automatic; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = 7B426AB21DDD559D002E94E7 /* Build configuration list for PBXProject "LayerVideoCompositor" */; 115 | compatibilityVersion = "Xcode 3.2"; 116 | developmentRegion = English; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = 7B426AAE1DDD559D002E94E7; 123 | productRefGroup = 7B426AB81DDD559D002E94E7 /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | 7B426AB61DDD559D002E94E7 /* LayerVideoCompositor */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXResourcesBuildPhase section */ 133 | 7B426AB51DDD559D002E94E7 /* Resources */ = { 134 | isa = PBXResourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | 7B426AD11DDD5739002E94E7 /* video.mov in Resources */, 138 | 7B426AC51DDD559D002E94E7 /* LaunchScreen.storyboard in Resources */, 139 | 7B426AC21DDD559D002E94E7 /* Assets.xcassets in Resources */, 140 | 7B426AC01DDD559D002E94E7 /* Main.storyboard in Resources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXResourcesBuildPhase section */ 145 | 146 | /* Begin PBXSourcesBuildPhase section */ 147 | 7B426AB31DDD559D002E94E7 /* Sources */ = { 148 | isa = PBXSourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | 7B426ACF1DDD5647002E94E7 /* LayerVideoCompositor.swift in Sources */, 152 | 7B426ABD1DDD559D002E94E7 /* ViewController.swift in Sources */, 153 | 7B426ACE1DDD5647002E94E7 /* LayerVideoCompositionInstruction.swift in Sources */, 154 | 7B426ABB1DDD559D002E94E7 /* AppDelegate.swift in Sources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXSourcesBuildPhase section */ 159 | 160 | /* Begin PBXVariantGroup section */ 161 | 7B426ABE1DDD559D002E94E7 /* Main.storyboard */ = { 162 | isa = PBXVariantGroup; 163 | children = ( 164 | 7B426ABF1DDD559D002E94E7 /* Base */, 165 | ); 166 | name = Main.storyboard; 167 | sourceTree = ""; 168 | }; 169 | 7B426AC31DDD559D002E94E7 /* LaunchScreen.storyboard */ = { 170 | isa = PBXVariantGroup; 171 | children = ( 172 | 7B426AC41DDD559D002E94E7 /* Base */, 173 | ); 174 | name = LaunchScreen.storyboard; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXVariantGroup section */ 178 | 179 | /* Begin XCBuildConfiguration section */ 180 | 7B426AC71DDD559D002E94E7 /* Debug */ = { 181 | isa = XCBuildConfiguration; 182 | buildSettings = { 183 | ALWAYS_SEARCH_USER_PATHS = NO; 184 | CLANG_ANALYZER_NONNULL = YES; 185 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 186 | CLANG_CXX_LIBRARY = "libc++"; 187 | CLANG_ENABLE_MODULES = YES; 188 | CLANG_ENABLE_OBJC_ARC = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_CONSTANT_CONVERSION = YES; 191 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 192 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 193 | CLANG_WARN_EMPTY_BODY = YES; 194 | CLANG_WARN_ENUM_CONVERSION = YES; 195 | CLANG_WARN_INFINITE_RECURSION = YES; 196 | CLANG_WARN_INT_CONVERSION = YES; 197 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 198 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 199 | CLANG_WARN_UNREACHABLE_CODE = YES; 200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 201 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 202 | COPY_PHASE_STRIP = NO; 203 | DEBUG_INFORMATION_FORMAT = dwarf; 204 | ENABLE_STRICT_OBJC_MSGSEND = YES; 205 | ENABLE_TESTABILITY = YES; 206 | GCC_C_LANGUAGE_STANDARD = gnu99; 207 | GCC_DYNAMIC_NO_PIC = NO; 208 | GCC_NO_COMMON_BLOCKS = YES; 209 | GCC_OPTIMIZATION_LEVEL = 0; 210 | GCC_PREPROCESSOR_DEFINITIONS = ( 211 | "DEBUG=1", 212 | "$(inherited)", 213 | ); 214 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 215 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 216 | GCC_WARN_UNDECLARED_SELECTOR = YES; 217 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 218 | GCC_WARN_UNUSED_FUNCTION = YES; 219 | GCC_WARN_UNUSED_VARIABLE = YES; 220 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 221 | MTL_ENABLE_DEBUG_INFO = YES; 222 | ONLY_ACTIVE_ARCH = YES; 223 | SDKROOT = iphoneos; 224 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 225 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 226 | TARGETED_DEVICE_FAMILY = "1,2"; 227 | }; 228 | name = Debug; 229 | }; 230 | 7B426AC81DDD559D002E94E7 /* Release */ = { 231 | isa = XCBuildConfiguration; 232 | buildSettings = { 233 | ALWAYS_SEARCH_USER_PATHS = NO; 234 | CLANG_ANALYZER_NONNULL = YES; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_WARN_BOOL_CONVERSION = YES; 240 | CLANG_WARN_CONSTANT_CONVERSION = YES; 241 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 242 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 243 | CLANG_WARN_EMPTY_BODY = YES; 244 | CLANG_WARN_ENUM_CONVERSION = YES; 245 | CLANG_WARN_INFINITE_RECURSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 248 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 249 | CLANG_WARN_UNREACHABLE_CODE = YES; 250 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 251 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 252 | COPY_PHASE_STRIP = NO; 253 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 254 | ENABLE_NS_ASSERTIONS = NO; 255 | ENABLE_STRICT_OBJC_MSGSEND = YES; 256 | GCC_C_LANGUAGE_STANDARD = gnu99; 257 | GCC_NO_COMMON_BLOCKS = YES; 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 260 | GCC_WARN_UNDECLARED_SELECTOR = YES; 261 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 262 | GCC_WARN_UNUSED_FUNCTION = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 265 | MTL_ENABLE_DEBUG_INFO = NO; 266 | SDKROOT = iphoneos; 267 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 268 | TARGETED_DEVICE_FAMILY = "1,2"; 269 | VALIDATE_PRODUCT = YES; 270 | }; 271 | name = Release; 272 | }; 273 | 7B426ACA1DDD559D002E94E7 /* Debug */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | CLANG_ENABLE_MODULES = YES; 278 | DEVELOPMENT_TEAM = X45WPY5JFZ; 279 | INFOPLIST_FILE = LayerVideoCompositor/Info.plist; 280 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 281 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 282 | PRODUCT_BUNDLE_IDENTIFIER = ca.gurulogic.LayerVideoCompositor; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 285 | SWIFT_VERSION = 3.0; 286 | }; 287 | name = Debug; 288 | }; 289 | 7B426ACB1DDD559D002E94E7 /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 293 | CLANG_ENABLE_MODULES = YES; 294 | DEVELOPMENT_TEAM = X45WPY5JFZ; 295 | INFOPLIST_FILE = LayerVideoCompositor/Info.plist; 296 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 297 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 298 | PRODUCT_BUNDLE_IDENTIFIER = ca.gurulogic.LayerVideoCompositor; 299 | PRODUCT_NAME = "$(TARGET_NAME)"; 300 | SWIFT_VERSION = 3.0; 301 | }; 302 | name = Release; 303 | }; 304 | /* End XCBuildConfiguration section */ 305 | 306 | /* Begin XCConfigurationList section */ 307 | 7B426AB21DDD559D002E94E7 /* Build configuration list for PBXProject "LayerVideoCompositor" */ = { 308 | isa = XCConfigurationList; 309 | buildConfigurations = ( 310 | 7B426AC71DDD559D002E94E7 /* Debug */, 311 | 7B426AC81DDD559D002E94E7 /* Release */, 312 | ); 313 | defaultConfigurationIsVisible = 0; 314 | defaultConfigurationName = Release; 315 | }; 316 | 7B426AC91DDD559D002E94E7 /* Build configuration list for PBXNativeTarget "LayerVideoCompositor" */ = { 317 | isa = XCConfigurationList; 318 | buildConfigurations = ( 319 | 7B426ACA1DDD559D002E94E7 /* Debug */, 320 | 7B426ACB1DDD559D002E94E7 /* Release */, 321 | ); 322 | defaultConfigurationIsVisible = 0; 323 | defaultConfigurationName = Release; 324 | }; 325 | /* End XCConfigurationList section */ 326 | }; 327 | rootObject = 7B426AAF1DDD559D002E94E7 /* Project object */; 328 | } 329 | -------------------------------------------------------------------------------- /LayerVideoCompositor.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LayerVideoCompositor/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LayerVideoCompositor 4 | // 5 | // Created by Sami Samhuri on 2016-11-16. 6 | // Copyright © 2016 Guru Logic. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /LayerVideoCompositor/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LayerVideoCompositor/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LayerVideoCompositor/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /LayerVideoCompositor/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /LayerVideoCompositor/LayerVideoCompositionInstruction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LayerVideoCompositionInstruction.swift 3 | // LayerVideoCompositor 4 | // 5 | // Created by Sami Samhuri on 2016-09-05. 6 | // Copyright © 2016 Guru Logic Inc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import AVFoundation 11 | 12 | final class LayerVideoCompositionInstruction: NSObject, AVVideoCompositionInstructionProtocol { 13 | // Fixed 14 | let enablePostProcessing: Bool = true 15 | let containsTweening: Bool = false 16 | let passthroughTrackID: CMPersistentTrackID = kCMPersistentTrackID_Invalid 17 | 18 | // Variable 19 | let timeRange: CMTimeRange 20 | let requiredSourceTrackIDs: [NSValue]? 21 | let videoTrackID: CMPersistentTrackID 22 | let targetSize: CGSize 23 | let transform: CGAffineTransform 24 | let overlayLayer: CALayer? 25 | 26 | init(track: AVAssetTrack, timeRange: CMTimeRange, overlayLayer: CALayer?, transform: CGAffineTransform, targetSize: CGSize) { 27 | assert(overlayLayer == nil || overlayLayer!.bounds.size == targetSize) 28 | self.requiredSourceTrackIDs = [NSNumber(value: track.trackID)] 29 | self.timeRange = timeRange 30 | self.videoTrackID = track.trackID 31 | self.transform = transform 32 | self.targetSize = targetSize 33 | self.overlayLayer = overlayLayer 34 | super.init() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LayerVideoCompositor/LayerVideoCompositor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LayerVideoCompositor.swift 3 | // LayerVideoCompositor 4 | // 5 | // Created by Sami Samhuri on 2016-09-05. 6 | // Copyright © 2016 Guru Logic Inc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Dispatch 11 | import AVFoundation 12 | import CoreImage 13 | 14 | enum LayerVideoCompositingError: Error { 15 | case invalidRequest 16 | case sourceFrameBuffer 17 | case overlayTextLayer 18 | } 19 | 20 | final class LayerVideoCompositor: NSObject, AVVideoCompositing { 21 | private let queue = DispatchQueue(label: "ca.gurulogic.layer-video-compositor.render", qos: .default) 22 | private var renderContext: AVVideoCompositionRenderContext = AVVideoCompositionRenderContext() 23 | private var cancelled: Bool = false 24 | private let ciContext: CIContext = { 25 | if let eaglContext = EAGLContext(api: .openGLES3) ?? EAGLContext(api: .openGLES2) { 26 | return CIContext(eaglContext: eaglContext) 27 | } 28 | return CIContext() 29 | }() 30 | private var cachedOverlaySnapshot: CGImage? 31 | private let colorSpace = CGColorSpaceCreateDeviceRGB() 32 | 33 | var supportsWideColorSourceFrames: Bool { 34 | return false 35 | } 36 | 37 | private static let pixelFormat = kCVPixelFormatType_32BGRA 38 | 39 | let sourcePixelBufferAttributes: [String : Any]? = [ 40 | kCVPixelBufferPixelFormatTypeKey as String : NSNumber(value: LayerVideoCompositor.pixelFormat), 41 | kCVPixelBufferOpenGLESCompatibilityKey as String : NSNumber(value: true), 42 | ] 43 | 44 | let requiredPixelBufferAttributesForRenderContext: [String : Any] = [ 45 | kCVPixelBufferPixelFormatTypeKey as String : NSNumber(value: LayerVideoCompositor.pixelFormat), 46 | kCVPixelBufferOpenGLESCompatibilityKey as String : NSNumber(value: true), 47 | ] 48 | 49 | func renderContextChanged(_ newRenderContext: AVVideoCompositionRenderContext) { 50 | renderContext = newRenderContext 51 | } 52 | 53 | func startRequest(_ request: AVAsynchronousVideoCompositionRequest) { 54 | queue.async { 55 | guard !self.cancelled else { 56 | request.finishCancelledRequest() 57 | return 58 | } 59 | 60 | do { 61 | let renderedBuffer = try self.renderFrame(forRequest: request) 62 | request.finish(withComposedVideoFrame: renderedBuffer) 63 | } 64 | catch { 65 | request.finish(with: error) 66 | } 67 | } 68 | } 69 | 70 | func cancelAllPendingVideoCompositionRequests() { 71 | cancelled = true 72 | queue.async(flags: .barrier) { 73 | self.cancelled = false 74 | } 75 | } 76 | 77 | private func overlaySnapshot(layer: CALayer) throws -> CGImage { 78 | if let cachedSnapshot = cachedOverlaySnapshot { 79 | return cachedSnapshot 80 | } 81 | layer.isGeometryFlipped = true 82 | let size = layer.bounds.size 83 | let w = Int(size.width) 84 | let h = Int(size.height) 85 | guard let context = CGContext(data: nil, width: w, height: h, bitsPerComponent: 8, bytesPerRow: 4 * w, space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { throw NSError() } 86 | layer.render(in: context) 87 | guard let snapshot = context.makeImage() else { throw NSError() } 88 | cachedOverlaySnapshot = snapshot 89 | return snapshot 90 | } 91 | 92 | private func renderFrame(forRequest request: AVAsynchronousVideoCompositionRequest) throws -> CVPixelBuffer { 93 | return try autoreleasepool { 94 | guard let instruction = request.videoCompositionInstruction as? LayerVideoCompositionInstruction else { 95 | throw LayerVideoCompositingError.invalidRequest 96 | } 97 | guard let videoFrameBuffer = request.sourceFrame(byTrackID: instruction.videoTrackID) else { 98 | // Try to be resilient in the face of errors. If we can't even generate a blank frame then fail. 99 | if let blankBuffer = renderContext.newPixelBuffer() { 100 | return blankBuffer 101 | } 102 | else { 103 | throw LayerVideoCompositingError.sourceFrameBuffer 104 | } 105 | } 106 | let frameImage = CIImage(cvPixelBuffer: videoFrameBuffer).applying(instruction.transform) 107 | guard let layer = instruction.overlayLayer, let overlayImage = try? CIImage(cgImage: overlaySnapshot(layer: layer)), 108 | let composeFilter = CIFilter(name: "CISourceAtopCompositing") else { 109 | throw LayerVideoCompositingError.overlayTextLayer 110 | } 111 | composeFilter.setValue(frameImage, forKey: kCIInputBackgroundImageKey) 112 | composeFilter.setValue(overlayImage, forKey: kCIInputImageKey) 113 | guard let outputImage = composeFilter.outputImage, 114 | let renderedBuffer = renderContext.newPixelBuffer() else { 115 | throw LayerVideoCompositingError.overlayTextLayer 116 | } 117 | ciContext.render(outputImage, to: renderedBuffer, bounds: outputImage.extent, colorSpace: self.colorSpace) 118 | return renderedBuffer 119 | } 120 | } 121 | } 122 | 123 | -------------------------------------------------------------------------------- /LayerVideoCompositor/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LayerVideoCompositor 4 | // 5 | // Created by Sami Samhuri on 2016-11-16. 6 | // Copyright © 2016 Guru Logic. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AVFoundation 11 | 12 | class ViewController: UIViewController { 13 | @IBOutlet private var label: UILabel? 14 | @IBOutlet private var indicator: UIActivityIndicatorView? 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | let path = Bundle.main.path(forResource: "video.mov", ofType: nil) 19 | let url = URL(fileURLWithPath: path!) 20 | let start = Date() 21 | overlayTextOnVideo(videoURL: url) { maybeURL in 22 | DispatchQueue.main.async { 23 | self.indicator?.stopAnimating() 24 | guard let url = maybeURL else { 25 | self.label?.text = "Error. See console for details." 26 | return 27 | } 28 | 29 | let end = Date() 30 | let duration = end.timeIntervalSince1970 - start.timeIntervalSince1970 31 | print("Exported in \(duration) seconds.") 32 | 33 | self.label?.text = "Done. Video is in the Documents folder which you can access with iTunes, or an app like iMazing or iExplorer." 34 | let player = AVPlayer(url: url) 35 | let layer = AVPlayerLayer(player: player) 36 | let y = 16 + (self.label?.frame.maxY ?? 0) 37 | let width = self.view.bounds.width 38 | layer.frame = CGRect(x: 0, y: y, width: width, height: 9 / 16 * width) 39 | self.view.layer.addSublayer(layer) 40 | player.play() 41 | } 42 | } 43 | } 44 | 45 | private func newOverlayLayer(size: CGSize, text: String) -> CALayer { 46 | let margin: CGFloat = 16 47 | let textHeight: CGFloat = 120 48 | let textLayer = CATextLayer() 49 | textLayer.alignmentMode = kCAAlignmentCenter 50 | textLayer.fontSize = 96 51 | textLayer.frame = CGRect(x: margin, y: margin, width: size.width - 2 * margin, height: textHeight) 52 | textLayer.string = text 53 | textLayer.foregroundColor = UIColor(white: 1, alpha: 0.7).cgColor 54 | textLayer.shadowColor = UIColor.black.cgColor 55 | textLayer.shadowOpacity = 0.8 56 | 57 | let overlayLayer = CALayer() 58 | overlayLayer.frame = CGRect(origin: .zero, size: size) 59 | overlayLayer.addSublayer(textLayer) 60 | 61 | return overlayLayer 62 | } 63 | 64 | private func overlayTextOnVideo(videoURL: URL, completion: @escaping (URL?) -> Void) { 65 | let asset = AVURLAsset(url: videoURL) 66 | let videoTracks = asset.tracks(withMediaType: AVMediaTypeVideo) 67 | guard let sourceVideoTrack = videoTracks.first else { 68 | print("error: asset has no video tracks") 69 | completion(nil) 70 | return 71 | } 72 | let timeRange = CMTimeRange(start: kCMTimeZero, duration: asset.duration) 73 | let videoComposition = AVMutableVideoComposition(propertiesOf: asset) 74 | videoComposition.customVideoCompositorClass = LayerVideoCompositor.self 75 | let overlayLayer = newOverlayLayer(size: sourceVideoTrack.naturalSize, text: "Layeriffic!") 76 | let instruction = LayerVideoCompositionInstruction(track: sourceVideoTrack, timeRange: timeRange, overlayLayer: overlayLayer, transform: sourceVideoTrack.preferredTransform, targetSize: sourceVideoTrack.naturalSize) 77 | videoComposition.instructions = [instruction] 78 | 79 | let documentDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! 80 | let path = documentDir.appending("/export.mov") 81 | let outputURL = URL(fileURLWithPath: path) 82 | _ = try? FileManager.default.removeItem(at: outputURL) 83 | 84 | guard let presetName = AVAssetExportSession.exportPresets(compatibleWith: asset).first, 85 | let exportSession = AVAssetExportSession(asset: asset, presetName: presetName) else { 86 | print("failed to create asset export session") 87 | completion(nil) 88 | return 89 | } 90 | exportSession.videoComposition = videoComposition 91 | exportSession.outputFileType = AVFileTypeMPEG4 92 | exportSession.outputURL = outputURL 93 | exportSession.exportAsynchronously { 94 | guard exportSession.status == .completed else { 95 | print("export failed: \(exportSession.error)") 96 | completion(nil) 97 | return 98 | } 99 | completion(outputURL) 100 | } 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /LayerVideoCompositor/video.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samsonjs/LayerVideoCompositor/e0826027ca6cafcf02659395d8caf3749d756ec7/LayerVideoCompositor/video.mov -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LayerVideoCompositor 2 | 3 | An example of using a custom video compositor to overlay a layer on a video. 4 | 5 | This may be useful in working around [radar 28553945](http://www.openradar.me/28553945) as described in [this StackOverflow question](http://stackoverflow.com/questions/39760147/ios-10-avplayerlayer-doesnt-show-video-after-using-avvideocompositioncoreanima). 6 | 7 | This was extracted from [1 Second Everyday](http://1se.co) so if this was useful you should check out our app :) 8 | 9 | # License 10 | 11 | [MIT License](https://sjs.mit-license.org) 12 | --------------------------------------------------------------------------------