Skip to content

Commit ee85248

Browse files
author
RenZhu Macro
committed
fix bugs & add more motions.
one video track can only use one motion
1 parent c135346 commit ee85248

18 files changed

+417
-46
lines changed

Examples/SimpleVideoAnimation/SimpleVIdeoAnimation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
6A874BB924C5462C00ADFD8A /* MetalVideoProcess.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A874BB824C545CC00ADFD8A /* MetalVideoProcess.framework */; };
1919
6A874BBA24C5462C00ADFD8A /* MetalVideoProcess.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6A874BB824C545CC00ADFD8A /* MetalVideoProcess.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2020
6A874BDA24C6FDE200ADFD8A /* 853.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 6A874BD824C6FDE200ADFD8A /* 853.mp4 */; };
21+
AB59B95124C9717600943BE2 /* NavigateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB59B94F24C9717600943BE2 /* NavigateViewController.swift */; };
2122
/* End PBXBuildFile section */
2223

2324
/* Begin PBXContainerItemProxy section */
@@ -58,6 +59,7 @@
5859
6A874BB324C545CC00ADFD8A /* MetalVideoProcess.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MetalVideoProcess.xcodeproj; path = ../../MetalVideoProcess.xcodeproj; sourceTree = "<group>"; };
5960
6A874BD824C6FDE200ADFD8A /* 853.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = 853.mp4; path = SimpleVIdeoAnimation/853.mp4; sourceTree = SOURCE_ROOT; };
6061
A512CD4DD2F5AB414CF01FE6 /* Pods-SimpleVideoAnimation.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleVideoAnimation.release.xcconfig"; path = "Target Support Files/Pods-SimpleVideoAnimation/Pods-SimpleVideoAnimation.release.xcconfig"; sourceTree = "<group>"; };
62+
AB59B94F24C9717600943BE2 /* NavigateViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NavigateViewController.swift; path = SimpleVIdeoAnimation/NavigateViewController.swift; sourceTree = SOURCE_ROOT; };
6163
D107CF0887B69DDEA376CBEA /* Pods-SimpleVideoAnimation.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleVideoAnimation.debug.xcconfig"; path = "Target Support Files/Pods-SimpleVideoAnimation/Pods-SimpleVideoAnimation.debug.xcconfig"; sourceTree = "<group>"; };
6264
/* End PBXFileReference section */
6365

