├── .gitignore ├── Podfile ├── README.md ├── Test.mp4 ├── VideoToWebpDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── VideoToWebpDemo.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── VideoToWebpDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── VideoToWebpDemoUITests ├── Info.plist └── VideoToWebpDemoUITests.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ 3 | build_info 4 | debugBuild.sh 5 | products/ 6 | Build/ 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | #*.xcworkspace 16 | !default.xcworkspace 17 | xcuserdata 18 | profile 19 | *.moved-aside 20 | DerivedData 21 | .idea/ 22 | *.xcuserstate 23 | *.xcbkptlist 24 | # Pods - for those of you who use CocoaPods 25 | Pods/ 26 | *.swp 27 | Podfile.lock -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '8.0' 2 | 3 | source 'https://github.com/CocoaPods/Specs.git' 4 | 5 | target 'VideoToWebpDemo' do 6 | project 'VideoToWebpDemo' 7 | 8 | #第三方库 9 | pod 'YYWebImage', '~>1.0.0' 10 | pod 'YYImage/WebP' 11 | end 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VideoToWebp 2 | ## [抖音短视频生成webp动图解决方案](https://www.jianshu.com/p/c75938791cdf) 3 | -------------------------------------------------------------------------------- /Test.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxShare/VideoToWebp/a7ee677f77767342566633f498b452c72bb0f24c/Test.mp4 -------------------------------------------------------------------------------- /VideoToWebpDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1894801CEB793CCEE103D7B0 /* libPods-VideoToWebpDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 33A08A3076576EE6E16B65B3 /* libPods-VideoToWebpDemo.a */; }; 11 | 465A4042209B14C400B4C795 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 465A4041209B14C400B4C795 /* AppDelegate.m */; }; 12 | 465A4045209B14C700B4C795 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 465A4044209B14C700B4C795 /* ViewController.m */; }; 13 | 465A4048209B14C800B4C795 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 465A4046209B14C800B4C795 /* Main.storyboard */; }; 14 | 465A404A209B14CC00B4C795 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 465A4049209B14CC00B4C795 /* Assets.xcassets */; }; 15 | 465A404D209B14CC00B4C795 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 465A404B209B14CC00B4C795 /* LaunchScreen.storyboard */; }; 16 | 465A4050209B14CC00B4C795 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 465A404F209B14CC00B4C795 /* main.m */; }; 17 | 465A405A209B14CC00B4C795 /* VideoToWebpDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 465A4059209B14CC00B4C795 /* VideoToWebpDemoUITests.m */; }; 18 | 465A4065209B154000B4C795 /* Test.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 465A4064209B154000B4C795 /* Test.mp4 */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 465A4056209B14CC00B4C795 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 465A4035209B14C400B4C795 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 465A403C209B14C400B4C795; 27 | remoteInfo = VideoToWebpDemo; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 33A08A3076576EE6E16B65B3 /* libPods-VideoToWebpDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VideoToWebpDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 465A403D209B14C400B4C795 /* VideoToWebpDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VideoToWebpDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 465A4040209B14C400B4C795 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | 465A4041209B14C400B4C795 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | 465A4043209B14C400B4C795 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | 465A4044209B14C700B4C795 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | 465A4047209B14C800B4C795 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | 465A4049209B14CC00B4C795 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 465A404C209B14CC00B4C795 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | 465A404E209B14CC00B4C795 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 465A404F209B14CC00B4C795 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 43 | 465A4055209B14CC00B4C795 /* VideoToWebpDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VideoToWebpDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 465A4059209B14CC00B4C795 /* VideoToWebpDemoUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VideoToWebpDemoUITests.m; sourceTree = ""; }; 45 | 465A405B209B14CC00B4C795 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | 465A4064209B154000B4C795 /* Test.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = Test.mp4; sourceTree = ""; }; 47 | 9EE8F28AAF74795B1FBC8AF4 /* Pods-VideoToWebpDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VideoToWebpDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-VideoToWebpDemo/Pods-VideoToWebpDemo.debug.xcconfig"; sourceTree = ""; }; 48 | C5BC8D21133426FE7E04309C /* Pods-VideoToWebpDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VideoToWebpDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-VideoToWebpDemo/Pods-VideoToWebpDemo.release.xcconfig"; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | 465A403A209B14C400B4C795 /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | 1894801CEB793CCEE103D7B0 /* libPods-VideoToWebpDemo.a in Frameworks */, 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | 465A4052209B14CC00B4C795 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | /* End PBXFrameworksBuildPhase section */ 68 | 69 | /* Begin PBXGroup section */ 70 | 465A4034209B14C400B4C795 = { 71 | isa = PBXGroup; 72 | children = ( 73 | 465A4064209B154000B4C795 /* Test.mp4 */, 74 | 465A403F209B14C400B4C795 /* VideoToWebpDemo */, 75 | 465A4058209B14CC00B4C795 /* VideoToWebpDemoUITests */, 76 | 465A403E209B14C400B4C795 /* Products */, 77 | BE143FDE70509D5255477E28 /* Pods */, 78 | 5093730E2035AE391AA91483 /* Frameworks */, 79 | ); 80 | sourceTree = ""; 81 | }; 82 | 465A403E209B14C400B4C795 /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 465A403D209B14C400B4C795 /* VideoToWebpDemo.app */, 86 | 465A4055209B14CC00B4C795 /* VideoToWebpDemoUITests.xctest */, 87 | ); 88 | name = Products; 89 | sourceTree = ""; 90 | }; 91 | 465A403F209B14C400B4C795 /* VideoToWebpDemo */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 465A4040209B14C400B4C795 /* AppDelegate.h */, 95 | 465A4041209B14C400B4C795 /* AppDelegate.m */, 96 | 465A4043209B14C400B4C795 /* ViewController.h */, 97 | 465A4044209B14C700B4C795 /* ViewController.m */, 98 | 465A4046209B14C800B4C795 /* Main.storyboard */, 99 | 465A4049209B14CC00B4C795 /* Assets.xcassets */, 100 | 465A404B209B14CC00B4C795 /* LaunchScreen.storyboard */, 101 | 465A404E209B14CC00B4C795 /* Info.plist */, 102 | 465A404F209B14CC00B4C795 /* main.m */, 103 | ); 104 | path = VideoToWebpDemo; 105 | sourceTree = ""; 106 | }; 107 | 465A4058209B14CC00B4C795 /* VideoToWebpDemoUITests */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 465A4059209B14CC00B4C795 /* VideoToWebpDemoUITests.m */, 111 | 465A405B209B14CC00B4C795 /* Info.plist */, 112 | ); 113 | path = VideoToWebpDemoUITests; 114 | sourceTree = ""; 115 | }; 116 | 5093730E2035AE391AA91483 /* Frameworks */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 33A08A3076576EE6E16B65B3 /* libPods-VideoToWebpDemo.a */, 120 | ); 121 | name = Frameworks; 122 | sourceTree = ""; 123 | }; 124 | BE143FDE70509D5255477E28 /* Pods */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 9EE8F28AAF74795B1FBC8AF4 /* Pods-VideoToWebpDemo.debug.xcconfig */, 128 | C5BC8D21133426FE7E04309C /* Pods-VideoToWebpDemo.release.xcconfig */, 129 | ); 130 | name = Pods; 131 | sourceTree = ""; 132 | }; 133 | /* End PBXGroup section */ 134 | 135 | /* Begin PBXNativeTarget section */ 136 | 465A403C209B14C400B4C795 /* VideoToWebpDemo */ = { 137 | isa = PBXNativeTarget; 138 | buildConfigurationList = 465A405E209B14CC00B4C795 /* Build configuration list for PBXNativeTarget "VideoToWebpDemo" */; 139 | buildPhases = ( 140 | 6ACB75BD1301256F2B6918E4 /* [CP] Check Pods Manifest.lock */, 141 | 465A4039209B14C400B4C795 /* Sources */, 142 | 465A403A209B14C400B4C795 /* Frameworks */, 143 | 465A403B209B14C400B4C795 /* Resources */, 144 | 31B1BDDCEC5E78E2F7AAE40F /* [CP] Embed Pods Frameworks */, 145 | F6B746CBAA934A0538A83562 /* [CP] Copy Pods Resources */, 146 | ); 147 | buildRules = ( 148 | ); 149 | dependencies = ( 150 | ); 151 | name = VideoToWebpDemo; 152 | productName = VideoToWebpDemo; 153 | productReference = 465A403D209B14C400B4C795 /* VideoToWebpDemo.app */; 154 | productType = "com.apple.product-type.application"; 155 | }; 156 | 465A4054209B14CC00B4C795 /* VideoToWebpDemoUITests */ = { 157 | isa = PBXNativeTarget; 158 | buildConfigurationList = 465A4061209B14CC00B4C795 /* Build configuration list for PBXNativeTarget "VideoToWebpDemoUITests" */; 159 | buildPhases = ( 160 | 465A4051209B14CC00B4C795 /* Sources */, 161 | 465A4052209B14CC00B4C795 /* Frameworks */, 162 | 465A4053209B14CC00B4C795 /* Resources */, 163 | ); 164 | buildRules = ( 165 | ); 166 | dependencies = ( 167 | 465A4057209B14CC00B4C795 /* PBXTargetDependency */, 168 | ); 169 | name = VideoToWebpDemoUITests; 170 | productName = VideoToWebpDemoUITests; 171 | productReference = 465A4055209B14CC00B4C795 /* VideoToWebpDemoUITests.xctest */; 172 | productType = "com.apple.product-type.bundle.ui-testing"; 173 | }; 174 | /* End PBXNativeTarget section */ 175 | 176 | /* Begin PBXProject section */ 177 | 465A4035209B14C400B4C795 /* Project object */ = { 178 | isa = PBXProject; 179 | attributes = { 180 | LastUpgradeCheck = 0930; 181 | ORGANIZATIONNAME = kanxiang; 182 | TargetAttributes = { 183 | 465A403C209B14C400B4C795 = { 184 | CreatedOnToolsVersion = 9.3; 185 | }; 186 | 465A4054209B14CC00B4C795 = { 187 | CreatedOnToolsVersion = 9.3; 188 | TestTargetID = 465A403C209B14C400B4C795; 189 | }; 190 | }; 191 | }; 192 | buildConfigurationList = 465A4038209B14C400B4C795 /* Build configuration list for PBXProject "VideoToWebpDemo" */; 193 | compatibilityVersion = "Xcode 9.3"; 194 | developmentRegion = en; 195 | hasScannedForEncodings = 0; 196 | knownRegions = ( 197 | en, 198 | Base, 199 | ); 200 | mainGroup = 465A4034209B14C400B4C795; 201 | productRefGroup = 465A403E209B14C400B4C795 /* Products */; 202 | projectDirPath = ""; 203 | projectRoot = ""; 204 | targets = ( 205 | 465A403C209B14C400B4C795 /* VideoToWebpDemo */, 206 | 465A4054209B14CC00B4C795 /* VideoToWebpDemoUITests */, 207 | ); 208 | }; 209 | /* End PBXProject section */ 210 | 211 | /* Begin PBXResourcesBuildPhase section */ 212 | 465A403B209B14C400B4C795 /* Resources */ = { 213 | isa = PBXResourcesBuildPhase; 214 | buildActionMask = 2147483647; 215 | files = ( 216 | 465A4065209B154000B4C795 /* Test.mp4 in Resources */, 217 | 465A404D209B14CC00B4C795 /* LaunchScreen.storyboard in Resources */, 218 | 465A404A209B14CC00B4C795 /* Assets.xcassets in Resources */, 219 | 465A4048209B14C800B4C795 /* Main.storyboard in Resources */, 220 | ); 221 | runOnlyForDeploymentPostprocessing = 0; 222 | }; 223 | 465A4053209B14CC00B4C795 /* Resources */ = { 224 | isa = PBXResourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | ); 228 | runOnlyForDeploymentPostprocessing = 0; 229 | }; 230 | /* End PBXResourcesBuildPhase section */ 231 | 232 | /* Begin PBXShellScriptBuildPhase section */ 233 | 31B1BDDCEC5E78E2F7AAE40F /* [CP] Embed Pods Frameworks */ = { 234 | isa = PBXShellScriptBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | ); 238 | inputPaths = ( 239 | ); 240 | name = "[CP] Embed Pods Frameworks"; 241 | outputPaths = ( 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | shellPath = /bin/sh; 245 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VideoToWebpDemo/Pods-VideoToWebpDemo-frameworks.sh\"\n"; 246 | showEnvVarsInLog = 0; 247 | }; 248 | 6ACB75BD1301256F2B6918E4 /* [CP] Check Pods Manifest.lock */ = { 249 | isa = PBXShellScriptBuildPhase; 250 | buildActionMask = 2147483647; 251 | files = ( 252 | ); 253 | inputPaths = ( 254 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 255 | "${PODS_ROOT}/Manifest.lock", 256 | ); 257 | name = "[CP] Check Pods Manifest.lock"; 258 | outputPaths = ( 259 | "$(DERIVED_FILE_DIR)/Pods-VideoToWebpDemo-checkManifestLockResult.txt", 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | shellPath = /bin/sh; 263 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 264 | showEnvVarsInLog = 0; 265 | }; 266 | F6B746CBAA934A0538A83562 /* [CP] Copy Pods Resources */ = { 267 | isa = PBXShellScriptBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | ); 271 | inputPaths = ( 272 | ); 273 | name = "[CP] Copy Pods Resources"; 274 | outputPaths = ( 275 | ); 276 | runOnlyForDeploymentPostprocessing = 0; 277 | shellPath = /bin/sh; 278 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VideoToWebpDemo/Pods-VideoToWebpDemo-resources.sh\"\n"; 279 | showEnvVarsInLog = 0; 280 | }; 281 | /* End PBXShellScriptBuildPhase section */ 282 | 283 | /* Begin PBXSourcesBuildPhase section */ 284 | 465A4039209B14C400B4C795 /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | 465A4045209B14C700B4C795 /* ViewController.m in Sources */, 289 | 465A4050209B14CC00B4C795 /* main.m in Sources */, 290 | 465A4042209B14C400B4C795 /* AppDelegate.m in Sources */, 291 | ); 292 | runOnlyForDeploymentPostprocessing = 0; 293 | }; 294 | 465A4051209B14CC00B4C795 /* Sources */ = { 295 | isa = PBXSourcesBuildPhase; 296 | buildActionMask = 2147483647; 297 | files = ( 298 | 465A405A209B14CC00B4C795 /* VideoToWebpDemoUITests.m in Sources */, 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | /* End PBXSourcesBuildPhase section */ 303 | 304 | /* Begin PBXTargetDependency section */ 305 | 465A4057209B14CC00B4C795 /* PBXTargetDependency */ = { 306 | isa = PBXTargetDependency; 307 | target = 465A403C209B14C400B4C795 /* VideoToWebpDemo */; 308 | targetProxy = 465A4056209B14CC00B4C795 /* PBXContainerItemProxy */; 309 | }; 310 | /* End PBXTargetDependency section */ 311 | 312 | /* Begin PBXVariantGroup section */ 313 | 465A4046209B14C800B4C795 /* Main.storyboard */ = { 314 | isa = PBXVariantGroup; 315 | children = ( 316 | 465A4047209B14C800B4C795 /* Base */, 317 | ); 318 | name = Main.storyboard; 319 | sourceTree = ""; 320 | }; 321 | 465A404B209B14CC00B4C795 /* LaunchScreen.storyboard */ = { 322 | isa = PBXVariantGroup; 323 | children = ( 324 | 465A404C209B14CC00B4C795 /* Base */, 325 | ); 326 | name = LaunchScreen.storyboard; 327 | sourceTree = ""; 328 | }; 329 | /* End PBXVariantGroup section */ 330 | 331 | /* Begin XCBuildConfiguration section */ 332 | 465A405C209B14CC00B4C795 /* Debug */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | ALWAYS_SEARCH_USER_PATHS = NO; 336 | CLANG_ANALYZER_NONNULL = YES; 337 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 338 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 339 | CLANG_CXX_LIBRARY = "libc++"; 340 | CLANG_ENABLE_MODULES = YES; 341 | CLANG_ENABLE_OBJC_ARC = YES; 342 | CLANG_ENABLE_OBJC_WEAK = YES; 343 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 344 | CLANG_WARN_BOOL_CONVERSION = YES; 345 | CLANG_WARN_COMMA = YES; 346 | CLANG_WARN_CONSTANT_CONVERSION = YES; 347 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 348 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 349 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 350 | CLANG_WARN_EMPTY_BODY = YES; 351 | CLANG_WARN_ENUM_CONVERSION = YES; 352 | CLANG_WARN_INFINITE_RECURSION = YES; 353 | CLANG_WARN_INT_CONVERSION = YES; 354 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 355 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 356 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 357 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 358 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 359 | CLANG_WARN_STRICT_PROTOTYPES = YES; 360 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 361 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 362 | CLANG_WARN_UNREACHABLE_CODE = YES; 363 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 364 | CODE_SIGN_IDENTITY = "iPhone Developer"; 365 | COPY_PHASE_STRIP = NO; 366 | DEBUG_INFORMATION_FORMAT = dwarf; 367 | ENABLE_STRICT_OBJC_MSGSEND = YES; 368 | ENABLE_TESTABILITY = YES; 369 | GCC_C_LANGUAGE_STANDARD = gnu11; 370 | GCC_DYNAMIC_NO_PIC = NO; 371 | GCC_NO_COMMON_BLOCKS = YES; 372 | GCC_OPTIMIZATION_LEVEL = 0; 373 | GCC_PREPROCESSOR_DEFINITIONS = ( 374 | "DEBUG=1", 375 | "$(inherited)", 376 | ); 377 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 378 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 379 | GCC_WARN_UNDECLARED_SELECTOR = YES; 380 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 381 | GCC_WARN_UNUSED_FUNCTION = YES; 382 | GCC_WARN_UNUSED_VARIABLE = YES; 383 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 384 | MTL_ENABLE_DEBUG_INFO = YES; 385 | ONLY_ACTIVE_ARCH = YES; 386 | SDKROOT = iphoneos; 387 | }; 388 | name = Debug; 389 | }; 390 | 465A405D209B14CC00B4C795 /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | buildSettings = { 393 | ALWAYS_SEARCH_USER_PATHS = NO; 394 | CLANG_ANALYZER_NONNULL = YES; 395 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 396 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 397 | CLANG_CXX_LIBRARY = "libc++"; 398 | CLANG_ENABLE_MODULES = YES; 399 | CLANG_ENABLE_OBJC_ARC = YES; 400 | CLANG_ENABLE_OBJC_WEAK = YES; 401 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 402 | CLANG_WARN_BOOL_CONVERSION = YES; 403 | CLANG_WARN_COMMA = YES; 404 | CLANG_WARN_CONSTANT_CONVERSION = YES; 405 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 406 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 407 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 408 | CLANG_WARN_EMPTY_BODY = YES; 409 | CLANG_WARN_ENUM_CONVERSION = YES; 410 | CLANG_WARN_INFINITE_RECURSION = YES; 411 | CLANG_WARN_INT_CONVERSION = YES; 412 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 413 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 414 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 415 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 416 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 417 | CLANG_WARN_STRICT_PROTOTYPES = YES; 418 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 419 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 420 | CLANG_WARN_UNREACHABLE_CODE = YES; 421 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 422 | CODE_SIGN_IDENTITY = "iPhone Developer"; 423 | COPY_PHASE_STRIP = NO; 424 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 425 | ENABLE_NS_ASSERTIONS = NO; 426 | ENABLE_STRICT_OBJC_MSGSEND = YES; 427 | GCC_C_LANGUAGE_STANDARD = gnu11; 428 | GCC_NO_COMMON_BLOCKS = YES; 429 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 430 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 431 | GCC_WARN_UNDECLARED_SELECTOR = YES; 432 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 433 | GCC_WARN_UNUSED_FUNCTION = YES; 434 | GCC_WARN_UNUSED_VARIABLE = YES; 435 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 436 | MTL_ENABLE_DEBUG_INFO = NO; 437 | SDKROOT = iphoneos; 438 | VALIDATE_PRODUCT = YES; 439 | }; 440 | name = Release; 441 | }; 442 | 465A405F209B14CC00B4C795 /* Debug */ = { 443 | isa = XCBuildConfiguration; 444 | baseConfigurationReference = 9EE8F28AAF74795B1FBC8AF4 /* Pods-VideoToWebpDemo.debug.xcconfig */; 445 | buildSettings = { 446 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 447 | CODE_SIGN_STYLE = Manual; 448 | DEVELOPMENT_TEAM = ""; 449 | INFOPLIST_FILE = VideoToWebpDemo/Info.plist; 450 | LD_RUNPATH_SEARCH_PATHS = ( 451 | "$(inherited)", 452 | "@executable_path/Frameworks", 453 | ); 454 | PRODUCT_BUNDLE_IDENTIFIER = cn.kx.ios.VideoToWebpDemo; 455 | PRODUCT_NAME = "$(TARGET_NAME)"; 456 | PROVISIONING_PROFILE_SPECIFIER = ""; 457 | TARGETED_DEVICE_FAMILY = "1,2"; 458 | }; 459 | name = Debug; 460 | }; 461 | 465A4060209B14CC00B4C795 /* Release */ = { 462 | isa = XCBuildConfiguration; 463 | baseConfigurationReference = C5BC8D21133426FE7E04309C /* Pods-VideoToWebpDemo.release.xcconfig */; 464 | buildSettings = { 465 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 466 | CODE_SIGN_STYLE = Manual; 467 | DEVELOPMENT_TEAM = ""; 468 | INFOPLIST_FILE = VideoToWebpDemo/Info.plist; 469 | LD_RUNPATH_SEARCH_PATHS = ( 470 | "$(inherited)", 471 | "@executable_path/Frameworks", 472 | ); 473 | PRODUCT_BUNDLE_IDENTIFIER = cn.kx.ios.VideoToWebpDemo; 474 | PRODUCT_NAME = "$(TARGET_NAME)"; 475 | PROVISIONING_PROFILE_SPECIFIER = ""; 476 | TARGETED_DEVICE_FAMILY = "1,2"; 477 | }; 478 | name = Release; 479 | }; 480 | 465A4062209B14CC00B4C795 /* Debug */ = { 481 | isa = XCBuildConfiguration; 482 | buildSettings = { 483 | CODE_SIGN_STYLE = Automatic; 484 | INFOPLIST_FILE = VideoToWebpDemoUITests/Info.plist; 485 | LD_RUNPATH_SEARCH_PATHS = ( 486 | "$(inherited)", 487 | "@executable_path/Frameworks", 488 | "@loader_path/Frameworks", 489 | ); 490 | PRODUCT_BUNDLE_IDENTIFIER = cn.kx.ios.VideoToWebpDemoUITests; 491 | PRODUCT_NAME = "$(TARGET_NAME)"; 492 | TARGETED_DEVICE_FAMILY = "1,2"; 493 | TEST_TARGET_NAME = VideoToWebpDemo; 494 | }; 495 | name = Debug; 496 | }; 497 | 465A4063209B14CC00B4C795 /* Release */ = { 498 | isa = XCBuildConfiguration; 499 | buildSettings = { 500 | CODE_SIGN_STYLE = Automatic; 501 | INFOPLIST_FILE = VideoToWebpDemoUITests/Info.plist; 502 | LD_RUNPATH_SEARCH_PATHS = ( 503 | "$(inherited)", 504 | "@executable_path/Frameworks", 505 | "@loader_path/Frameworks", 506 | ); 507 | PRODUCT_BUNDLE_IDENTIFIER = cn.kx.ios.VideoToWebpDemoUITests; 508 | PRODUCT_NAME = "$(TARGET_NAME)"; 509 | TARGETED_DEVICE_FAMILY = "1,2"; 510 | TEST_TARGET_NAME = VideoToWebpDemo; 511 | }; 512 | name = Release; 513 | }; 514 | /* End XCBuildConfiguration section */ 515 | 516 | /* Begin XCConfigurationList section */ 517 | 465A4038209B14C400B4C795 /* Build configuration list for PBXProject "VideoToWebpDemo" */ = { 518 | isa = XCConfigurationList; 519 | buildConfigurations = ( 520 | 465A405C209B14CC00B4C795 /* Debug */, 521 | 465A405D209B14CC00B4C795 /* Release */, 522 | ); 523 | defaultConfigurationIsVisible = 0; 524 | defaultConfigurationName = Release; 525 | }; 526 | 465A405E209B14CC00B4C795 /* Build configuration list for PBXNativeTarget "VideoToWebpDemo" */ = { 527 | isa = XCConfigurationList; 528 | buildConfigurations = ( 529 | 465A405F209B14CC00B4C795 /* Debug */, 530 | 465A4060209B14CC00B4C795 /* Release */, 531 | ); 532 | defaultConfigurationIsVisible = 0; 533 | defaultConfigurationName = Release; 534 | }; 535 | 465A4061209B14CC00B4C795 /* Build configuration list for PBXNativeTarget "VideoToWebpDemoUITests" */ = { 536 | isa = XCConfigurationList; 537 | buildConfigurations = ( 538 | 465A4062209B14CC00B4C795 /* Debug */, 539 | 465A4063209B14CC00B4C795 /* Release */, 540 | ); 541 | defaultConfigurationIsVisible = 0; 542 | defaultConfigurationName = Release; 543 | }; 544 | /* End XCConfigurationList section */ 545 | }; 546 | rootObject = 465A4035209B14C400B4C795 /* Project object */; 547 | } 548 | -------------------------------------------------------------------------------- /VideoToWebpDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VideoToWebpDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /VideoToWebpDemo.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /VideoToWebpDemo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /VideoToWebpDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // AppDelegate.h 2 | // VideoToWebpDemo 3 | // 4 | // Created by K·X on 2018/5/3. 5 | // Copyright © 2018年 kanxiang. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface AppDelegate : UIResponder 11 | 12 | @property (strong, nonatomic) UIWindow *window; 13 | 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /VideoToWebpDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // AppDelegate.m 2 | // VideoToWebpDemo 3 | // 4 | // Created by K·X on 2018/5/3. 5 | // Copyright © 2018年 kanxiang. All rights reserved. 6 | // 7 | 8 | #import "AppDelegate.h" 9 | 10 | @interface AppDelegate () 11 | 12 | @end 13 | 14 | @implementation AppDelegate 15 | 16 | 17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 18 | // Override point for customization after application launch. 19 | return YES; 20 | } 21 | 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 26 | } 27 | 28 | 29 | - (void)applicationDidEnterBackground:(UIApplication *)application { 30 | // 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. 31 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 32 | } 33 | 34 | 35 | - (void)applicationWillEnterForeground:(UIApplication *)application { 36 | // 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. 37 | } 38 | 39 | 40 | - (void)applicationDidBecomeActive:(UIApplication *)application { 41 | // 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. 42 | } 43 | 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /VideoToWebpDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /VideoToWebpDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /VideoToWebpDemo/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 | -------------------------------------------------------------------------------- /VideoToWebpDemo/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 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /VideoToWebpDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | -------------------------------------------------------------------------------- /VideoToWebpDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // ViewController.h 2 | // VideoToWebpDemo 3 | // 4 | // Created by K·X on 2018/5/3. 5 | // Copyright © 2018年 kanxiang. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface ViewController : UIViewController 11 | 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /VideoToWebpDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // ViewController.m 2 | // VideoToWebpDemo 3 | // 4 | // Created by K·X on 2018/5/3. 5 | // Copyright © 2018年 kanxiang. All rights reserved. 6 | // 7 | 8 | #import "ViewController.h" 9 | #import 10 | #import 11 | #import 12 | 13 | @interface ViewController () 14 | - (IBAction)btnSaveClicked:(id)sender; 15 | @property (weak, nonatomic) IBOutlet YYAnimatedImageView *centerAnimateView; 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | // Do any additional setup after loading the view, typically from a nib. 24 | } 25 | 26 | - (void)createFilePath:(NSString *)path{ 27 | NSFileManager *fileManager = [NSFileManager new]; 28 | BOOL isDir = NO; 29 | if ([fileManager fileExistsAtPath:path isDirectory:&isDir]) { 30 | 31 | } else { 32 | [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil]; 33 | } 34 | } 35 | 36 | - (NSString *)createWebpFilePath{ 37 | NSString * path = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp/Media"]; 38 | [self createFilePath:path]; 39 | NSString *uuidStr = [[NSUUID UUID] UUIDString]; 40 | NSString * fileName = [NSString stringWithFormat:@"S_%@.webp",uuidStr]; 41 | return [path stringByAppendingPathComponent:fileName]; 42 | } 43 | 44 | - (NSString * )saveToWebpByVideoPath:(NSURL *)videoUrl{ 45 | NSString * filePath = [self createWebpFilePath]; 46 | YYImageEncoder *gifEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeWebP]; 47 | gifEncoder.loopCount = 0; 48 | gifEncoder.quality = 0.8; 49 | 50 | AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoUrl options:nil]; 51 | int64_t value = asset.duration.value; 52 | int64_t scale = asset.duration.timescale; 53 | 54 | AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; 55 | generator.appliesPreferredTrackTransform = YES; 56 | //下面两个值设为0表示精确取帧,否则系统会有优化取出来的帧时间间隔不对等 57 | generator.requestedTimeToleranceAfter = kCMTimeZero; 58 | generator.requestedTimeToleranceBefore = kCMTimeZero; 59 | 60 | for (int i = 0; i <=4; i++) { 61 | CGFloat starttime = i*0.1+0.5; 62 | CMTime time = CMTimeMakeWithSeconds(starttime, (int)scale); 63 | NSError *error = nil; 64 | CMTime actualTime; 65 | CGImageRef image = [generator copyCGImageAtTime:time actualTime:&actualTime error:&error]; 66 | UIImage * img = [UIImage imageWithCGImage:image]; 67 | img = [self resizeToMaxHeight:480 img:img]; 68 | [gifEncoder addImage:img duration:0.1]; 69 | CGImageRelease(image); 70 | } 71 | for (int i=3; i>=0; i--) { 72 | CGFloat starttime = i*0.1+0.5; 73 | CMTime time = CMTimeMakeWithSeconds(starttime, (int)scale); 74 | NSError *error = nil; 75 | CMTime actualTime; 76 | CGImageRef image = [generator copyCGImageAtTime:time actualTime:&actualTime error:&error]; 77 | UIImage * img = [UIImage imageWithCGImage:image]; 78 | img = [self resizeToMaxHeight:480 img:img]; 79 | [gifEncoder addImage:img duration:0.1]; 80 | CGImageRelease(image); 81 | } 82 | 83 | [gifEncoder encodeToFile:filePath]; 84 | NSLog(@"生成webp成功!"); 85 | return filePath; 86 | } 87 | 88 | - (UIImage *)resizeToMaxHeight:(CGFloat)height img:(UIImage *)img{ 89 | if (img.size.widthheight) { 91 | CGSize newSize = CGSizeMake(height*1.0*img.size.width/img.size.height, height); 92 | img = [img yy_imageByResizeToSize:newSize contentMode:UIViewContentModeScaleToFill]; 93 | } 94 | } 95 | else{ 96 | if (img.size.width>height) { 97 | CGSize newSize = CGSizeMake(height,img.size.height*height*1.0/img.size.width); 98 | img = [img yy_imageByResizeToSize:newSize contentMode:UIViewContentModeScaleToFill]; 99 | } 100 | } 101 | return img; 102 | } 103 | 104 | 105 | - (IBAction)btnSaveClicked:(id)sender { 106 | NSString * videoPath = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"mp4"]; 107 | NSURL * videoUrl = [NSURL fileURLWithPath:videoPath]; 108 | NSString * webpFilePath = [self saveToWebpByVideoPath:videoUrl]; 109 | YYImage * tmpImg = [YYImage imageWithContentsOfFile:webpFilePath]; 110 | self.centerAnimateView.image = tmpImg; 111 | } 112 | @end 113 | -------------------------------------------------------------------------------- /VideoToWebpDemo/main.m: -------------------------------------------------------------------------------- 1 | // main.m 2 | // VideoToWebpDemo 3 | // 4 | // Created by K·X on 2018/5/3. 5 | // Copyright © 2018年 kanxiang. All rights reserved. 6 | // 7 | 8 | #import 9 | #import "AppDelegate.h" 10 | 11 | int main(int argc, char * argv[]) { 12 | @autoreleasepool { 13 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /VideoToWebpDemoUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /VideoToWebpDemoUITests/VideoToWebpDemoUITests.m: -------------------------------------------------------------------------------- 1 | // VideoToWebpDemoUITests.m 2 | // VideoToWebpDemoUITests 3 | // 4 | // Created by K·X on 2018/5/3. 5 | // Copyright © 2018年 kanxiang. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface VideoToWebpDemoUITests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation VideoToWebpDemoUITests 15 | 16 | - (void)setUp { 17 | [super setUp]; 18 | 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | 21 | // In UI tests it is usually best to stop immediately when a failure occurs. 22 | self.continueAfterFailure = NO; 23 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 24 | [[[XCUIApplication alloc] init] launch]; 25 | 26 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 27 | } 28 | 29 | - (void)tearDown { 30 | // Put teardown code here. This method is called after the invocation of each test method in the class. 31 | [super tearDown]; 32 | } 33 | 34 | - (void)testExample { 35 | // Use recording to get started writing UI tests. 36 | // Use XCTAssert and related functions to verify your tests produce the correct results. 37 | } 38 | 39 | @end 40 | --------------------------------------------------------------------------------