@@ -109,6 +111,7 @@
109111
6A874B9F24C53EF700ADFD8A /* AppDelegate.swift */,
110112
6A874BA124C53EF700ADFD8A /* SceneDelegate.swift */,
111113
6A874BA324C53EF700ADFD8A /* ViewController.swift */,
114+
AB59B94F24C9717600943BE2 /* NavigateViewController.swift */,
112115
6A874BA524C53EF700ADFD8A /* Main.storyboard */,
113116
6A874BA824C53EF800ADFD8A /* Assets.xcassets */,
114117
6A874BAA24C53EF800ADFD8A /* LaunchScreen.storyboard */,
@@ -269,6 +272,7 @@
269272
buildActionMask = 2147483647;
270273
files = (
271274
6A874BA424C53EF700ADFD8A /* ViewController.swift in Sources */,
275+
AB59B95124C9717600943BE2 /* NavigateViewController.swift in Sources */,
272276
6A874BA024C53EF700ADFD8A /* AppDelegate.swift in Sources */,
273277
6A874BA224C53EF700ADFD8A /* SceneDelegate.swift in Sources */,
274278
);
Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17132" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Sjl-30-bHq">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17105.1"/>
67
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
79
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
810
</dependencies>
911
<scenes>
1012
<!--View Controller-->
1113
<scene sceneID="tne-QT-ifu">
1214
<objects>
13-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="SimpleVideoAnimation" customModuleProvider="target" sceneMemberID="viewController">
15+
<viewController storyboardIdentifier="ViewController" id="BYZ-38-t0r" customClass="ViewController" customModule="SimpleVideoAnimation" customModuleProvider="target" sceneMemberID="viewController">
1416
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1517
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1618
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1719
<subviews>
18-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FXj-LY-59h" customClass="MetalVideoProcessRenderView" customModule="MetalVideoProcess">
19-
<rect key="frame" x="0.0" y="0.0" width="375" height="375"/>
20-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
20+
<view contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FXj-LY-59h" customClass="MetalVideoProcessRenderView" customModule="MetalVideoProcess">
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="438"/>
22+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
2123
<constraints>
2224
<constraint firstAttribute="width" secondItem="FXj-LY-59h" secondAttribute="height" id="iBP-Gu-Wj9"/>
2325
</constraints>
2426
</view>
25-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gLe-Zn-niL">
26-
<rect key="frame" x="166.5" y="515" width="42" height="30"/>
27+
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gLe-Zn-niL">
28+
<rect key="frame" x="231" y="562" width="42" height="30"/>
2729
<state key="normal" title="Pause"/>
2830
<connections>
2931
<action selector="pause:" destination="BYZ-38-t0r" eventType="touchUpInside" id="jXA-Ko-2E5"/>
3032
</connections>
3133
</button>
32-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9lP-KN-D4J">
33-
<rect key="frame" x="172.5" y="475" width="30" height="30"/>
34+
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9lP-KN-D4J">
35+
<rect key="frame" x="136" y="562" width="30" height="30"/>
3436
<state key="normal" title="Play"/>
3537
<connections>
3638
<action selector="play:" destination="BYZ-38-t0r" eventType="touchUpInside" id="BxN-gS-f9o"/>
3739
</connections>
3840
</button>
39-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="JkB-hg-7A6" customClass="TrimmerView" customModule="PryntTrimmerView">
40-
<rect key="frame" x="0.0" y="385" width="375" height="80"/>
41-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
41+
<view contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JkB-hg-7A6" customClass="TrimmerView" customModule="PryntTrimmerView">
42+
<rect key="frame" x="0.0" y="470" width="375" height="80"/>
43+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
4244
<constraints>
4345
<constraint firstAttribute="height" constant="80" id="9zr-ar-gfx"/>
4446
</constraints>
4547
</view>
4648
</subviews>
47-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
49+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
50+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
4851
<constraints>
4952
<constraint firstItem="9lP-KN-D4J" firstAttribute="top" secondItem="JkB-hg-7A6" secondAttribute="bottom" constant="10" id="EVm-H0-xCG"/>
5053
<constraint firstItem="FXj-LY-59h" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="Hbb-9e-X3i"/>
@@ -57,7 +60,6 @@
5760
<constraint firstItem="JkB-hg-7A6" firstAttribute="top" secondItem="FXj-LY-59h" secondAttribute="bottom" constant="10" id="rCV-zQ-Eyi"/>
5861
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="FXj-LY-59h" secondAttribute="trailing" id="rUK-5t-TAP"/>
5962
</constraints>
60-
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
6163
</view>
6264
<connections>
6365
<outlet property="progressView" destination="JkB-hg-7A6" id="eky-zy-L0Z"/>
@@ -66,7 +68,27 @@
6668
</viewController>
6769
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
6870
</objects>
69-
<point key="canvasLocation" x="132" y="138"/>
71+
<point key="canvasLocation" x="132" y="137.18140929535232"/>
72+
</scene>
73+
<!--NavigateView-->
74+
<scene sceneID="XBJ-QK-b6X">
75+
<objects>
76+
<viewController id="Sjl-30-bHq" userLabel="NavigateView" customClass="NavigateViewController" customModule="SimpleVideoAnimation" customModuleProvider="target" sceneMemberID="viewController">
77+
<view key="view" contentMode="scaleToFill" id="aeg-zc-cBS">
78+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
79+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
80+
<viewLayoutGuide key="safeArea" id="qlq-zn-i27"/>
81+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
82+
</view>
83+
</viewController>
84+
<placeholder placeholderIdentifier="IBFirstResponder" id="Aj9-BM-fNL" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
85+
</objects>
86+
<point key="canvasLocation" x="-906" y="137"/>
7087
</scene>
7188
</scenes>
89+
<resources>
90+
<systemColor name="systemBackgroundColor">
91+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
92+
</systemColor>
93+
</resources>
7294
</document>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//
2+
// NavigateViewController.swift
3+
// SimpleVideoTransition
4+
//
5+
// Created by Ruanshengqiang Macro on 2020/7/2.
6+
// Copyright © 2020 Ruanshengqiang Macro. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import MetalVideoProcess
11+
import AVFoundation
12+
import MetalVideoProcess
13+
14+
class NavigateViewController: UIViewController {
15+
@IBOutlet weak var naviStackView: UIStackView!
16+
17+
var transitionTimeRange = CMTimeRange.init()
18+
19+
let N = 3
20+
private func getTransition(index: Int) -> (titleName: String, transObject: MetalVideoProcessMotion) {
21+
switch index {
22+
case 0:
23+
return (titleName: "向上滑动", transObject: MetalVideoProcessMoveUpMotion())
24+
case 1:
25+
return (titleName: "放大", transObject: MetalVideoProcessMoveInMotion())
26+
case 2:
27+
return (titleName: "旋转", transObject: MetalVideoProcessRotateMotion())
28+
case 3:
29+
return (titleName: "渐显", transObject: MetalVideoProcessFadeInMotion())
30+
default:
31+
return (titleName: "放大", transObject: MetalVideoProcessMoveInMotion())
32+
33+
}
34+
}
35+
private func getButton(index: Int) -> UIButton {
36+
let splitNum = 5.0
37+
let pieceWidth = Double(self.view.frame.width) / splitNum
38+
let buttonWidth = pieceWidth * 0.8
39+
let dIndex = Double(index)
40+
let indexX = fmod(dIndex, splitNum) * pieceWidth
41+
let indexY = (floor(dIndex / splitNum)) * pieceWidth + 100.0
42+
43+
let buttonFrame = CGRect(x: indexX, y: indexY, width: buttonWidth, height: buttonWidth)
44+
45+
let but = UIButton(frame: buttonFrame)
46+
but.backgroundColor = UIColor(red: 0.3, green: 0.4, blue: 0.3, alpha: 0.7)
47+
but.setTitle(getTransition(index: index).titleName, for: .normal)
48+
49+
but.titleLabel?.adjustsFontSizeToFitWidth = true
50+
but.addTarget(self, action: #selector(self.swithController(_:)), for: .touchUpInside)
51+
52+
but.tag = index
53+
return but
54+
}
55+
56+
override func viewDidLoad() {
57+
super.viewDidLoad()
58+
for index in 0...N - 1 {
59+
self.view.addSubview(getButton(index: index))
60+
}
61+
}
62+
63+
@IBAction func swithController(_ sender: UIButton) {
64+
65+
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as! ViewController
66+
67+
let trans = getTransition(index: sender.tag)
68+
69+
viewController.motionIn = trans.transObject
70+
71+
self.present(viewController, animated: true, completion: nil)
72+
}
73+
}
74+
75+

Examples/SimpleVideoAnimation/SimpleVIdeoAnimation/ViewController.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,29 @@ class ViewController: UIViewController {
3535
let fadeIn = MetalVideoProcessFadeInMotion()
3636
fadeIn.timingType = .quadraticEaseOut
3737

38-
let fadeOut = MetalVideoProcessFadeOutMotion()
39-
fadeOut.timingType = .quarticEaseOut
40-
4138
let fadeInTimeRange = CMTimeRangeMake(start: CMTime(seconds: 2.0), duration: CMTime(seconds: 2.0))
4239
fadeIn.saveUniformSettings(forTimelineRange: fadeInTimeRange, trackID: item1.trackID)
4340

44-
let fadeOutTimeRange = CMTimeRange(start: item1.timeRange.end - CMTime(seconds: 4.0), duration: CMTime(seconds: 1.5))
45-
fadeOut.saveUniformSettings(forTimelineRange: fadeOutTimeRange, trackID: item1.trackID)
46-
4741
let player = try MetalVideoProcessPlayer(playerItem: playerItem)
4842
player.playerDelegate = self
4943

5044
let background = MetalVideoProcessBackground(trackID: 0)
5145
background.aspectRatioType = .Ratio9_16
5246
background.canvasSizeType = .Type720p
53-
background.setBackgroundType(type: .Blur)
47+
background.setBackgroundType(type: .Black)
5448

5549
let transform = MetalVideoProcessTransformFilter()
5650
transform.saveUniformSettings(forTimelineRange: item1.timeRange, trackID: item1.trackID)
5751
transform.roi = CGRect(x: 0.25, y: 0.25, width: 0.5, height: 0.5)
5852

5953
player.addTarget(background, atTargetIndex: 0, trackID: item1.trackID, targetTrackId: 0)
60-
54+
55+
6156
background --> fadeIn //source 0
6257
player.addTarget(transform, atTargetIndex: nil, trackID: item1.trackID, targetTrackId: 0) //source 1
6358

64-
transform --> fadeIn //source 1
59+
transform --> fadeIn --> renderView//source 1
6560

66-
background --> fadeOut //source 0
67-
fadeIn --> fadeOut --> renderView //source 1
68-
6961
self.player = player
7062
} catch {
7163

Examples/SimpleVideoEditor/SimpleVideoEditor/ViewController+UIGestureRecognizerDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension ViewController: UIGestureRecognizerDelegate {
5858
let tanl = ges.translation(in: ges.view)
5959

6060
// have to content the view scaleFactor and the vertex to texture scale.
61-
transformFilter.translation = Position(currentPostion.x + Float(tanl.x * self.renderView.contentScaleFactor * 2.0) / Float(self.renderView.drawableSize.width), currentPostion.y - Float(tanl.y * self.renderView.contentScaleFactor * 2.0) / Float(self.renderView.drawableSize.height))
61+
transformFilter.translation = Position(currentPostion.x + Float(tanl.x * self.renderView.contentScaleFactor * 2.0) / Float(self.renderView.drawableSize.width), 1.0 - currentPostion.y - Float(tanl.y * self.renderView.contentScaleFactor * 2.0) / Float(self.renderView.drawableSize.height))
6262

6363
} else if ges.state == .ended {
6464
currentPostion = (transformFilter.translation)

0 commit comments

Comments
 (0)