├── .gitignore ├── LICENSE ├── README.md ├── TestAVFoundation ├── TestAVFoundation.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── TestAVFoundation │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── dot.imageset │ │ ├── Contents.json │ │ └── 点.png │ ├── icon.imageset │ │ ├── Contents.json │ │ └── Icon120@2x.png │ ├── pause.imageset │ │ ├── Contents.json │ │ └── 暂停.png │ └── play.imageset │ │ ├── Contents.json │ │ └── 播放.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── ConvertUtil.h │ ├── ConvertUtil.m │ ├── FOFMoviePlayerView │ ├── FOFMoviePlayerView.h │ └── FOFMoviePlayerView.m │ ├── Info.plist │ ├── TestMoviePlayerViewController.h │ ├── TestMoviePlayerViewController.m │ ├── VideoEdit │ ├── FOFMoviePlayer │ │ ├── FOFMoviePlayer.h │ │ └── FOFMoviePlayer.m │ ├── Haft.h │ ├── Haft.m │ ├── Line.h │ ├── Line.m │ ├── VideoEditViewController.h │ ├── VideoEditViewController.m │ ├── VideoPieces.h │ └── VideoPieces.m │ ├── VideoPlayerViewController.h │ ├── VideoPlayerViewController.m │ ├── VideoViewController.h │ ├── VideoViewController.m │ ├── ViewController.h │ ├── ViewController.m │ ├── empty.png │ ├── lame │ ├── lame.h │ └── libmp3lame.a │ ├── main.m │ ├── test.aac │ ├── video.mp4 │ ├── 女声.mp3 │ ├── 宿命者.mp3 │ └── 男声.mp3 ├── 微信小视频截取.gif └── 效果.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 OceanFish 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StudyAVFoundation 2 | 对AVFoundation的学习,包括音频视频、的播放、录取、合成、截取、调速等操作 3 | 4 | ![](./效果.gif) 5 | ![](./微信小视频截取.gif) 6 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4211763E209BEDA10022884E /* test.aac in Resources */ = {isa = PBXBuildFile; fileRef = 4211763D209BEDA00022884E /* test.aac */; }; 11 | 422E489920C91EB700455D77 /* ConvertUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 422E489820C91EB700455D77 /* ConvertUtil.m */; }; 12 | 422E489D20C91EF400455D77 /* libmp3lame.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 422E489C20C91EF400455D77 /* libmp3lame.a */; }; 13 | 423ADBE92099809D008A3846 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 423ADBE82099809D008A3846 /* AppDelegate.m */; }; 14 | 423ADBEC2099809D008A3846 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 423ADBEB2099809D008A3846 /* ViewController.m */; }; 15 | 423ADBEF2099809E008A3846 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 423ADBED2099809E008A3846 /* Main.storyboard */; }; 16 | 423ADBF12099809E008A3846 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 423ADBF02099809E008A3846 /* Assets.xcassets */; }; 17 | 423ADBF42099809E008A3846 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 423ADBF22099809E008A3846 /* LaunchScreen.storyboard */; }; 18 | 423ADBF72099809E008A3846 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 423ADBF62099809E008A3846 /* main.m */; }; 19 | 423ADBFF2099A886008A3846 /* 女声.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 423ADBFD2099A886008A3846 /* 女声.mp3 */; }; 20 | 423ADC022099A9EE008A3846 /* 男声.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 423ADC012099A9EE008A3846 /* 男声.mp3 */; }; 21 | 4274FAE7209AA3A300D76153 /* 宿命者.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 4274FAE6209AA3A300D76153 /* 宿命者.mp3 */; }; 22 | 4274FAEB209AAFA200D76153 /* empty.png in Resources */ = {isa = PBXBuildFile; fileRef = 4274FAEA209AAFA200D76153 /* empty.png */; }; 23 | 4276A01A20F8337600000DEE /* VideoPlayerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4276A01920F8337500000DEE /* VideoPlayerViewController.m */; }; 24 | 4276A01D20F8339E00000DEE /* VideoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4276A01C20F8339E00000DEE /* VideoViewController.m */; }; 25 | 42A5D14E20A0225A00566691 /* video.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 42A5D14D20A0225A00566691 /* video.mp4 */; }; 26 | 42A5D15220A130EA00566691 /* video2.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 42A5D15120A130EA00566691 /* video2.mp4 */; }; 27 | 42A5D15820A3DE0E00566691 /* FOFMoviePlayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A5D15720A3DE0E00566691 /* FOFMoviePlayerView.m */; }; 28 | 42A5D15C20A3E23800566691 /* TestMoviePlayerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A5D15A20A3E23800566691 /* TestMoviePlayerViewController.m */; }; 29 | 42A734CB20F596270079E862 /* VideoEditViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A734CA20F596270079E862 /* VideoEditViewController.m */; }; 30 | 42A734CE20F597BE0079E862 /* FOFMoviePlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A734CD20F597BE0079E862 /* FOFMoviePlayer.m */; }; 31 | 42A734D120F5D2EF0079E862 /* VideoPieces.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A734D020F5D2EF0079E862 /* VideoPieces.m */; }; 32 | 42A734D420F5D8940079E862 /* Haft.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A734D320F5D8940079E862 /* Haft.m */; }; 33 | 42A734D720F5E99C0079E862 /* Line.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A734D620F5E99C0079E862 /* Line.m */; }; 34 | /* End PBXBuildFile section */ 35 | 36 | /* Begin PBXFileReference section */ 37 | 4211763D209BEDA00022884E /* test.aac */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.aac; sourceTree = ""; }; 38 | 422E489720C91EB700455D77 /* ConvertUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConvertUtil.h; sourceTree = ""; }; 39 | 422E489820C91EB700455D77 /* ConvertUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConvertUtil.m; sourceTree = ""; }; 40 | 422E489B20C91EEB00455D77 /* lame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lame.h; sourceTree = ""; }; 41 | 422E489C20C91EF400455D77 /* libmp3lame.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libmp3lame.a; sourceTree = ""; }; 42 | 423ADBE42099809D008A3846 /* TestAVFoundation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestAVFoundation.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 423ADBE72099809D008A3846 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | 423ADBE82099809D008A3846 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | 423ADBEA2099809D008A3846 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 46 | 423ADBEB2099809D008A3846 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 47 | 423ADBEE2099809E008A3846 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 48 | 423ADBF02099809E008A3846 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | 423ADBF32099809E008A3846 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 50 | 423ADBF52099809E008A3846 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 423ADBF62099809E008A3846 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 52 | 423ADBFD2099A886008A3846 /* 女声.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "女声.mp3"; sourceTree = ""; }; 53 | 423ADC012099A9EE008A3846 /* 男声.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "男声.mp3"; sourceTree = ""; }; 54 | 4274FAE6209AA3A300D76153 /* 宿命者.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "宿命者.mp3"; sourceTree = ""; }; 55 | 4274FAEA209AAFA200D76153 /* empty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = empty.png; sourceTree = ""; }; 56 | 4276A01920F8337500000DEE /* VideoPlayerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VideoPlayerViewController.m; sourceTree = ""; }; 57 | 4276A01B20F8339E00000DEE /* VideoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoViewController.h; sourceTree = ""; }; 58 | 4276A01C20F8339E00000DEE /* VideoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VideoViewController.m; sourceTree = ""; }; 59 | 42A5D14A20A0197F00566691 /* VideoPlayerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoPlayerViewController.h; sourceTree = ""; }; 60 | 42A5D14D20A0225A00566691 /* video.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = video.mp4; sourceTree = ""; }; 61 | 42A5D15120A130EA00566691 /* video2.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = video2.mp4; sourceTree = ""; }; 62 | 42A5D15620A3DE0E00566691 /* FOFMoviePlayerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FOFMoviePlayerView.h; sourceTree = ""; }; 63 | 42A5D15720A3DE0E00566691 /* FOFMoviePlayerView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FOFMoviePlayerView.m; sourceTree = ""; }; 64 | 42A5D15920A3E23800566691 /* TestMoviePlayerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestMoviePlayerViewController.h; sourceTree = ""; }; 65 | 42A5D15A20A3E23800566691 /* TestMoviePlayerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestMoviePlayerViewController.m; sourceTree = ""; }; 66 | 42A734C920F596270079E862 /* VideoEditViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoEditViewController.h; sourceTree = ""; }; 67 | 42A734CA20F596270079E862 /* VideoEditViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VideoEditViewController.m; sourceTree = ""; }; 68 | 42A734CC20F597BE0079E862 /* FOFMoviePlayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FOFMoviePlayer.h; sourceTree = ""; }; 69 | 42A734CD20F597BE0079E862 /* FOFMoviePlayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FOFMoviePlayer.m; sourceTree = ""; }; 70 | 42A734CF20F5D2EF0079E862 /* VideoPieces.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoPieces.h; sourceTree = ""; }; 71 | 42A734D020F5D2EF0079E862 /* VideoPieces.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VideoPieces.m; sourceTree = ""; }; 72 | 42A734D220F5D8940079E862 /* Haft.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Haft.h; sourceTree = ""; }; 73 | 42A734D320F5D8940079E862 /* Haft.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Haft.m; sourceTree = ""; }; 74 | 42A734D520F5E99C0079E862 /* Line.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Line.h; sourceTree = ""; }; 75 | 42A734D620F5E99C0079E862 /* Line.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Line.m; sourceTree = ""; }; 76 | /* End PBXFileReference section */ 77 | 78 | /* Begin PBXFrameworksBuildPhase section */ 79 | 423ADBE12099809D008A3846 /* Frameworks */ = { 80 | isa = PBXFrameworksBuildPhase; 81 | buildActionMask = 2147483647; 82 | files = ( 83 | 422E489D20C91EF400455D77 /* libmp3lame.a in Frameworks */, 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | /* End PBXFrameworksBuildPhase section */ 88 | 89 | /* Begin PBXGroup section */ 90 | 422E489A20C91ED300455D77 /* lame */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 422E489B20C91EEB00455D77 /* lame.h */, 94 | 422E489C20C91EF400455D77 /* libmp3lame.a */, 95 | ); 96 | path = lame; 97 | sourceTree = ""; 98 | }; 99 | 423ADBDB2099809C008A3846 = { 100 | isa = PBXGroup; 101 | children = ( 102 | 423ADBE62099809D008A3846 /* TestAVFoundation */, 103 | 423ADBE52099809D008A3846 /* Products */, 104 | ); 105 | sourceTree = ""; 106 | }; 107 | 423ADBE52099809D008A3846 /* Products */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 423ADBE42099809D008A3846 /* TestAVFoundation.app */, 111 | ); 112 | name = Products; 113 | sourceTree = ""; 114 | }; 115 | 423ADBE62099809D008A3846 /* TestAVFoundation */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 42A734C820F595DC0079E862 /* VideoEdit */, 119 | 427D0F5420FD800200A6AFE7 /* FOFMoviePlayerView */, 120 | 422E489A20C91ED300455D77 /* lame */, 121 | 423ADC012099A9EE008A3846 /* 男声.mp3 */, 122 | 423ADBFD2099A886008A3846 /* 女声.mp3 */, 123 | 4274FAE6209AA3A300D76153 /* 宿命者.mp3 */, 124 | 4211763D209BEDA00022884E /* test.aac */, 125 | 4274FAEA209AAFA200D76153 /* empty.png */, 126 | 42A5D14D20A0225A00566691 /* video.mp4 */, 127 | 42A5D15120A130EA00566691 /* video2.mp4 */, 128 | 423ADBE72099809D008A3846 /* AppDelegate.h */, 129 | 423ADBE82099809D008A3846 /* AppDelegate.m */, 130 | 423ADBEA2099809D008A3846 /* ViewController.h */, 131 | 423ADBEB2099809D008A3846 /* ViewController.m */, 132 | 4276A01B20F8339E00000DEE /* VideoViewController.h */, 133 | 4276A01C20F8339E00000DEE /* VideoViewController.m */, 134 | 42A5D14A20A0197F00566691 /* VideoPlayerViewController.h */, 135 | 4276A01920F8337500000DEE /* VideoPlayerViewController.m */, 136 | 42A5D15920A3E23800566691 /* TestMoviePlayerViewController.h */, 137 | 42A5D15A20A3E23800566691 /* TestMoviePlayerViewController.m */, 138 | 422E489720C91EB700455D77 /* ConvertUtil.h */, 139 | 422E489820C91EB700455D77 /* ConvertUtil.m */, 140 | 423ADBED2099809E008A3846 /* Main.storyboard */, 141 | 423ADBF02099809E008A3846 /* Assets.xcassets */, 142 | 423ADBF22099809E008A3846 /* LaunchScreen.storyboard */, 143 | 423ADBF52099809E008A3846 /* Info.plist */, 144 | 423ADBF62099809E008A3846 /* main.m */, 145 | ); 146 | path = TestAVFoundation; 147 | sourceTree = ""; 148 | }; 149 | 427D0F5320FD7FEC00A6AFE7 /* FOFMoviePlayer */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | 42A734CC20F597BE0079E862 /* FOFMoviePlayer.h */, 153 | 42A734CD20F597BE0079E862 /* FOFMoviePlayer.m */, 154 | ); 155 | path = FOFMoviePlayer; 156 | sourceTree = ""; 157 | }; 158 | 427D0F5420FD800200A6AFE7 /* FOFMoviePlayerView */ = { 159 | isa = PBXGroup; 160 | children = ( 161 | 42A5D15620A3DE0E00566691 /* FOFMoviePlayerView.h */, 162 | 42A5D15720A3DE0E00566691 /* FOFMoviePlayerView.m */, 163 | ); 164 | path = FOFMoviePlayerView; 165 | sourceTree = ""; 166 | }; 167 | 42A734C820F595DC0079E862 /* VideoEdit */ = { 168 | isa = PBXGroup; 169 | children = ( 170 | 427D0F5320FD7FEC00A6AFE7 /* FOFMoviePlayer */, 171 | 42A734C920F596270079E862 /* VideoEditViewController.h */, 172 | 42A734CA20F596270079E862 /* VideoEditViewController.m */, 173 | 42A734CF20F5D2EF0079E862 /* VideoPieces.h */, 174 | 42A734D020F5D2EF0079E862 /* VideoPieces.m */, 175 | 42A734D220F5D8940079E862 /* Haft.h */, 176 | 42A734D320F5D8940079E862 /* Haft.m */, 177 | 42A734D520F5E99C0079E862 /* Line.h */, 178 | 42A734D620F5E99C0079E862 /* Line.m */, 179 | ); 180 | path = VideoEdit; 181 | sourceTree = ""; 182 | }; 183 | /* End PBXGroup section */ 184 | 185 | /* Begin PBXNativeTarget section */ 186 | 423ADBE32099809D008A3846 /* TestAVFoundation */ = { 187 | isa = PBXNativeTarget; 188 | buildConfigurationList = 423ADBFA2099809E008A3846 /* Build configuration list for PBXNativeTarget "TestAVFoundation" */; 189 | buildPhases = ( 190 | 423ADBE02099809D008A3846 /* Sources */, 191 | 423ADBE12099809D008A3846 /* Frameworks */, 192 | 423ADBE22099809D008A3846 /* Resources */, 193 | ); 194 | buildRules = ( 195 | ); 196 | dependencies = ( 197 | ); 198 | name = TestAVFoundation; 199 | productName = TestAVFoundation; 200 | productReference = 423ADBE42099809D008A3846 /* TestAVFoundation.app */; 201 | productType = "com.apple.product-type.application"; 202 | }; 203 | /* End PBXNativeTarget section */ 204 | 205 | /* Begin PBXProject section */ 206 | 423ADBDC2099809D008A3846 /* Project object */ = { 207 | isa = PBXProject; 208 | attributes = { 209 | LastUpgradeCheck = 0920; 210 | ORGANIZATIONNAME = FlyOceanFish; 211 | TargetAttributes = { 212 | 423ADBE32099809D008A3846 = { 213 | CreatedOnToolsVersion = 9.2; 214 | ProvisioningStyle = Automatic; 215 | }; 216 | }; 217 | }; 218 | buildConfigurationList = 423ADBDF2099809D008A3846 /* Build configuration list for PBXProject "TestAVFoundation" */; 219 | compatibilityVersion = "Xcode 8.0"; 220 | developmentRegion = en; 221 | hasScannedForEncodings = 0; 222 | knownRegions = ( 223 | en, 224 | Base, 225 | ); 226 | mainGroup = 423ADBDB2099809C008A3846; 227 | productRefGroup = 423ADBE52099809D008A3846 /* Products */; 228 | projectDirPath = ""; 229 | projectRoot = ""; 230 | targets = ( 231 | 423ADBE32099809D008A3846 /* TestAVFoundation */, 232 | ); 233 | }; 234 | /* End PBXProject section */ 235 | 236 | /* Begin PBXResourcesBuildPhase section */ 237 | 423ADBE22099809D008A3846 /* Resources */ = { 238 | isa = PBXResourcesBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | 4274FAE7209AA3A300D76153 /* 宿命者.mp3 in Resources */, 242 | 4274FAEB209AAFA200D76153 /* empty.png in Resources */, 243 | 423ADBF42099809E008A3846 /* LaunchScreen.storyboard in Resources */, 244 | 4211763E209BEDA10022884E /* test.aac in Resources */, 245 | 42A5D14E20A0225A00566691 /* video.mp4 in Resources */, 246 | 42A5D15220A130EA00566691 /* video2.mp4 in Resources */, 247 | 423ADBF12099809E008A3846 /* Assets.xcassets in Resources */, 248 | 423ADBEF2099809E008A3846 /* Main.storyboard in Resources */, 249 | 423ADBFF2099A886008A3846 /* 女声.mp3 in Resources */, 250 | 423ADC022099A9EE008A3846 /* 男声.mp3 in Resources */, 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | /* End PBXResourcesBuildPhase section */ 255 | 256 | /* Begin PBXSourcesBuildPhase section */ 257 | 423ADBE02099809D008A3846 /* Sources */ = { 258 | isa = PBXSourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | 42A734CE20F597BE0079E862 /* FOFMoviePlayer.m in Sources */, 262 | 42A734D720F5E99C0079E862 /* Line.m in Sources */, 263 | 4276A01A20F8337600000DEE /* VideoPlayerViewController.m in Sources */, 264 | 42A734CB20F596270079E862 /* VideoEditViewController.m in Sources */, 265 | 422E489920C91EB700455D77 /* ConvertUtil.m in Sources */, 266 | 423ADBEC2099809D008A3846 /* ViewController.m in Sources */, 267 | 423ADBF72099809E008A3846 /* main.m in Sources */, 268 | 42A5D15C20A3E23800566691 /* TestMoviePlayerViewController.m in Sources */, 269 | 42A734D120F5D2EF0079E862 /* VideoPieces.m in Sources */, 270 | 42A5D15820A3DE0E00566691 /* FOFMoviePlayerView.m in Sources */, 271 | 423ADBE92099809D008A3846 /* AppDelegate.m in Sources */, 272 | 4276A01D20F8339E00000DEE /* VideoViewController.m in Sources */, 273 | 42A734D420F5D8940079E862 /* Haft.m in Sources */, 274 | ); 275 | runOnlyForDeploymentPostprocessing = 0; 276 | }; 277 | /* End PBXSourcesBuildPhase section */ 278 | 279 | /* Begin PBXVariantGroup section */ 280 | 423ADBED2099809E008A3846 /* Main.storyboard */ = { 281 | isa = PBXVariantGroup; 282 | children = ( 283 | 423ADBEE2099809E008A3846 /* Base */, 284 | ); 285 | name = Main.storyboard; 286 | sourceTree = ""; 287 | }; 288 | 423ADBF22099809E008A3846 /* LaunchScreen.storyboard */ = { 289 | isa = PBXVariantGroup; 290 | children = ( 291 | 423ADBF32099809E008A3846 /* Base */, 292 | ); 293 | name = LaunchScreen.storyboard; 294 | sourceTree = ""; 295 | }; 296 | /* End PBXVariantGroup section */ 297 | 298 | /* Begin XCBuildConfiguration section */ 299 | 423ADBF82099809E008A3846 /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ALWAYS_SEARCH_USER_PATHS = NO; 303 | CLANG_ANALYZER_NONNULL = YES; 304 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 305 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 306 | CLANG_CXX_LIBRARY = "libc++"; 307 | CLANG_ENABLE_MODULES = YES; 308 | CLANG_ENABLE_OBJC_ARC = YES; 309 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 310 | CLANG_WARN_BOOL_CONVERSION = YES; 311 | CLANG_WARN_COMMA = YES; 312 | CLANG_WARN_CONSTANT_CONVERSION = YES; 313 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 314 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 315 | CLANG_WARN_EMPTY_BODY = YES; 316 | CLANG_WARN_ENUM_CONVERSION = YES; 317 | CLANG_WARN_INFINITE_RECURSION = YES; 318 | CLANG_WARN_INT_CONVERSION = YES; 319 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 320 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 321 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 322 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 323 | CLANG_WARN_STRICT_PROTOTYPES = YES; 324 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 325 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 326 | CLANG_WARN_UNREACHABLE_CODE = YES; 327 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 328 | CODE_SIGN_IDENTITY = "iPhone Developer"; 329 | COPY_PHASE_STRIP = NO; 330 | DEBUG_INFORMATION_FORMAT = dwarf; 331 | ENABLE_STRICT_OBJC_MSGSEND = YES; 332 | ENABLE_TESTABILITY = YES; 333 | GCC_C_LANGUAGE_STANDARD = gnu11; 334 | GCC_DYNAMIC_NO_PIC = NO; 335 | GCC_NO_COMMON_BLOCKS = YES; 336 | GCC_OPTIMIZATION_LEVEL = 0; 337 | GCC_PREPROCESSOR_DEFINITIONS = ( 338 | "DEBUG=1", 339 | "$(inherited)", 340 | ); 341 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 342 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 343 | GCC_WARN_UNDECLARED_SELECTOR = YES; 344 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 345 | GCC_WARN_UNUSED_FUNCTION = YES; 346 | GCC_WARN_UNUSED_VARIABLE = YES; 347 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 348 | MTL_ENABLE_DEBUG_INFO = YES; 349 | ONLY_ACTIVE_ARCH = YES; 350 | SDKROOT = iphoneos; 351 | }; 352 | name = Debug; 353 | }; 354 | 423ADBF92099809E008A3846 /* Release */ = { 355 | isa = XCBuildConfiguration; 356 | buildSettings = { 357 | ALWAYS_SEARCH_USER_PATHS = NO; 358 | CLANG_ANALYZER_NONNULL = YES; 359 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 360 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 361 | CLANG_CXX_LIBRARY = "libc++"; 362 | CLANG_ENABLE_MODULES = YES; 363 | CLANG_ENABLE_OBJC_ARC = YES; 364 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 365 | CLANG_WARN_BOOL_CONVERSION = YES; 366 | CLANG_WARN_COMMA = YES; 367 | CLANG_WARN_CONSTANT_CONVERSION = YES; 368 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 369 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 370 | CLANG_WARN_EMPTY_BODY = YES; 371 | CLANG_WARN_ENUM_CONVERSION = YES; 372 | CLANG_WARN_INFINITE_RECURSION = YES; 373 | CLANG_WARN_INT_CONVERSION = YES; 374 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 375 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 376 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 377 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 378 | CLANG_WARN_STRICT_PROTOTYPES = YES; 379 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 380 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 381 | CLANG_WARN_UNREACHABLE_CODE = YES; 382 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 383 | CODE_SIGN_IDENTITY = "iPhone Developer"; 384 | COPY_PHASE_STRIP = NO; 385 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 386 | ENABLE_NS_ASSERTIONS = NO; 387 | ENABLE_STRICT_OBJC_MSGSEND = YES; 388 | GCC_C_LANGUAGE_STANDARD = gnu11; 389 | GCC_NO_COMMON_BLOCKS = YES; 390 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 391 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 392 | GCC_WARN_UNDECLARED_SELECTOR = YES; 393 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 394 | GCC_WARN_UNUSED_FUNCTION = YES; 395 | GCC_WARN_UNUSED_VARIABLE = YES; 396 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 397 | MTL_ENABLE_DEBUG_INFO = NO; 398 | SDKROOT = iphoneos; 399 | VALIDATE_PRODUCT = YES; 400 | }; 401 | name = Release; 402 | }; 403 | 423ADBFB2099809E008A3846 /* Debug */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 407 | CODE_SIGN_IDENTITY = "iPhone Developer"; 408 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 409 | CODE_SIGN_STYLE = Automatic; 410 | DEVELOPMENT_TEAM = EC23THMNG7; 411 | INFOPLIST_FILE = TestAVFoundation/Info.plist; 412 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 413 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 414 | LIBRARY_SEARCH_PATHS = ( 415 | "$(inherited)", 416 | "$(PROJECT_DIR)/TestAVFoundation/lame", 417 | ); 418 | PRODUCT_BUNDLE_IDENTIFIER = com.fof.TestAVFoundation3; 419 | PRODUCT_NAME = "$(TARGET_NAME)"; 420 | PROVISIONING_PROFILE_SPECIFIER = ""; 421 | TARGETED_DEVICE_FAMILY = 1; 422 | }; 423 | name = Debug; 424 | }; 425 | 423ADBFC2099809E008A3846 /* Release */ = { 426 | isa = XCBuildConfiguration; 427 | buildSettings = { 428 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 429 | CODE_SIGN_IDENTITY = "iPhone Developer"; 430 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 431 | CODE_SIGN_STYLE = Automatic; 432 | DEVELOPMENT_TEAM = EC23THMNG7; 433 | INFOPLIST_FILE = TestAVFoundation/Info.plist; 434 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 435 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 436 | LIBRARY_SEARCH_PATHS = ( 437 | "$(inherited)", 438 | "$(PROJECT_DIR)/TestAVFoundation/lame", 439 | ); 440 | PRODUCT_BUNDLE_IDENTIFIER = com.fof.TestAVFoundation3; 441 | PRODUCT_NAME = "$(TARGET_NAME)"; 442 | PROVISIONING_PROFILE_SPECIFIER = ""; 443 | TARGETED_DEVICE_FAMILY = 1; 444 | }; 445 | name = Release; 446 | }; 447 | /* End XCBuildConfiguration section */ 448 | 449 | /* Begin XCConfigurationList section */ 450 | 423ADBDF2099809D008A3846 /* Build configuration list for PBXProject "TestAVFoundation" */ = { 451 | isa = XCConfigurationList; 452 | buildConfigurations = ( 453 | 423ADBF82099809E008A3846 /* Debug */, 454 | 423ADBF92099809E008A3846 /* Release */, 455 | ); 456 | defaultConfigurationIsVisible = 0; 457 | defaultConfigurationName = Release; 458 | }; 459 | 423ADBFA2099809E008A3846 /* Build configuration list for PBXNativeTarget "TestAVFoundation" */ = { 460 | isa = XCConfigurationList; 461 | buildConfigurations = ( 462 | 423ADBFB2099809E008A3846 /* Debug */, 463 | 423ADBFC2099809E008A3846 /* Release */, 464 | ); 465 | defaultConfigurationIsVisible = 0; 466 | defaultConfigurationName = Release; 467 | }; 468 | /* End XCConfigurationList section */ 469 | }; 470 | rootObject = 423ADBDC2099809D008A3846 /* Project object */; 471 | } 472 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/2. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/2. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // 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. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/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 | } -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/dot.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "点.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/dot.imageset/点.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/Assets.xcassets/dot.imageset/点.png -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/icon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "Icon120@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/icon.imageset/Icon120@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/Assets.xcassets/icon.imageset/Icon120@2x.png -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/pause.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "暂停.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/pause.imageset/暂停.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/Assets.xcassets/pause.imageset/暂停.png -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/play.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "播放.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/Assets.xcassets/play.imageset/播放.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/Assets.xcassets/play.imageset/播放.png -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/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 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/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 | 32 | 40 | 48 | 56 | 64 | 72 | 80 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 141 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 231 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/ConvertUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // ConvertUtil.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/6/7. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ConvertUtil : NSObject 12 | 13 | +(void)cafFile:(NSString *)cafFilePath toMp3File:(NSString* )mp3FilePath; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/ConvertUtil.m: -------------------------------------------------------------------------------- 1 | // 2 | // ConvertUtil.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/6/7. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "ConvertUtil.h" 10 | #import "lame.h" 11 | 12 | @implementation ConvertUtil 13 | +(void)cafFile:(NSString *)cafFilePath toMp3File:(NSString* )mp3FilePath{ 14 | @try { 15 | 16 | int read, write; 17 | 18 | FILE *pcm = fopen([cafFilePath cStringUsingEncoding:1], "rb"); 19 | fseek(pcm, 4*1024, SEEK_CUR);//去除多余的头部,不然会有咔嚓的一声噪音 20 | FILE *mp3 = fopen([mp3FilePath cStringUsingEncoding:1], "wb"); 21 | 22 | const int PCM_SIZE = 8192; 23 | const int MP3_SIZE = 8192; 24 | short int pcm_buffer[PCM_SIZE*2]; 25 | unsigned char mp3_buffer[MP3_SIZE]; 26 | 27 | lame_t lame = lame_init(); 28 | lame_set_num_channels(lame, 2);//设置1为单通道,默认为2双通道 29 | lame_set_in_samplerate(lame, 8000.0);//11025.0 30 | // lame_set_VBR(lame, vbr_default); 31 | lame_set_brate(lame, 16); 32 | lame_set_mode(lame, 3); 33 | lame_set_quality(lame, 2); /* 2=high 5 = medium 7=low 音质*/ 34 | lame_init_params(lame); 35 | 36 | do{ 37 | read = fread(pcm_buffer, 2*sizeof(short int), PCM_SIZE, pcm); 38 | if (read == 0) { 39 | write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE); 40 | }else{ 41 | write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE); 42 | } 43 | 44 | fwrite(mp3_buffer, write, 1, mp3); 45 | 46 | 47 | }while (read!=0); 48 | 49 | lame_close(lame); 50 | fclose(mp3); 51 | fclose(pcm); 52 | NSLog(@"convert to mp3 succ %@",mp3FilePath); 53 | } 54 | @catch (NSException *exception) { 55 | NSLog(@"%@",[exception description]); 56 | } 57 | } 58 | @end 59 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/FOFMoviePlayerView/FOFMoviePlayerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // FOFMoviePlayer.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/10. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface FOFMoviePlayerView : UIView 13 | 14 | @property(nonatomic,strong)NSURL *url; 15 | 16 | @property(nonatomic,strong)AVPlayer *player; 17 | @property(nonatomic,strong)AVPlayerLayer *playerLayer; 18 | @property(nonatomic,strong)AVPlayerItem *playItem; 19 | 20 | - (instancetype)initWithURL:(NSURL *)url; 21 | @end 22 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/FOFMoviePlayerView/FOFMoviePlayerView.m: -------------------------------------------------------------------------------- 1 | // 2 | // FOFMoviePlayer.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/10. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "FOFMoviePlayerView.h" 10 | 11 | @interface FOFMoviePlayerView() 12 | { 13 | UIView *_indicatorView; 14 | AVPlayerLooper *_playerLooper; 15 | } 16 | 17 | @property (nonatomic,assign) CMTime duration; 18 | @property (nonatomic,assign) BOOL canKeepUp; 19 | 20 | @property (strong, nonatomic) UIButton *btn; 21 | @property (strong, nonatomic) UILabel *mLabeStart; 22 | @property (strong, nonatomic) UILabel *mLabelTimeLeft; 23 | @property (strong, nonatomic) UISlider *mlider; 24 | @property (strong, nonatomic) UIProgressView *mprogressView; 25 | 26 | @property (strong, nonatomic) UIView *mViewProgress; 27 | @property (strong, nonatomic) UIActivityIndicatorView *indicator; 28 | @property (strong, nonatomic) UISegmentedControl *mSegmentedControl; 29 | @end 30 | @implementation FOFMoviePlayerView 31 | 32 | - (instancetype)initWithURL:(NSURL *)url{ 33 | self = [super init]; 34 | if (self) { 35 | [self initViews]; 36 | self.url = url; 37 | } 38 | return self; 39 | } 40 | -(void)layoutSubviews{ 41 | [super layoutSubviews]; 42 | self.playerLayer.frame = CGRectMake(0, 0,CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)-14); 43 | [_btn addTarget:self action:@selector(actionPlayPause:) forControlEvents:UIControlEventTouchUpInside]; 44 | _btn.frame = CGRectMake(CGRectGetWidth(self.playerLayer.bounds)/2-24,CGRectGetHeight(self.playerLayer.bounds)/2-24, 48, 48); 45 | [self layoutIndicatorSubviews]; 46 | } 47 | -(void)awakeFromNib{ 48 | [super awakeFromNib]; 49 | [self initViews]; 50 | } 51 | -(void)setUrl:(NSURL *)url{ 52 | _url = url; 53 | [self.player replaceCurrentItemWithPlayerItem:self.playItem]; 54 | } 55 | 56 | -(void)initViews{ 57 | [self initIndicatorView]; 58 | self.userInteractionEnabled = YES; 59 | [self.mlider setThumbImage:[UIImage imageNamed:@"dot"] forState:UIControlStateNormal]; 60 | [self.mlider addObserver:self forKeyPath:@"tracking" options:NSKeyValueObservingOptionNew context:nil]; 61 | 62 | self.player = [[AVPlayer alloc] init]; 63 | self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; 64 | self.playerLayer.backgroundColor = [UIColor grayColor].CGColor; 65 | self.playerLayer.videoGravity = AVLayerVideoGravityResize; 66 | [self.layer addSublayer:self.playerLayer]; 67 | 68 | __weak typeof(self) this = self; 69 | [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 12) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) { 70 | float currentTime = CMTimeGetSeconds(time); 71 | this.mlider.value = currentTime; 72 | this.mLabeStart.text = [this getMMSSFromSS:(int)currentTime]; 73 | this.mLabelTimeLeft.text = [this getMMSSFromSS:(int)(CMTimeGetSeconds(this.duration)-currentTime)]; 74 | if (fabs(CMTimeGetSeconds(this.duration)-currentTime)<=0.01) { 75 | [this replay]; 76 | } 77 | }]; 78 | 79 | 80 | _btn = [UIButton buttonWithType:UIButtonTypeCustom]; 81 | [_btn setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal]; 82 | [_btn setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateSelected]; 83 | [self addSubview:_btn]; 84 | 85 | self.indicator = [[UIActivityIndicatorView alloc] initWithFrame:_btn.frame]; 86 | self.indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; 87 | self.indicator.color = [UIColor colorWithRed:23/255.0 green:130/255.0 blue:210/255.9 alpha:1]; 88 | self.indicator.hidden = YES; 89 | [self addSubview:self.indicator]; 90 | 91 | [self.mSegmentedControl addTarget:self action:@selector(segmentedIndexChanged:) forControlEvents:UIControlEventValueChanged]; 92 | } 93 | - (void)initIndicatorView{ 94 | _indicatorView = [[UIView alloc] initWithFrame:CGRectZero]; 95 | _mLabeStart = [[UILabel alloc] initWithFrame:CGRectZero]; 96 | _mLabeStart.font = [UIFont systemFontOfSize:11]; 97 | _mLabeStart.text = @"00:00:00"; 98 | 99 | _mLabelTimeLeft = [[UILabel alloc] initWithFrame:CGRectZero]; 100 | _mLabelTimeLeft.font = [UIFont systemFontOfSize:11]; 101 | 102 | _mlider = [[UISlider alloc] initWithFrame:CGRectZero]; 103 | _mlider.minimumTrackTintColor = [UIColor blueColor]; 104 | _mlider.backgroundColor = [UIColor clearColor]; 105 | _mlider.maximumTrackTintColor = [UIColor clearColor]; 106 | 107 | _mprogressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; 108 | _mprogressView.progressTintColor = [UIColor colorWithWhite:0.5 alpha:1]; 109 | 110 | [_indicatorView addSubview:_mLabeStart]; 111 | [_indicatorView addSubview:_mLabelTimeLeft]; 112 | [_indicatorView addSubview:_mprogressView]; 113 | [_indicatorView addSubview:_mlider]; 114 | [self addSubview:_indicatorView]; 115 | 116 | } 117 | - (void)layoutIndicatorSubviews{ 118 | _indicatorView.frame = CGRectMake(0, CGRectGetHeight(self.playerLayer.bounds), CGRectGetWidth(self.bounds), 15); 119 | _mLabeStart.frame = CGRectMake(0, 0, 49, 15); 120 | _mLabelTimeLeft.frame = CGRectMake(CGRectGetWidth(self.bounds)-49, 0, 49, 15); 121 | float _mliderX = _mLabeStart.frame.origin.x+CGRectGetWidth(_mLabeStart.bounds)+8; 122 | _mlider.frame = CGRectMake(_mliderX, 0, CGRectGetWidth(self.bounds)-_mliderX-CGRectGetWidth(_mLabelTimeLeft.bounds)-8, 15); 123 | _mprogressView.frame = CGRectMake(_mlider.frame.origin.x+2, (15-2)/2.0, CGRectGetWidth(_mlider.bounds)-8, 2); 124 | } 125 | #pragma mark - Action 126 | -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 127 | UITouch *touch = touches.anyObject; 128 | CGPoint point = [touch locationInView:self]; 129 | CALayer *layer = [self.playerLayer hitTest:point]; 130 | if (layer) { 131 | if (_btn.alpha) { 132 | [self animalHide]; 133 | }else{ 134 | [self animalShow]; 135 | } 136 | } 137 | } 138 | 139 | - (void)actionPlayPause:(UIButton *)sender { 140 | if (sender.selected) { 141 | [self.player pause]; 142 | }else{ 143 | [self.player play]; 144 | [self performSelector:@selector(animalHide) withObject:nil afterDelay:1]; 145 | } 146 | sender.selected = !sender.selected; 147 | } 148 | 149 | - (void)segmentedIndexChanged:(UISegmentedControl *)sender{ 150 | self.player.rate = sender.selectedSegmentIndex+1; 151 | } 152 | 153 | #pragma mark - Observe 154 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ 155 | if ([keyPath isEqualToString:@"status"]) { 156 | AVPlayerItem *item = (AVPlayerItem *)object; 157 | AVPlayerItemStatus status = [[change objectForKey:@"new"] intValue]; // 获取更改后的状态 158 | if (status == AVPlayerItemStatusReadyToPlay) { 159 | _duration = item.duration;//只有在此状态下才能获取,不能在AVPlayerItem初始化后马上获取 160 | self.mLabelTimeLeft.text = [self getMMSSFromSS:(int)CMTimeGetSeconds(_duration)]; 161 | self.mlider.maximumValue = CMTimeGetSeconds(_duration); 162 | self.mlider.minimumValue = 0; 163 | NSLog(@"准备播放"); 164 | } else if (status == AVPlayerItemStatusFailed) { 165 | AVPlayerItem *item = (AVPlayerItem *)object; 166 | NSLog(@"%@",item.error); 167 | NSLog(@"AVPlayerStatusFailed"); 168 | } else { 169 | NSLog(@"%@",item.error); 170 | NSLog(@"AVPlayerStatusUnknown"); 171 | } 172 | }else if ([keyPath isEqualToString:@"tracking"]){ 173 | NSInteger status = [change[@"new"] integerValue]; 174 | float slideValue = self.mlider.value; 175 | [self.player seekToTime:CMTimeMake(slideValue*_duration.timescale, _duration.timescale) completionHandler:^(BOOL finished) { 176 | 177 | }]; 178 | self.mLabeStart.text = [self getMMSSFromSS:(int)slideValue]; 179 | self.mLabelTimeLeft.text = [self getMMSSFromSS:(int)(CMTimeGetSeconds(_duration)-slideValue)]; 180 | 181 | if (status) {//正在拖动 182 | [self.player pause]; 183 | }else{//停止拖动 184 | if (_btn.selected) { 185 | [self.player play]; 186 | } 187 | 188 | } 189 | }else if ([keyPath isEqualToString:@"loadedTimeRanges"]){ 190 | NSArray *array = _playItem.loadedTimeRanges; 191 | CMTimeRange timeRange = [array.firstObject CMTimeRangeValue];//本次缓冲时间范围 192 | float startSeconds = CMTimeGetSeconds(timeRange.start); 193 | float durationSeconds = CMTimeGetSeconds(timeRange.duration); 194 | NSTimeInterval totalBuffer = startSeconds + durationSeconds;//缓冲总长度 195 | self.mprogressView.progress = totalBuffer/CMTimeGetSeconds(_duration); 196 | NSLog(@"当前缓冲时间:%f",totalBuffer); 197 | }else if ([keyPath isEqualToString:@"playbackBufferEmpty"]){ 198 | NSLog(@"缓存不够,不能播放!"); 199 | }else if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"]){ 200 | if ([change[@"new"] boolValue]) { 201 | if (!self.indicator.hidden) { 202 | self.indicator.hidden = YES; 203 | [self.indicator stopAnimating]; 204 | } 205 | self.canKeepUp = YES; 206 | NSLog(@"缓存的足够多可以播放了!"); 207 | }else{ 208 | self.canKeepUp = NO; 209 | } 210 | } 211 | 212 | } 213 | 214 | -(AVPlayerItem *)playItem{ 215 | _playItem = [[AVPlayerItem alloc] initWithURL:_url]; 216 | //监听播放器的状态,准备好播放、失败、未知错误 217 | [_playItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; 218 | // 监听缓存的时间 219 | [_playItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil]; 220 | // 监听获取当缓存不够,视频加载不出来的情况: 221 | [_playItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil]; 222 | // 用于监听缓存足够播放的状态 223 | [_playItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil]; 224 | 225 | // if ([_playItem canPlayFastForward]) {//只有是true的时候,才能支持2倍速度以上 226 | // [self.mSegmentedControl insertSegmentWithTitle:@"X3" atIndex:2 animated:NO]; 227 | // [self.mSegmentedControl insertSegmentWithTitle:@"X4" atIndex:3 animated:NO]; 228 | // } 229 | return _playItem; 230 | } 231 | -(NSString *)getMMSSFromSS:(NSInteger)seconds{ 232 | NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600]; 233 | NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60]; 234 | NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60]; 235 | NSString *format_time = [NSString stringWithFormat:@"%@:%@:%@",str_hour,str_minute,str_second]; 236 | return format_time; 237 | } 238 | #pragma mark - Private 239 | - (void)replay{ 240 | self.btn.selected = NO; 241 | [_player seekToTime:kCMTimeZero]; 242 | [self animalShow]; 243 | } 244 | - (void)animalHide{ 245 | [UIView animateWithDuration:1 animations:^{ 246 | _btn.alpha = 0; 247 | _indicatorView.alpha = 0; 248 | if (!self.canKeepUp) { 249 | self.indicator.hidden = NO; 250 | [self.indicator startAnimating]; 251 | } 252 | }]; 253 | } 254 | - (void)animalShow{ 255 | [UIView animateWithDuration:1 animations:^{ 256 | if (self.indicator.hidden) { 257 | _btn.alpha = 1; 258 | } 259 | _indicatorView.alpha = 1; 260 | }]; 261 | } 262 | -(void)dealloc{ 263 | // 需要释放一下资源否则会奔溃 264 | [_playItem removeObserver:self forKeyPath:@"status"]; 265 | [_playItem removeObserver:self forKeyPath:@"loadedTimeRanges"]; 266 | [_playItem removeObserver:self forKeyPath:@"playbackBufferEmpty"]; 267 | [_playItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"]; 268 | [_player.currentItem cancelPendingSeeks]; 269 | [_player.currentItem.asset cancelLoading]; 270 | NSLog(@"顺利销毁"); 271 | } 272 | @end 273 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/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 | NSAppTransportSecurity 24 | 25 | NSAllowsArbitraryLoads 26 | 27 | 28 | NSMicrophoneUsageDescription 29 | 请允许使用录音 30 | UIBackgroundModes 31 | 32 | audio 33 | 34 | UILaunchStoryboardName 35 | LaunchScreen 36 | UIMainStoryboardFile 37 | Main 38 | UIRequiredDeviceCapabilities 39 | 40 | armv7 41 | 42 | UISupportedInterfaceOrientations 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | UISupportedInterfaceOrientations~ipad 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationPortraitUpsideDown 52 | UIInterfaceOrientationLandscapeLeft 53 | UIInterfaceOrientationLandscapeRight 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/TestMoviePlayerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestMoviePlayerViewController.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/10. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TestMoviePlayerViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/TestMoviePlayerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestMoviePlayerViewController.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/10. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "TestMoviePlayerViewController.h" 10 | #import "FOFMoviePlayerView.h" 11 | 12 | @interface TestMoviePlayerViewController () 13 | 14 | @property (weak, nonatomic) IBOutlet FOFMoviePlayerView *mMoviePlayer; 15 | @end 16 | 17 | @implementation TestMoviePlayerViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | self.edgesForExtendedLayout = UIRectEdgeNone; 22 | self.mMoviePlayer.url = [NSURL URLWithString:@"http://192.168.9.197:8080/videos/videos.mp4"]; 23 | } 24 | 25 | - (void)didReceiveMemoryWarning { 26 | [super didReceiveMemoryWarning]; 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | /* 31 | #pragma mark - Navigation 32 | 33 | // In a storyboard-based application, you will often want to do a little preparation before navigation 34 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 35 | // Get the new view controller using [segue destinationViewController]. 36 | // Pass the selected object to the new view controller. 37 | } 38 | */ 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/FOFMoviePlayer/FOFMoviePlayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // FOFMoviePlayer.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | typedef void(^BlockStatusReadyPlay)(AVPlayerItem *palyItem); 13 | typedef void(^BlockStatusFailed)(void); 14 | typedef void(^BlockStatusUnknown)(void); 15 | typedef void(^BlockTracking)(NSInteger status); 16 | typedef void(^BlockLoadedTimeRanges)(double progress); 17 | typedef void(^BlockPlaybackLikelyToKeepUp)(BOOL keepUp); 18 | typedef void(^BlockPlayToEndTime)(void); 19 | 20 | @interface FOFMoviePlayer : NSObject 21 | @property(nonatomic,copy)BlockStatusReadyPlay blockStatusReadyPlay; 22 | @property(nonatomic,copy)BlockStatusFailed blockStatusFailed; 23 | @property(nonatomic,copy)BlockStatusUnknown blockStatusUnknown; 24 | @property(nonatomic,copy)BlockTracking blockTracking; 25 | @property(nonatomic,copy)BlockLoadedTimeRanges blockLoadedTimeRanges; 26 | @property(nonatomic,copy)BlockPlaybackLikelyToKeepUp blockPlaybackLikelyToKeepUp; 27 | @property(nonatomic,copy)BlockPlayToEndTime blockPlayToEndTime; 28 | 29 | @property (nonatomic,assign)CGFloat lastStartSeconds; 30 | 31 | @property(nonatomic,strong,readonly)NSURL *url; 32 | 33 | @property(nonatomic,strong,readonly)AVPlayer *player; 34 | @property(nonatomic,strong,readonly)AVPlayerLayer *playerLayer; 35 | @property(nonatomic,strong,readonly)AVPlayerItem *playItem; 36 | 37 | -(instancetype)initWithFrame:(CGRect)frame url:(NSURL *)url superLayer:(CALayer *)superLayer; 38 | -(instancetype)initWithFrame:(CGRect)frame url:(NSURL *)url superLayer:(CALayer *)superLayer loop:(BOOL)loop; 39 | 40 | - (void)fof_play; 41 | - (void)fof_pause; 42 | @end 43 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/FOFMoviePlayer/FOFMoviePlayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // FOFMoviePlayer.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "FOFMoviePlayer.h" 10 | @interface FOFMoviePlayer() 11 | { 12 | AVPlayerLooper *_playerLooper; 13 | AVPlayerItem *_playItem; 14 | BOOL _loop; 15 | } 16 | @property(nonatomic,strong)NSURL *url; 17 | 18 | @property(nonatomic,strong)AVPlayer *player; 19 | @property(nonatomic,strong)AVPlayerLayer *playerLayer; 20 | @property(nonatomic,strong)AVPlayerItem *playItem; 21 | 22 | @property (nonatomic,assign) CMTime duration; 23 | @end 24 | @implementation FOFMoviePlayer 25 | 26 | -(instancetype)initWithFrame:(CGRect)frame url:(NSURL *)url superLayer:(CALayer *)superLayer{ 27 | self = [super init]; 28 | if (self) { 29 | [self initplayers:superLayer]; 30 | _playerLayer.frame = frame; 31 | self.url = url; 32 | } 33 | return self; 34 | } 35 | -(instancetype)initWithFrame:(CGRect)frame url:(NSURL *)url superLayer:(CALayer *)superLayer loop:(BOOL)loop{ 36 | self = [self initWithFrame:frame url:url superLayer:superLayer]; 37 | if (self) { 38 | _loop = loop; 39 | } 40 | return self; 41 | } 42 | - (void)initplayers:(CALayer *)superLayer{ 43 | self.player = [[AVPlayer alloc] init]; 44 | self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; 45 | self.playerLayer.videoGravity = AVLayerVideoGravityResize; 46 | [superLayer addSublayer:self.playerLayer]; 47 | } 48 | - (void)initLoopPlayers:(CALayer *)superLayer{ 49 | self.player = [[AVQueuePlayer alloc] init]; 50 | self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; 51 | self.playerLayer.videoGravity = AVLayerVideoGravityResize; 52 | [superLayer addSublayer:self.playerLayer]; 53 | } 54 | -(void)fof_play{ 55 | [self.player play]; 56 | } 57 | -(void)fof_pause{ 58 | [self.player pause]; 59 | } 60 | 61 | #pragma mark - Observe 62 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ 63 | if ([keyPath isEqualToString:@"status"]) { 64 | AVPlayerItem *item = (AVPlayerItem *)object; 65 | AVPlayerItemStatus status = [[change objectForKey:@"new"] intValue]; // 获取更改后的状态 66 | if (status == AVPlayerItemStatusReadyToPlay) { 67 | _duration = item.duration;//只有在此状态下才能获取,不能在AVPlayerItem初始化后马上获取 68 | NSLog(@"准备播放"); 69 | if (self.blockStatusReadyPlay) { 70 | self.blockStatusReadyPlay(item); 71 | } 72 | } else if (status == AVPlayerItemStatusFailed) { 73 | if (self.blockStatusFailed) { 74 | self.blockStatusFailed(); 75 | } 76 | AVPlayerItem *item = (AVPlayerItem *)object; 77 | NSLog(@"%@",item.error); 78 | NSLog(@"AVPlayerStatusFailed"); 79 | } else { 80 | self.blockStatusUnknown(); 81 | NSLog(@"%@",item.error); 82 | NSLog(@"AVPlayerStatusUnknown"); 83 | } 84 | }else if ([keyPath isEqualToString:@"tracking"]){ 85 | NSInteger status = [change[@"new"] integerValue]; 86 | if (self.blockTracking) { 87 | self.blockTracking(status); 88 | } 89 | if (status) {//正在拖动 90 | [self.player pause]; 91 | }else{//停止拖动 92 | 93 | } 94 | }else if ([keyPath isEqualToString:@"loadedTimeRanges"]){ 95 | NSArray *array = _playItem.loadedTimeRanges; 96 | CMTimeRange timeRange = [array.firstObject CMTimeRangeValue];//本次缓冲时间范围 97 | CGFloat startSeconds = CMTimeGetSeconds(timeRange.start); 98 | CGFloat durationSeconds = CMTimeGetSeconds(timeRange.duration); 99 | NSTimeInterval totalBuffer = startSeconds + durationSeconds;//缓冲总长度 100 | double progress = totalBuffer/CMTimeGetSeconds(_duration); 101 | if (self.blockLoadedTimeRanges) { 102 | self.blockLoadedTimeRanges(progress); 103 | } 104 | NSLog(@"当前缓冲时间:%f",totalBuffer); 105 | }else if ([keyPath isEqualToString:@"playbackBufferEmpty"]){ 106 | NSLog(@"缓存不够,不能播放!"); 107 | }else if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"]){ 108 | if (self.blockPlaybackLikelyToKeepUp) { 109 | self.blockPlaybackLikelyToKeepUp([change[@"new"] boolValue]); 110 | } 111 | } 112 | 113 | } 114 | 115 | -(void)setUrl:(NSURL *)url{ 116 | _url = url; 117 | [self.player replaceCurrentItemWithPlayerItem:self.playItem]; 118 | } 119 | 120 | -(AVPlayerItem *)playItem{ 121 | _playItem = [[AVPlayerItem alloc] initWithURL:_url]; 122 | //监听播放器的状态,准备好播放、失败、未知错误 123 | [_playItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; 124 | // 监听缓存的时间 125 | [_playItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil]; 126 | // 监听获取当缓存不够,视频加载不出来的情况: 127 | [_playItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil]; 128 | // 用于监听缓存足够播放的状态 129 | [_playItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil]; 130 | 131 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(private_playerMovieFinish) name:AVPlayerItemDidPlayToEndTimeNotification object:nil]; 132 | 133 | return _playItem; 134 | } 135 | - (void)private_playerMovieFinish{ 136 | NSLog(@"播放结束"); 137 | if (self.blockPlayToEndTime) { 138 | self.blockPlayToEndTime(); 139 | } 140 | if (_loop) { 141 | [self.player pause]; 142 | CMTime time = CMTimeMake(1, 1); 143 | __weak typeof(self)this = self; 144 | [self.player seekToTime:time completionHandler:^(BOOL finished) { 145 | [this.player play]; 146 | }]; 147 | } 148 | } 149 | -(void)dealloc{ 150 | NSLog(@"-----销毁-----"); 151 | } 152 | @end 153 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/Haft.h: -------------------------------------------------------------------------------- 1 | // 2 | // Haft.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | typedef void(^BlockMove)(CGPoint point); 11 | typedef void(^BlockMoveEnd)(void); 12 | @interface Haft : UIView 13 | @property (nonatomic,copy)BlockMove blockMove; 14 | @property (nonatomic,copy)BlockMoveEnd blockMoveEnd; 15 | /** 16 | 增加左边的相应区域 17 | */ 18 | @property (nonatomic,assign)NSInteger lefEdgeInset; 19 | /** 20 | 增加右边的相应区域 21 | */ 22 | @property (nonatomic,assign)NSInteger rightEdgeInset; 23 | /** 24 | 增加上边的相应区域 25 | */ 26 | @property (nonatomic,assign)NSInteger topEdgeInset; 27 | /** 28 | 增加下边的相应区域 29 | */ 30 | @property (nonatomic,assign)NSInteger bottomEdgeInset; 31 | @end 32 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/Haft.m: -------------------------------------------------------------------------------- 1 | // 2 | // Haft.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "Haft.h" 10 | #import 11 | 12 | @implementation Haft 13 | -(instancetype)initWithFrame:(CGRect)frame{ 14 | self = [super initWithFrame:frame]; 15 | if (self) { 16 | self.userInteractionEnabled = true; 17 | } 18 | return self; 19 | } 20 | 21 | -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{ 22 | CGRect rect = CGRectMake(self.bounds.origin.x-self.lefEdgeInset, self.bounds.origin.y-self.topEdgeInset, CGRectGetWidth(self.bounds)+self.lefEdgeInset+self.rightEdgeInset, CGRectGetHeight(self.bounds)+self.bottomEdgeInset+self.topEdgeInset); 23 | if (CGRectContainsPoint(rect, point)) { 24 | return YES; 25 | } 26 | return NO; 27 | } 28 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 29 | NSLog(@"开始"); 30 | } 31 | -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 32 | NSLog(@"Move"); 33 | UITouch *touch = touches.anyObject; 34 | CGPoint point = [touch locationInView:self.superview]; 35 | CGFloat maxX = CGRectGetWidth(self.superview.bounds)-CGRectGetWidth(self.bounds); 36 | if (point.x>maxX) { 37 | point.x = maxX; 38 | } 39 | if (point.x>=0&&point.x<=(CGRectGetWidth(self.superview.bounds)-CGRectGetWidth(self.bounds))&&self.blockMove) { 40 | self.blockMove(point); 41 | } 42 | } 43 | -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 44 | if (self.blockMoveEnd) { 45 | self.blockMoveEnd(); 46 | } 47 | } 48 | - (void)drawRect:(CGRect)rect { 49 | 50 | CGFloat width = CGRectGetWidth(self.bounds); 51 | CGFloat height = CGRectGetHeight(self.bounds); 52 | CGFloat lineWidth = 1.5; 53 | CGFloat lineHeight = 12; 54 | CGFloat gap = (width-lineWidth*2)/3.0; 55 | CGFloat lineY = (height-lineHeight)/2.0; 56 | 57 | CGContextRef context = UIGraphicsGetCurrentContext(); 58 | CGContextSetLineWidth(context, lineWidth); 59 | CGContextSetStrokeColorWithColor(context, [[UIColor grayColor] colorWithAlphaComponent:0.8].CGColor); 60 | CGContextMoveToPoint(context, gap+lineWidth/2, lineY); 61 | CGContextAddLineToPoint(context, gap+lineWidth/2, lineY+lineHeight); 62 | CGContextStrokePath(context); 63 | 64 | CGContextSetLineWidth(context, lineWidth); 65 | CGContextSetStrokeColorWithColor(context, [[UIColor grayColor] colorWithAlphaComponent:0.8].CGColor); 66 | CGContextMoveToPoint(context, gap*2+lineWidth+lineWidth/2, lineY); 67 | CGContextAddLineToPoint(context, gap*2+lineWidth+lineWidth/2, lineY+lineHeight); 68 | CGContextStrokePath(context); 69 | 70 | } 71 | 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/Line.h: -------------------------------------------------------------------------------- 1 | // 2 | // Line.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Line : UIView 12 | @property (nonatomic,assign)CGPoint beginPoint; 13 | @property (nonatomic,assign)CGPoint endPoint; 14 | @end 15 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/Line.m: -------------------------------------------------------------------------------- 1 | // 2 | // Line.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "Line.h" 10 | #import 11 | 12 | @implementation Line 13 | 14 | -(void)setBeginPoint:(CGPoint)beginPoint{ 15 | _beginPoint = beginPoint; 16 | [self setNeedsDisplay]; 17 | } 18 | -(void)setEndPoint:(CGPoint)endPoint{ 19 | _endPoint = endPoint; 20 | [self setNeedsDisplay]; 21 | } 22 | - (void)drawRect:(CGRect)rect { 23 | CGContextRef context = UIGraphicsGetCurrentContext(); 24 | CGContextSetLineWidth(context, 3); 25 | CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:0.9 alpha:1].CGColor); 26 | CGContextMoveToPoint(context, self.beginPoint.x, self.beginPoint.y); 27 | CGContextAddLineToPoint(context, self.endPoint.x, self.endPoint.y); 28 | CGContextStrokePath(context); 29 | } 30 | 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/VideoEditViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // VideoEditViewController.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VideoEditViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/VideoEditViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // VideoEditViewController.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "VideoEditViewController.h" 10 | #import "FOFMoviePlayer.h" 11 | #import "VideoPieces.h" 12 | 13 | @interface VideoEditViewController (){ 14 | UIImageView *iv; 15 | } 16 | @property (nonatomic,strong)FOFMoviePlayer *moviePlayer; 17 | @property (nonatomic,strong)VideoPieces *videoPieces; 18 | @property (nonatomic,assign)CGFloat totalSeconds; 19 | @property (nonatomic,assign)CGFloat lastStartSeconds; 20 | @property (nonatomic,assign)CGFloat lastEndSeconds; 21 | @property (nonatomic,assign)BOOL seeking; 22 | @property (nonatomic,strong)id timeObserverToken; 23 | @end 24 | 25 | @implementation VideoEditViewController 26 | 27 | - (void)viewDidLoad { 28 | [super viewDidLoad]; 29 | self.edgesForExtendedLayout = UIRectEdgeNone; 30 | self.view.backgroundColor = [UIColor blackColor]; 31 | NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]; 32 | self.lastEndSeconds = NAN; 33 | self.moviePlayer = [[FOFMoviePlayer alloc] initWithFrame:CGRectMake(10, 20,400, 300) url:[NSURL fileURLWithPath:path] superLayer:self.view.layer]; 34 | __weak typeof(self) this = self; 35 | [self.moviePlayer setBlockStatusReadyPlay:^(AVPlayerItem *playItem){ 36 | [this.moviePlayer fof_play]; 37 | this.totalSeconds = CMTimeGetSeconds(playItem.duration); 38 | }]; 39 | 40 | [self.moviePlayer setBlockPlayToEndTime:^{ 41 | [this private_replayAtBeginTime:this.lastStartSeconds]; 42 | }]; 43 | // 如果对于时间精度要求比较小,可以适当增加timescale的值。这里是1.0/10 = 0.1; 44 | self.timeObserverToken = [self.moviePlayer.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 10) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) { 45 | if (!this.seeking) { 46 | if (fabs(CMTimeGetSeconds(time)-this.lastEndSeconds)<=0.2) { 47 | [this private_replayAtBeginTime:this.lastStartSeconds]; 48 | } 49 | } 50 | }]; 51 | CGFloat width = CGRectGetWidth(self.view.bounds); 52 | _videoPieces = [[VideoPieces alloc] initWithFrame:CGRectMake(30, 350, width-60, 80)]; 53 | [_videoPieces setBlockSeekOffLeft:^(CGFloat offX) { 54 | this.seeking = true; 55 | [this.moviePlayer fof_pause]; 56 | this.lastStartSeconds = this.totalSeconds*offX/CGRectGetWidth(this.videoPieces.bounds); 57 | [this.moviePlayer.player seekToTime:CMTimeMakeWithSeconds(this.lastStartSeconds, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero]; 58 | }]; 59 | [_videoPieces setBlockSeekOffRight:^(CGFloat offX) { 60 | this.seeking = true; 61 | [this.moviePlayer fof_pause]; 62 | this.lastEndSeconds = this.totalSeconds*offX/CGRectGetWidth(this.videoPieces.bounds); 63 | [this.moviePlayer.player seekToTime:CMTimeMakeWithSeconds(this.lastEndSeconds, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero]; 64 | }]; 65 | 66 | [_videoPieces setBlockMoveEnd:^{ 67 | NSLog(@"滑动结束"); 68 | if (this.seeking) { 69 | this.seeking = false; 70 | [this private_replayAtBeginTime:this.lastStartSeconds]; 71 | } 72 | }]; 73 | _videoPieces.backgroundColor = [UIColor clearColor]; 74 | [self.view addSubview:_videoPieces]; 75 | CGFloat widthIV = (CGRectGetWidth(_videoPieces.frame))/10.0; 76 | CGFloat heightIV = CGRectGetHeight(_videoPieces.frame); 77 | [self getVideoThumbnail:path count:10 splitCompleteBlock:^(BOOL success, NSMutableArray *splitimgs) { 78 | for (int i = 0; i 10 | #import "Haft.h" 11 | 12 | typedef void(^BlockSeekOff)(CGFloat offX); 13 | 14 | @interface VideoPieces : UIView 15 | @property (nonatomic,copy)BlockSeekOff blockSeekOffLeft; 16 | @property (nonatomic,copy)BlockSeekOff blockSeekOffRight; 17 | @property (nonatomic,copy)BlockMoveEnd blockMoveEnd; 18 | @property (nonatomic,assign)CGFloat minGap; 19 | @end 20 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoEdit/VideoPieces.m: -------------------------------------------------------------------------------- 1 | // 2 | // VideoPieces.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/11. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "VideoPieces.h" 10 | 11 | #import "Line.h" 12 | 13 | @interface VideoPieces() 14 | { 15 | CGPoint _beginPoint; 16 | } 17 | @property(nonatomic,strong) Haft *leftHaft; 18 | @property(nonatomic,strong) Haft *rightHaft; 19 | @property(nonatomic,strong) Line *topLine; 20 | @property(nonatomic,strong) Line *bottomLine; 21 | @property(nonatomic,strong) UIView *leftMaskView; 22 | @property(nonatomic,strong) UIView *rightMaskView; 23 | @end 24 | @implementation VideoPieces 25 | -(instancetype)initWithFrame:(CGRect)frame{ 26 | self = [super initWithFrame:frame]; 27 | if (self) { 28 | [self initSubViews:frame]; 29 | } 30 | return self; 31 | } 32 | - (void)initSubViews:(CGRect)frame{ 33 | CGFloat height = CGRectGetHeight(frame); 34 | CGFloat width = CGRectGetWidth(frame); 35 | _minGap = 30; 36 | CGFloat widthHaft = 10; 37 | CGFloat heightLine = 3; 38 | _leftHaft = [[Haft alloc] initWithFrame:CGRectMake(0, 0, widthHaft, height)]; 39 | _leftHaft.alpha = 0.8; 40 | _leftHaft.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1]; 41 | _leftHaft.rightEdgeInset = 20; 42 | _leftHaft.lefEdgeInset = 5; 43 | __weak typeof(self) this = self; 44 | [_leftHaft setBlockMove:^(CGPoint point) { 45 | CGFloat maxX = this.rightHaft.frame.origin.x-this.minGap; 46 | if (point.x=minX) { 69 | this.topLine.endPoint = CGPointMake(point.x-widthHaft, heightLine/2.0); 70 | this.bottomLine.endPoint = CGPointMake(point.x-widthHaft, heightLine/2.0); 71 | this.rightHaft.frame = CGRectMake(point.x, 0, widthHaft, height); 72 | this.rightMaskView.frame = CGRectMake(point.x+widthHaft, 0, width-point.x-widthHaft, height); 73 | if (this.blockSeekOffRight) { 74 | this.blockSeekOffRight(point.x); 75 | } 76 | } 77 | }]; 78 | [_rightHaft setBlockMoveEnd:^{ 79 | if (this.blockMoveEnd) { 80 | this.blockMoveEnd(); 81 | } 82 | }]; 83 | _topLine = [[Line alloc] init]; 84 | _topLine.alpha = 0.8; 85 | _topLine.frame = CGRectMake(widthHaft, 0, width-2*widthHaft, heightLine); 86 | _topLine.beginPoint = CGPointMake(0, heightLine/2.0); 87 | _topLine.endPoint = CGPointMake(CGRectGetWidth(_topLine.bounds), heightLine/2.0); 88 | _topLine.backgroundColor = [UIColor clearColor]; 89 | [self addSubview:_topLine]; 90 | 91 | _bottomLine = [[Line alloc] init]; 92 | _bottomLine.alpha = 0.8; 93 | _bottomLine.frame = CGRectMake(widthHaft, height-heightLine, width-2*widthHaft, heightLine); 94 | _bottomLine.beginPoint = CGPointMake(0, heightLine/2.0); 95 | _bottomLine.endPoint = CGPointMake(CGRectGetWidth(_bottomLine.bounds), heightLine/2.0); 96 | _bottomLine.backgroundColor = [UIColor clearColor]; 97 | [self addSubview:_bottomLine]; 98 | 99 | [self addSubview:_leftHaft]; 100 | [self addSubview:_rightHaft]; 101 | 102 | self.leftMaskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, height)]; 103 | self.leftMaskView.backgroundColor = [UIColor grayColor]; 104 | self.leftMaskView.alpha = 0.8; 105 | [self addSubview:self.leftMaskView]; 106 | self.rightMaskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, height)]; 107 | self.rightMaskView.backgroundColor = [UIColor grayColor]; 108 | self.rightMaskView.alpha = 0.8; 109 | [self addSubview:self.rightMaskView]; 110 | } 111 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 112 | UITouch *touch = touches.anyObject; 113 | _beginPoint = [touch locationInView:self]; 114 | 115 | } 116 | /* 117 | // Only override drawRect: if you perform custom drawing. 118 | // An empty implementation adversely affects performance during animation. 119 | - (void)drawRect:(CGRect)rect { 120 | // Drawing code 121 | } 122 | */ 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoPlayerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // VideoViewController.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/7. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VideoPlayerViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoPlayerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // VideoViewController.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/7. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | 10 | /* 11 | AVQueuePlayer可以很好连续播放两个视频,播放A的时候会提前预加载B,甚至C,但是AVQueuePlayer不是播放列表。可以实现循环播放功能 12 | AVPlayerLooper 实现循环播放功能代码更加简洁 13 | */ 14 | #import "VideoPlayerViewController.h" 15 | #import 16 | 17 | @interface VideoPlayerViewController () 18 | { 19 | 20 | UIButton *_btn; 21 | AVPlayerItem *_playItem; 22 | AVPlayerLooper *_playerLooper; 23 | NSString *_path; 24 | } 25 | @property(nonatomic,strong)AVPlayer *player; 26 | @property(nonatomic,strong)AVPlayerLayer *playerLayer; 27 | @property (nonatomic,assign) CMTime duration; 28 | @property (nonatomic,assign) BOOL canKeepUp; 29 | 30 | @property (weak, nonatomic) IBOutlet UILabel *mLabeStart; 31 | @property (weak, nonatomic) IBOutlet UILabel *mLabelTimeLeft; 32 | @property (weak, nonatomic) IBOutlet UISlider *mlider; 33 | @property (weak, nonatomic) IBOutlet UIProgressView *mprogressView; 34 | 35 | @property (weak, nonatomic) IBOutlet UIView *mViewProgress; 36 | @property (strong, nonatomic) UIActivityIndicatorView *indicator; 37 | @property (weak, nonatomic) IBOutlet UISegmentedControl *mSegmentedControl; 38 | @end 39 | 40 | @implementation VideoPlayerViewController 41 | 42 | - (void)viewDidLoad { 43 | [super viewDidLoad]; 44 | self.title = @"视频播放器"; 45 | self.edgesForExtendedLayout = UIRectEdgeNone; 46 | _path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]; 47 | [self initPlayer]; 48 | } 49 | - (IBAction)actionGeneratePics:(id)sender { 50 | [self getVideoThumbnail:_path]; 51 | } 52 | UIImageView *iv; 53 | - (void)getVideoThumbnail:(NSString *)path{ 54 | AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:path]]; 55 | 56 | NSLog(@"%d",asset.duration.timescale); 57 | AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; 58 | generator.maximumSize = CGSizeMake(480,136);//如果是CGSizeMake(480,136),则获取到的图片是{240, 136}。与实际大小成比例 59 | // generator.apertureMode = AVAssetImageGeneratorApertureModeCleanAperture; 60 | generator.appliesPreferredTrackTransform = YES;//这个属性保证我们获取的图片的方向是正确的。比如有的视频需要旋转手机方向才是视频的正确方向。 61 | NSError *error = nil; 62 | CMTime actualTime;//确切获取图片的时间位置 63 | /**因为有误差,所以需要设置以下两个属性。如果不设置误差有点大,设置了之后相差非常非常的小**/ 64 | generator.requestedTimeToleranceAfter = kCMTimeZero; 65 | generator.requestedTimeToleranceBefore = kCMTimeZero; 66 | CMTime time = CMTimeMake(1,1);//想要获取图片的时间位置 67 | CGImageRef imageRef = [generator copyCGImageAtTime:time actualTime:&actualTime error:&error]; 68 | 69 | if (!error) { 70 | CMTimeShow(actualTime);//{1181/600 = 1.968} 71 | CMTimeShow(time);//{88200/44100 = 2.000} 72 | UIImage *image = [UIImage imageWithCGImage:imageRef]; 73 | if (iv==nil) { 74 | iv = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300,600)]; 75 | iv.contentMode = UIViewContentModeScaleAspectFit; 76 | [self.view addSubview:iv]; 77 | } 78 | iv.image = image; 79 | iv.backgroundColor = [UIColor redColor]; 80 | } 81 | } 82 | - (void)initPlayer{ 83 | [self.mlider setThumbImage:[UIImage imageNamed:@"dot"] forState:UIControlStateNormal]; 84 | [self.mlider addObserver:self forKeyPath:@"tracking" options:NSKeyValueObservingOptionNew context:nil]; 85 | 86 | 87 | // NSString *path = [[NSBundle mainBundle] pathForResource:@"video2" ofType:@"mp4"]; 88 | // NSURL *url = [NSURL fileURLWithPath:path]; 89 | 90 | // NSURL *url = [NSURL URLWithString:@"http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4"]; 91 | // NSURL *url = [NSURL URLWithString:@"http://192.168.9.196:8080/videos/video.mp4"]; 92 | NSURL *url = [NSURL URLWithString:@"http://192.168.9.197:8080/videos/videos.mp4"]; 93 | _playItem = [[AVPlayerItem alloc] initWithURL:url]; 94 | // _playItem.preferredForwardBufferDuration = 5;此属性设置缓存了多少秒就开始播放,不过要与AVPlayer的automaticallyWaitsToMinimizeStalling = false结合使用才行 95 | 96 | // AVAsset *asset = [AVAsset assetWithURL:url];//实际是创建了AVURLAsset 97 | // AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset]; 98 | // self.player = [AVPlayer playerWithPlayerItem:item];//此实例方法要配合以上两句实例才行,即通过AVAsset 99 | 100 | // self.player = [[AVPlayer alloc] initWithPlayerItem:_playItem];//这是第二种方式 101 | 102 | self.player = [[AVPlayer alloc] init];//第三种方式苹果推荐的方式,先实例化一个空的AVPlayerLayer创建之后,通过replaceCurrentItemWithPlayerItem设置。最好的实践是在AVPlayer调用play之后调用replaceCurrentItemWithPlayerItem 103 | self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; 104 | [self.player replaceCurrentItemWithPlayerItem:_playItem]; 105 | 106 | self.playerLayer.frame = CGRectMake(0, 0,CGRectGetWidth(self.view.bounds), 260); 107 | self.playerLayer.backgroundColor = [UIColor redColor].CGColor; 108 | self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspect; 109 | [self.view.layer addSublayer:self.playerLayer]; 110 | //监听播放器的状态,准备好播放、失败、未知错误 111 | [_playItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; 112 | // 监听缓存的时间 113 | [_playItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil]; 114 | // 监听获取当缓存不够,视频加载不出来的情况: 115 | [_playItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil]; 116 | // 用于监听缓存足够播放的状态 117 | [_playItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil]; 118 | __weak typeof(self) this = self; 119 | [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 10) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) { 120 | float currentTime = CMTimeGetSeconds(time); 121 | this.mlider.value = currentTime; 122 | this.mLabeStart.text = [this getMMSSFromSS:(int)currentTime]; 123 | this.mLabelTimeLeft.text = [this getMMSSFromSS:(int)(CMTimeGetSeconds(this.duration)-currentTime)]; 124 | }]; 125 | 126 | 127 | _btn = [UIButton buttonWithType:UIButtonTypeCustom]; 128 | [_btn setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal]; 129 | [_btn setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateSelected]; 130 | [_btn addTarget:self action:@selector(actionPlayPause:) forControlEvents:UIControlEventTouchUpInside]; 131 | _btn.frame = CGRectMake(CGRectGetWidth(self.playerLayer.bounds)/2-16,CGRectGetHeight(self.playerLayer.bounds)/2-16, 32, 32); 132 | [self.view addSubview:_btn]; 133 | 134 | self.indicator = [[UIActivityIndicatorView alloc] initWithFrame:_btn.frame]; 135 | self.indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; 136 | self.indicator.color = [UIColor colorWithRed:23/255.0 green:130/255.0 blue:210/255.9 alpha:1]; 137 | self.indicator.hidden = YES; 138 | [self.view addSubview:self.indicator]; 139 | 140 | if ([_playItem canPlayFastForward]) {//只有是true的时候,才能支持2倍速度以上 141 | [self.mSegmentedControl insertSegmentWithTitle:@"X3" atIndex:2 animated:NO]; 142 | [self.mSegmentedControl insertSegmentWithTitle:@"X4" atIndex:3 animated:NO]; 143 | } 144 | [self.mSegmentedControl addTarget:self action:@selector(segmentedIndexChanged:) forControlEvents:UIControlEventValueChanged]; 145 | // AVPlayerTimeControlStatusPaused, 暂停 146 | // AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate,等待播放 147 | // AVPlayerTimeControlStatusPlaying 播放 148 | // _player.timeControlStatus 149 | } 150 | #pragma mark - Action 151 | - (void)actionPlayPause:(UIButton *)sender { 152 | if (sender.selected) { 153 | [self.player pause]; 154 | }else{ 155 | [self.player play]; 156 | [self performSelector:@selector(animalHide) withObject:nil afterDelay:1]; 157 | } 158 | sender.selected = !sender.selected; 159 | } 160 | - (void)segmentedIndexChanged:(UISegmentedControl *)sender{ 161 | self.player.rate = sender.selectedSegmentIndex+1; 162 | } 163 | #pragma mark - Observe 164 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ 165 | if ([keyPath isEqualToString:@"status"]) { 166 | AVPlayerItem *item = (AVPlayerItem *)object; 167 | AVPlayerItemStatus status = [[change objectForKey:@"new"] intValue]; // 获取更改后的状态 168 | if (status == AVPlayerItemStatusReadyToPlay) { 169 | _duration = item.duration;//只有在此状态下才能获取,不能在AVPlayerItem初始化后马上获取 170 | self.mLabelTimeLeft.text = [self getMMSSFromSS:(int)CMTimeGetSeconds(_duration)]; 171 | self.mlider.maximumValue = CMTimeGetSeconds(_duration); 172 | self.mlider.minimumValue = 0; 173 | NSLog(@"准备播放"); 174 | } else if (status == AVPlayerItemStatusFailed) { 175 | AVPlayerItem *item = (AVPlayerItem *)object; 176 | NSLog(@"%@",item.error); 177 | NSLog(@"AVPlayerStatusFailed"); 178 | } else { 179 | NSLog(@"%@",item.error); 180 | NSLog(@"AVPlayerStatusUnknown"); 181 | } 182 | }else if ([keyPath isEqualToString:@"tracking"]){ 183 | NSInteger status = [change[@"new"] integerValue]; 184 | float slideValue = self.mlider.value; 185 | [self.player seekToTime:CMTimeMake(slideValue*_duration.timescale, _duration.timescale) completionHandler:^(BOOL finished) { 186 | 187 | }]; 188 | self.mLabeStart.text = [self getMMSSFromSS:(int)slideValue]; 189 | self.mLabelTimeLeft.text = [self getMMSSFromSS:(int)(CMTimeGetSeconds(_duration)-slideValue)]; 190 | if (status) {//正在拖动 191 | [self.player pause]; 192 | }else{//停止拖动 193 | if (_btn.selected) { 194 | [self.player play]; 195 | } 196 | 197 | } 198 | }else if ([keyPath isEqualToString:@"loadedTimeRanges"]){ 199 | NSArray *array = _playItem.loadedTimeRanges; 200 | CMTimeRange timeRange = [array.firstObject CMTimeRangeValue];//本次缓冲时间范围 201 | float startSeconds = CMTimeGetSeconds(timeRange.start); 202 | float durationSeconds = CMTimeGetSeconds(timeRange.duration); 203 | NSTimeInterval totalBuffer = startSeconds + durationSeconds;//缓冲总长度 204 | self.mprogressView.progress = totalBuffer/CMTimeGetSeconds(_duration); 205 | NSLog(@"当前缓冲时间:%f",totalBuffer); 206 | }else if ([keyPath isEqualToString:@"playbackBufferEmpty"]){ 207 | NSLog(@"缓存不够,不能播放!"); 208 | }else if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"]){ 209 | if ([change[@"new"] boolValue]) { 210 | if (!self.indicator.hidden) { 211 | self.indicator.hidden = YES; 212 | [self.indicator stopAnimating]; 213 | } 214 | self.canKeepUp = YES; 215 | NSLog(@"缓存的足够多可以播放了!"); 216 | }else{ 217 | self.canKeepUp = NO; 218 | } 219 | } 220 | 221 | } 222 | -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 223 | UITouch *touch = touches.anyObject; 224 | CGPoint point = [touch locationInView:self.view]; 225 | CALayer *layer = [self.playerLayer hitTest:point]; 226 | if (layer) { 227 | if (_btn.alpha) { 228 | [self animalHide]; 229 | }else{ 230 | [self animalShow]; 231 | } 232 | } 233 | } 234 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 235 | NSLog(@"begin"); 236 | } 237 | #pragma mark - Private 238 | - (void)animalHide{ 239 | [UIView animateWithDuration:1 animations:^{ 240 | _btn.alpha = 0; 241 | self.mViewProgress.alpha = 0; 242 | if (!self.canKeepUp) { 243 | self.indicator.hidden = NO; 244 | [self.indicator startAnimating]; 245 | } 246 | }]; 247 | } 248 | - (void)animalShow{ 249 | [UIView animateWithDuration:1 animations:^{ 250 | if (self.indicator.hidden) { 251 | _btn.alpha = 1; 252 | } 253 | self.mViewProgress.alpha = 1; 254 | }]; 255 | } 256 | 257 | -(NSString *)getMMSSFromSS:(NSInteger)seconds{ 258 | NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600]; 259 | NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60]; 260 | NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60]; 261 | NSString *format_time = [NSString stringWithFormat:@"%@:%@:%@",str_hour,str_minute,str_second]; 262 | return format_time; 263 | } 264 | /* 265 | #pragma mark - Navigation 266 | 267 | // In a storyboard-based application, you will often want to do a little preparation before navigation 268 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 269 | // Get the new view controller using [segue destinationViewController]. 270 | // Pass the selected object to the new view controller. 271 | } 272 | */ 273 | -(void)dealloc{ 274 | // 需要释放一下资源否则会奔溃 275 | [_playItem removeObserver:self forKeyPath:@"status"]; 276 | [_playItem removeObserver:self forKeyPath:@"loadedTimeRanges"]; 277 | [_playItem removeObserver:self forKeyPath:@"playbackBufferEmpty"]; 278 | [_playItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"]; 279 | [_player.currentItem cancelPendingSeeks]; 280 | [_player.currentItem.asset cancelLoading]; 281 | NSLog(@"顺利销毁"); 282 | } 283 | @end 284 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // VideoViewController.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/13. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VideoViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/VideoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // VideoViewController.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/7/13. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "VideoViewController.h" 10 | #import 11 | #import "FOFMoviePlayer.h" 12 | @interface VideoViewController () 13 | { 14 | NSString *_videoPath; 15 | NSString *_newVideoPath; 16 | NSMutableArray *_imagesArray; 17 | } 18 | @property (nonatomic,strong)FOFMoviePlayer *moviePlayer; 19 | 20 | @end 21 | 22 | @implementation VideoViewController 23 | 24 | - (void)viewDidLoad { 25 | [super viewDidLoad]; 26 | self.edgesForExtendedLayout = UIRectEdgeNone; 27 | self.title = @"视频编辑学习"; 28 | _videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]; 29 | _imagesArray = [NSMutableArray arrayWithCapacity:31]; 30 | for (int i = 1; i<32; i++) { 31 | [_imagesArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]]]; 32 | } 33 | } 34 | - (IBAction)actionClick:(UIButton *)sender { 35 | switch (sender.tag) { 36 | case 200: 37 | [self videoCut:_videoPath]; 38 | break; 39 | case 201://图片合成视频 40 | [self picturesToVideo]; 41 | default: 42 | break; 43 | } 44 | } 45 | 46 | 47 | - (void)videoCut:(NSString *)path{ 48 | // 1. 49 | AVURLAsset *asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:path]]; 50 | AVMutableComposition *composition = [AVMutableComposition composition]; 51 | AVMutableCompositionTrack *compositionTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 52 | NSError *error = nil; 53 | 54 | NSArray *tracks = asset.tracks; 55 | NSLog(@"所有轨道:%@\n",tracks);//打印出所有的资源轨道 56 | [compositionTrack setPreferredTransform:[[asset tracksWithMediaType:AVMediaTypeVideo].firstObject preferredTransform]]; 57 | [compositionTrack insertTimeRange:CMTimeRangeMake(CMTimeMake(1, 1), CMTimeMake(5, 1)) ofTrack:[asset tracksWithMediaType:AVMediaTypeVideo].firstObject atTime:kCMTimeZero error:&error];//设置视频的截取范围 58 | 59 | // 2. 60 | AVMutableVideoCompositionLayerInstruction *videolayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionTrack]; 61 | // CGAffineTransform translateToCenter = CGAffineTransformMakeTranslation(compositionTrack.naturalSize.height,0.0); 62 | // [videolayerInstruction setTransform:CGAffineTransformRotate(translateToCenter, M_PI_2) atTime:CMTimeMake(2, 1)];//将视频旋转90度 63 | [videolayerInstruction setOpacity:0.0 atTime:compositionTrack.asset.duration]; 64 | 65 | // 3. 66 | AVMutableVideoCompositionInstruction *videoCompositionInstrution = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; 67 | videoCompositionInstrution.timeRange = CMTimeRangeMake(kCMTimeZero, compositionTrack.asset.duration); 68 | videoCompositionInstrution.layerInstructions = @[videolayerInstruction]; 69 | 70 | // 4. 71 | AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition]; 72 | videoComposition.renderSize = CGSizeMake(compositionTrack.naturalSize.width, compositionTrack.naturalSize.height);//视频宽高,必须设置,否则会奔溃 73 | /* 74 | 电影:24 75 | PAL(帕尔制,电视广播制式)和SEACM():25 76 | NTSC(美国电视标准委员会):29.97 77 | Web/CD-ROM:15 78 | 其他视频类型,非丢帧视频,E-D动画 30 79 | */ 80 | videoComposition.frameDuration = CMTimeMake(1, 43);//必须设置,否则会奔溃,一般30就够了 81 | // videoComposition.renderScale 82 | videoComposition.instructions = [NSArray arrayWithObject:videoCompositionInstrution]; 83 | 84 | /*添加水印*/ 85 | [self addWaterMark:compositionTrack.naturalSize withBlock:^(CALayer *parent, CALayer *videoLayer) { 86 | videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parent]; 87 | }]; 88 | 89 | 90 | // 5. 91 | AVAssetExportSession *exportSesstion = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality]; 92 | _newVideoPath = [self pathForVideo:@"video"]; 93 | exportSesstion.outputURL = [NSURL fileURLWithPath:_newVideoPath]; 94 | exportSesstion.outputFileType = AVFileTypeMPEG4; 95 | exportSesstion.shouldOptimizeForNetworkUse = YES; 96 | 97 | exportSesstion.videoComposition = videoComposition;//设置导出视频的处理方案 98 | 99 | [exportSesstion exportAsynchronouslyWithCompletionHandler:^{ 100 | AVAssetExportSessionStatus status = exportSesstion.status; 101 | if (status == AVAssetExportSessionStatusCompleted) { 102 | NSLog(@"导出成功"); 103 | dispatch_async(dispatch_get_main_queue(), ^{ 104 | if (self.moviePlayer.playerLayer) { 105 | [self.moviePlayer.playerLayer removeFromSuperlayer]; 106 | } 107 | self.moviePlayer = [[FOFMoviePlayer alloc] initWithFrame:CGRectMake(10, 140,272, 480) url:[NSURL fileURLWithPath:_newVideoPath] superLayer:self.view.layer]; 108 | [self.moviePlayer.playerLayer setVideoGravity:AVLayerVideoGravityResizeAspect]; 109 | [self.moviePlayer fof_play]; 110 | }); 111 | }else{ 112 | 113 | NSLog(@"导出失败%@",exportSesstion.error); 114 | } 115 | }]; 116 | } 117 | - (void)addWaterMark:(CGSize)sizeOfVideo withBlock:(void (^)(CALayer *parent,CALayer *videoLayer)) returnBlock{ 118 | 119 | CATextLayer *textOfvideo=[[CATextLayer alloc] init]; 120 | textOfvideo.string=[NSString stringWithFormat:@"%@",@"测试水印文字"]; 121 | textOfvideo.font = (__bridge CFTypeRef _Nullable)([UIFont boldSystemFontOfSize:24]); 122 | // 渲染分辨率,否则显示模糊 123 | textOfvideo.contentsScale = [UIScreen mainScreen].scale; 124 | [textOfvideo setFrame:CGRectMake(0, 10, sizeOfVideo.width, 40)]; 125 | [textOfvideo setAlignmentMode:kCAAlignmentCenter]; 126 | [textOfvideo setForegroundColor:[UIColor whiteColor].CGColor]; 127 | 128 | UIImage *myImage=[UIImage imageNamed:@"icon.png"]; 129 | CALayer *layerCa = [CALayer layer]; 130 | layerCa.contents = (id)myImage.CGImage; 131 | layerCa.frame = CGRectMake(sizeOfVideo.width-120, sizeOfVideo.height-120, 120, 120); 132 | layerCa.opacity = 1.0; 133 | 134 | CALayer *parentLayer=[CALayer layer]; 135 | CALayer *videoLayer=[CALayer layer]; 136 | parentLayer.frame=CGRectMake(0, 0, sizeOfVideo.width, sizeOfVideo.height); 137 | videoLayer.frame=CGRectMake(0, 0, sizeOfVideo.width, sizeOfVideo.height); 138 | [parentLayer addSublayer:videoLayer]; 139 | [parentLayer addSublayer:layerCa]; 140 | [parentLayer addSublayer:textOfvideo]; 141 | returnBlock(parentLayer,videoLayer); 142 | } 143 | #pragma mark - Private 144 | - (NSString *)pathForVideo:(NSString *)videoName{ 145 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 146 | NSString *documentsDirectory = paths.firstObject; 147 | 148 | NSString *path = [documentsDirectory stringByAppendingPathComponent: 149 | [NSString stringWithFormat:@"%@-%d.mp4",videoName,arc4random() % 1000]]; 150 | NSLog(@"视频路径:%@\n",path); 151 | return path; 152 | } 153 | - (void)didReceiveMemoryWarning { 154 | [super didReceiveMemoryWarning]; 155 | // Dispose of any resources that can be recreated. 156 | } 157 | 158 | /** 159 | 图片合成视频,如果图片质量较高的话,需要压缩后才合成,这里有没有进行压缩 160 | */ 161 | - (void)picturesToVideo{ 162 | NSError *outError; 163 | NSURL *outputURL = [NSURL fileURLWithPath:[self pathForVideo:@"videoFromPics"]]; 164 | AVAssetWriter *assetWriter = [AVAssetWriter assetWriterWithURL:outputURL 165 | fileType:AVFileTypeQuickTimeMovie 166 | error:&outError]; 167 | BOOL success = (assetWriter != nil); 168 | if (success) { 169 | //写入视频大小 170 | NSInteger numPixels = 320 * 480; 171 | //每像素比特 172 | CGFloat bitsPerPixel = 6; 173 | NSInteger bitsPerSecond = numPixels * bitsPerPixel; 174 | 175 | // 码率和帧率设置,这个能够很好的压缩视频,否则导出来的视频比较大 176 | NSDictionary *compressionProperties = @{ AVVideoAverageBitRateKey : @(bitsPerSecond),//视频码率就是数据传输时单位时间传送的数据位数,一般我们用的单位是kbps即千位每秒。通俗一点的理解就是取样率,单位时间内取样率越大,精度就越高,处理出来的文件就越接近原始文件。 177 | AVVideoExpectedSourceFrameRateKey : @(30), 178 | AVVideoMaxKeyFrameIntervalKey : @(30), 179 | AVVideoProfileLevelKey : AVVideoProfileLevelH264BaselineAutoLevel 180 | }; 181 | 182 | CGSize size =CGSizeMake(320,480); 183 | NSDictionary *videoSetting = @{AVVideoWidthKey:@(size.width), 184 | AVVideoHeightKey:@(size.height), 185 | AVVideoCodecKey:AVVideoCodecH264, 186 | AVVideoScalingModeKey:AVVideoScalingModeResizeAspectFill, 187 | AVVideoCompressionPropertiesKey:compressionProperties 188 | }; 189 | 190 | AVAssetWriterInput *assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSetting]; 191 | 192 | NSDictionary*sourcePixelBufferAttributesDictionary =[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32ARGB],kCVPixelBufferPixelFormatTypeKey,nil]; 193 | // AVAssetWriterInputPixelBufferAdaptor提供CVPixelBufferPool实例, 194 | // 可以使用分配像素缓冲区写入输出文件。使用提供的像素为缓冲池分配通常 195 | // 是更有效的比添加像素缓冲区分配使用一个单独的池 196 | AVAssetWriterInputPixelBufferAdaptor *adaptor =[AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:assetWriterInput sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary]; 197 | 198 | if ([assetWriter canAddInput:assetWriterInput]) 199 | [assetWriter addInput:assetWriterInput]; 200 | 201 | [assetWriter startWriting]; 202 | 203 | [assetWriter startSessionAtSourceTime:kCMTimeZero]; 204 | 205 | dispatch_queue_t myInputSerialQueue =dispatch_queue_create("mediaInputQueue",NULL); 206 | 207 | __block int frame = 0; 208 | [assetWriterInput requestMediaDataWhenReadyOnQueue:myInputSerialQueue usingBlock:^{ 209 | while ([assetWriterInput isReadyForMoreMediaData]) 210 | { 211 | ++frame; 212 | if(frame >=[_imagesArray count]) 213 | { 214 | [assetWriterInput markAsFinished]; 215 | [assetWriter finishWritingWithCompletionHandler:^{ 216 | NSLog(@"合成完成!!"); 217 | }]; 218 | break; 219 | } 220 | 221 | CVPixelBufferRef nextBuffer = [self pixelBufferFromCGImage:[_imagesArray[frame] CGImage] size:size]; 222 | 223 | if (nextBuffer) 224 | { 225 | [adaptor appendPixelBuffer:nextBuffer withPresentationTime:CMTimeMake(frame,1)]; 226 | CFRelease(nextBuffer); 227 | nextBuffer = nil; 228 | } 229 | } 230 | }]; 231 | } 232 | 233 | } 234 | - (CVPixelBufferRef)pixelBufferFromCGImage:(CGImageRef)image size:(CGSize)size 235 | { 236 | NSDictionary *options =[NSDictionary dictionaryWithObjectsAndKeys: 237 | [NSNumber numberWithBool:YES],kCVPixelBufferCGImageCompatibilityKey, 238 | [NSNumber numberWithBool:YES],kCVPixelBufferCGBitmapContextCompatibilityKey,nil]; 239 | CVPixelBufferRef pxbuffer =NULL; 240 | CVReturn status =CVPixelBufferCreate(kCFAllocatorDefault,size.width,size.height,kCVPixelFormatType_32ARGB,(__bridge CFDictionaryRef) options,&pxbuffer); 241 | 242 | NSParameterAssert(status ==kCVReturnSuccess && pxbuffer !=NULL); 243 | 244 | CVPixelBufferLockBaseAddress(pxbuffer,0); 245 | 246 | void *pxdata =CVPixelBufferGetBaseAddress(pxbuffer); 247 | 248 | CGColorSpaceRef rgbColorSpace=CGColorSpaceCreateDeviceRGB(); 249 | // 当你调用这个函数的时候,Quartz创建一个位图绘制环境,也就是位图上下文。当你向上下文中绘制信息时,Quartz把你要绘制的信息作为位图数据绘制到指定的内存块。一个新的位图上下文的像素格式由三个参数决定:每个组件的位数,颜色空间,alpha选项 250 | CGContextRef context =CGBitmapContextCreate(pxdata,size.width,size.height,8,4*size.width,rgbColorSpace,kCGImageAlphaPremultipliedFirst); 251 | 252 | //使用CGContextDrawImage绘制图片 这里设置不正确的话 会导致视频颠倒 253 | // 当通过CGContextDrawImage绘制图片到一个context中时,如果传入的是UIImage的CGImageRef,因为UIKit和CG坐标系y轴相反,所以图片绘制将会上下颠倒 254 | CGContextDrawImage(context,CGRectMake(0,0,CGImageGetWidth(image),CGImageGetHeight(image)), image); 255 | // 释放色彩空间 256 | CGColorSpaceRelease(rgbColorSpace); 257 | // 释放context 258 | CGContextRelease(context); 259 | // 解锁pixel buffer 260 | CVPixelBufferUnlockBaseAddress(pxbuffer,0); 261 | 262 | return pxbuffer; 263 | } 264 | 265 | /* 266 | #pragma mark - Navigation 267 | 268 | // In a storyboard-based application, you will often want to do a little preparation before navigation 269 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 270 | // Get the new view controller using [segue destinationViewController]. 271 | // Pass the selected object to the new view controller. 272 | } 273 | */ 274 | 275 | @end 276 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/2. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/2. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import 11 | #import 12 | #import "ConvertUtil.h" 13 | 14 | @interface ViewController () 15 | { 16 | NSURL *_url; 17 | } 18 | @property (nonatomic,strong)AVAudioPlayer *player; 19 | @property (nonatomic,strong)AVAudioRecorder *recorder; 20 | @end 21 | 22 | @implementation ViewController 23 | 24 | - (void)viewDidLoad { 25 | [super viewDidLoad]; 26 | 27 | 28 | NSError *error = nil; 29 | [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];//支持后台播放和录音 30 | [[AVAudioSession sharedInstance] setActive:YES error:nil];//这两行代码在录音和播放的时候要写,否则会失败 31 | if (error) { 32 | NSLog(@"注册录音失败%@",error); 33 | }else{ 34 | NSLog(@"注册录音成功!"); 35 | } 36 | [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;//必须先调用一遍,要不锁屏界面的时候显示不出来。这里设置为空,表示还没有歌曲播放 37 | 38 | } 39 | 40 | - (void)viewDidAppear:(BOOL)animated { 41 | // 接受远程控制 这句如果不调用的话,锁屏不会显示出来 42 | [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 43 | } 44 | 45 | - (void)viewDidDisappear:(BOOL)animated { 46 | // 取消远程控制 47 | [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; 48 | } 49 | - (void)setPlayingInfo { 50 | // 设置后台播放时显示的东西,例如歌曲名字,图片等 51 | MPMediaItemArtwork *artWork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"empty.png"]]; 52 | 53 | NSDictionary *dic = @{MPMediaItemPropertyTitle:@"时间煮雨", 54 | MPMediaItemPropertyArtist:@"吴亦凡", 55 | MPMediaItemPropertyArtwork:artWork, 56 | MPMediaItemPropertyPlaybackDuration:@(3) 57 | }; 58 | [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dic]; 59 | 60 | } 61 | - (NSURL *)pathForMedia{ 62 | return [self pathForName:@"test.caf"]; 63 | } 64 | - (NSURL *)pathForName:(NSString *)name{ 65 | NSString *docum = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject; 66 | docum = [docum stringByAppendingPathComponent:name]; 67 | NSURL *url = [NSURL URLWithString:docum]; 68 | return url; 69 | } 70 | - (NSURL *)pathForPlaybackground{ 71 | NSString *path = [[NSBundle mainBundle] pathForResource:@"宿命者" ofType:@"mp3"]; 72 | NSURL *url = [NSURL fileURLWithPath:path]; 73 | return url; 74 | } 75 | //支持后台播放,并且锁屏可以看 76 | 77 | - (IBAction)actionPlaybackground:(id)sender { 78 | NSURL *url = [self pathForPlaybackground]; 79 | NSError *error = nil; 80 | self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];//播放声音 81 | if (error) { 82 | NSLog(@"播放失败%@",error); 83 | }else{ 84 | [self.player play]; 85 | [self setPlayingInfo]; 86 | } 87 | } 88 | //录音、合成之后等播放 89 | - (IBAction)actionPlay:(id)sender { 90 | NSURL *url = _url; 91 | NSError *error = nil; 92 | self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];//播放声音 93 | self.player.delegate = self; 94 | if (error) { 95 | NSLog(@"播放失败%@",error); 96 | }else{ 97 | [self.player play]; 98 | } 99 | 100 | } 101 | //暂停录音 102 | - (IBAction)actionPause:(id)sender { 103 | if ([self.recorder isRecording]) { 104 | // [self.recorder pause];//pause之后,不会把所有的录音写入文件中,并且可以通过recorde继续录制 105 | [self.recorder stop];//stop之后会把所有的录音都写到文件中。文件录制结束后一定要stop一下,否则有可能播放失败的 106 | } 107 | } 108 | //开始录音 109 | - (IBAction)actionRecord:(id)sender { 110 | _url = [self pathForMedia]; 111 | NSMutableDictionary *dicM=[NSMutableDictionary dictionary]; 112 | 113 | //设置录音格式 114 | 115 | [dicM setObject:@(kAudioFormatLinearPCM)forKey:AVFormatIDKey]; 116 | 117 | //设置录音采样率,8000是电话采样率,对于一般录音已经够了,不过为了保证声音不失真,采样频率应该在40kHz左右 118 | // 8000 Hz - 电话所用采样率, 对于人的说话已经足够 119 | // 11025 Hz - 电话所用采样率 120 | // 22050 Hz - 无线电广播所用采样率 121 | // 32000 Hz - miniDV 数码视频 camcorder、DAT (LP mode)所用采样率 122 | // 44100 Hz - 音频 CD, 也常用于 MPEG-1 音频(VCD,SVCD,MP3)所用采样率 123 | 124 | [dicM setObject:@(8000)forKey:AVSampleRateKey]; 125 | 126 | //设置录制通道 单频道和双频道 127 | 128 | [dicM setObject:@(2)forKey:AVNumberOfChannelsKey]; 129 | 130 | //每个采样点位数,分为8、16、24、32 131 | 132 | [dicM setObject:@(16)forKey:AVLinearPCMBitDepthKey]; 133 | 134 | //是否使用浮点数采样 转换成MP3的时候不能使用该属性 135 | 136 | // [dicM setObject:@(YES)forKey:AVLinearPCMIsFloatKey]; 137 | [dicM setObject:@(AVAudioQualityMedium) forKey:AVEncoderAudioQualityKey];//设置音频质量 138 | NSError *error = nil; 139 | 140 | self.recorder = [[AVAudioRecorder alloc] initWithURL:_url settings:dicM error:&error]; 141 | // [self.recorder recordForDuration:10];//能够精确控制要录制多少秒。时间到了则会自动停止 142 | if (error) { 143 | NSLog(@"%@",error.description); 144 | } 145 | if ([self.recorder prepareToRecord]) {//创建文件并且准备开始录音 146 | NSLog(@"准备好录音"); 147 | [self.recorder record];//开始录音或继续录音,(暂停之后可以继续录音) 148 | }else{ 149 | NSLog(@"失败"); 150 | } 151 | 152 | } 153 | - (NSURL *)pathForCompostion{ 154 | NSString *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject; 155 | document = [document stringByAppendingPathComponent:[NSString stringWithFormat:@"%.0f.m4a",[NSDate date].timeIntervalSince1970]]; 156 | return [NSURL fileURLWithPath:document]; 157 | } 158 | //开始合成 159 | - (IBAction)audioComposition:(UIButton *)button{ 160 | _url = [self pathForCompostion]; 161 | NSString *path1 = [[NSBundle mainBundle] pathForResource:@"男声" ofType:@"mp3"]; 162 | NSString *path2 = [[NSBundle mainBundle] pathForResource:@"女声" ofType:@"mp3"]; 163 | 164 | AVURLAsset *asset1 = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:path1]]; 165 | AVURLAsset *asset2 = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:path2]]; 166 | AVAssetTrack *track1 = [asset1 tracksWithMediaType:AVMediaTypeAudio].firstObject; 167 | AVAssetTrack *track2 = [asset2 tracksWithMediaType:AVMediaTypeAudio].firstObject; 168 | 169 | AVMutableComposition *composition = [AVMutableComposition composition]; 170 | AVMutableCompositionTrack *compositionTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:0]; 171 | 172 | // AVMutableCompositionTrack *compositionTrack2 = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:1];//这里可以再生成一个mutableCoposition,这样可以实现给一段声音添加一个背景音乐 173 | 174 | NSError *error1 = nil; 175 | NSError *error2 = nil; 176 | NSError *error3 = nil; 177 | float timescale1 = asset1.duration.timescale; 178 | float timescale2 = asset2.duration.timescale; 179 | 180 | [compositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset1.duration) ofTrack:track1 atTime:kCMTimeZero error:&error1]; 181 | [compositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset2.duration) ofTrack:track2 atTime:asset1.duration error:&error2]; 182 | 183 | // [compositionTrack2 insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration) ofTrack:track2 atTime:kCMTimeZero error:&error3]; 184 | 185 | // [compositionTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero,asset1.duration) toDuration:CMTimeMake(asset1.duration.value, timescale1*3)];//通过此方法可以实现语音或视频的加速和减速 186 | AVAssetExportSession *exportSessio = [AVAssetExportSession exportSessionWithAsset:composition presetName:AVAssetExportPresetAppleM4A]; 187 | exportSessio.outputFileType = AVFileTypeAppleM4A; 188 | exportSessio.outputURL = _url;//路径如果已经存在此文件,则导出会失败 189 | // exportSessio.timeRange //对音视频截取的时间 190 | [exportSessio exportAsynchronouslyWithCompletionHandler:^{ 191 | AVAssetExportSessionStatus status = exportSessio.status; 192 | if (status == AVAssetExportSessionStatusCompleted) { 193 | NSLog(@"导出成功"); 194 | }else{ 195 | NSLog(@"导出失败"); 196 | } 197 | }]; 198 | } 199 | - (IBAction)actionConvert:(UIButton *)sender { 200 | [ConvertUtil cafFile:_url.absoluteString toMp3File:[self pathForName:@"test.mp3"].absoluteString]; 201 | } 202 | 203 | //锁屏之后屏幕上显示的暂停、上一曲、下一曲操作 204 | -(void)remoteControlReceivedWithEvent:(UIEvent *)event{ 205 | // 根据事件的子类型(subtype) 来判断具体的事件类型, 并做出处理 206 | switch (event.subtype) { 207 | case UIEventSubtypeRemoteControlPlay: 208 | case UIEventSubtypeRemoteControlPause: { 209 | // 执行播放或暂停的相关操作 (锁屏界面和上拉快捷功能菜单处的播放按钮) 210 | break; 211 | } 212 | case UIEventSubtypeRemoteControlPreviousTrack: { 213 | // 执行上一曲的相关操作 (锁屏界面和上拉快捷功能菜单处的上一曲按钮) 214 | break; 215 | } 216 | case UIEventSubtypeRemoteControlNextTrack: { 217 | // 执行下一曲的相关操作 (锁屏界面和上拉快捷功能菜单处的下一曲按钮) 218 | // 设置后台播放时显示的东西,例如歌曲名字,图片等 219 | MPMediaItemArtwork *artWork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"empty.png"]]; 220 | 221 | NSDictionary *dic = @{MPMediaItemPropertyTitle:@"下一曲", 222 | MPMediaItemPropertyArtist:@"无名 ", 223 | MPMediaItemPropertyArtwork:artWork 224 | }; 225 | [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dic]; 226 | break; 227 | } 228 | case UIEventSubtypeRemoteControlTogglePlayPause: { 229 | // 进行播放/暂停的相关操作 (耳机的播放/暂停按钮) 230 | break; 231 | } 232 | default: 233 | break; 234 | } 235 | } 236 | 237 | @end 238 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/empty.png -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/lame/lame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to MP3 LAME encoding engine 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | /* $Id: lame.h,v 1.192 2017/08/31 14:14:46 robert Exp $ */ 23 | 24 | #ifndef LAME_LAME_H 25 | #define LAME_LAME_H 26 | 27 | /* for size_t typedef */ 28 | #include 29 | /* for va_list typedef */ 30 | #include 31 | /* for FILE typedef, TODO: remove when removing lame_mp3_tags_fid */ 32 | #include 33 | 34 | #if defined(__cplusplus) 35 | extern "C" { 36 | #endif 37 | 38 | typedef void (*lame_report_function)(const char *format, va_list ap); 39 | 40 | #if defined(WIN32) || defined(_WIN32) 41 | #undef CDECL 42 | #define CDECL __cdecl 43 | #else 44 | #define CDECL 45 | #endif 46 | 47 | #define DEPRECATED_OR_OBSOLETE_CODE_REMOVED 1 48 | 49 | typedef enum vbr_mode_e { 50 | vbr_off=0, 51 | vbr_mt, /* obsolete, same as vbr_mtrh */ 52 | vbr_rh, 53 | vbr_abr, 54 | vbr_mtrh, 55 | vbr_max_indicator, /* Don't use this! It's used for sanity checks. */ 56 | vbr_default=vbr_mtrh /* change this to change the default VBR mode of LAME */ 57 | } vbr_mode; 58 | 59 | 60 | /* MPEG modes */ 61 | typedef enum MPEG_mode_e { 62 | STEREO = 0, 63 | JOINT_STEREO, 64 | DUAL_CHANNEL, /* LAME doesn't supports this! */ 65 | MONO, 66 | NOT_SET, 67 | MAX_INDICATOR /* Don't use this! It's used for sanity checks. */ 68 | } MPEG_mode; 69 | 70 | /* Padding types */ 71 | typedef enum Padding_type_e { 72 | PAD_NO = 0, 73 | PAD_ALL, 74 | PAD_ADJUST, 75 | PAD_MAX_INDICATOR /* Don't use this! It's used for sanity checks. */ 76 | } Padding_type; 77 | 78 | 79 | 80 | /*presets*/ 81 | typedef enum preset_mode_e { 82 | /*values from 8 to 320 should be reserved for abr bitrates*/ 83 | /*for abr I'd suggest to directly use the targeted bitrate as a value*/ 84 | ABR_8 = 8, 85 | ABR_320 = 320, 86 | 87 | V9 = 410, /*Vx to match Lame and VBR_xx to match FhG*/ 88 | VBR_10 = 410, 89 | V8 = 420, 90 | VBR_20 = 420, 91 | V7 = 430, 92 | VBR_30 = 430, 93 | V6 = 440, 94 | VBR_40 = 440, 95 | V5 = 450, 96 | VBR_50 = 450, 97 | V4 = 460, 98 | VBR_60 = 460, 99 | V3 = 470, 100 | VBR_70 = 470, 101 | V2 = 480, 102 | VBR_80 = 480, 103 | V1 = 490, 104 | VBR_90 = 490, 105 | V0 = 500, 106 | VBR_100 = 500, 107 | 108 | 109 | 110 | /*still there for compatibility*/ 111 | R3MIX = 1000, 112 | STANDARD = 1001, 113 | EXTREME = 1002, 114 | INSANE = 1003, 115 | STANDARD_FAST = 1004, 116 | EXTREME_FAST = 1005, 117 | MEDIUM = 1006, 118 | MEDIUM_FAST = 1007 119 | } preset_mode; 120 | 121 | 122 | /*asm optimizations*/ 123 | typedef enum asm_optimizations_e { 124 | MMX = 1, 125 | AMD_3DNOW = 2, 126 | SSE = 3 127 | } asm_optimizations; 128 | 129 | 130 | /* psychoacoustic model */ 131 | typedef enum Psy_model_e { 132 | PSY_GPSYCHO = 1, 133 | PSY_NSPSYTUNE = 2 134 | } Psy_model; 135 | 136 | 137 | /* buffer considerations */ 138 | typedef enum buffer_constraint_e { 139 | MDB_DEFAULT=0, 140 | MDB_STRICT_ISO=1, 141 | MDB_MAXIMUM=2 142 | } buffer_constraint; 143 | 144 | 145 | struct lame_global_struct; 146 | typedef struct lame_global_struct lame_global_flags; 147 | typedef lame_global_flags *lame_t; 148 | 149 | 150 | 151 | 152 | /*********************************************************************** 153 | * 154 | * The LAME API 155 | * These functions should be called, in this order, for each 156 | * MP3 file to be encoded. See the file "API" for more documentation 157 | * 158 | ***********************************************************************/ 159 | 160 | 161 | /* 162 | * REQUIRED: 163 | * initialize the encoder. sets default for all encoder parameters, 164 | * returns NULL if some malloc()'s failed 165 | * otherwise returns pointer to structure needed for all future 166 | * API calls. 167 | */ 168 | lame_global_flags * CDECL lame_init(void); 169 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 170 | #else 171 | /* obsolete version */ 172 | int CDECL lame_init_old(lame_global_flags *); 173 | #endif 174 | 175 | /* 176 | * OPTIONAL: 177 | * set as needed to override defaults 178 | */ 179 | 180 | /******************************************************************** 181 | * input stream description 182 | ***********************************************************************/ 183 | /* number of samples. default = 2^32-1 */ 184 | int CDECL lame_set_num_samples(lame_global_flags *, unsigned long); 185 | unsigned long CDECL lame_get_num_samples(const lame_global_flags *); 186 | 187 | /* input sample rate in Hz. default = 44100hz */ 188 | int CDECL lame_set_in_samplerate(lame_global_flags *, int); 189 | int CDECL lame_get_in_samplerate(const lame_global_flags *); 190 | 191 | /* number of channels in input stream. default=2 */ 192 | int CDECL lame_set_num_channels(lame_global_flags *, int); 193 | int CDECL lame_get_num_channels(const lame_global_flags *); 194 | 195 | /* 196 | scale the input by this amount before encoding. default=1 197 | (not used by decoding routines) 198 | */ 199 | int CDECL lame_set_scale(lame_global_flags *, float); 200 | float CDECL lame_get_scale(const lame_global_flags *); 201 | 202 | /* 203 | scale the channel 0 (left) input by this amount before encoding. default=1 204 | (not used by decoding routines) 205 | */ 206 | int CDECL lame_set_scale_left(lame_global_flags *, float); 207 | float CDECL lame_get_scale_left(const lame_global_flags *); 208 | 209 | /* 210 | scale the channel 1 (right) input by this amount before encoding. default=1 211 | (not used by decoding routines) 212 | */ 213 | int CDECL lame_set_scale_right(lame_global_flags *, float); 214 | float CDECL lame_get_scale_right(const lame_global_flags *); 215 | 216 | /* 217 | output sample rate in Hz. default = 0, which means LAME picks best value 218 | based on the amount of compression. MPEG only allows: 219 | MPEG1 32, 44.1, 48khz 220 | MPEG2 16, 22.05, 24 221 | MPEG2.5 8, 11.025, 12 222 | (not used by decoding routines) 223 | */ 224 | int CDECL lame_set_out_samplerate(lame_global_flags *, int); 225 | int CDECL lame_get_out_samplerate(const lame_global_flags *); 226 | 227 | 228 | /******************************************************************** 229 | * general control parameters 230 | ***********************************************************************/ 231 | /* 1=cause LAME to collect data for an MP3 frame analyzer. default=0 */ 232 | int CDECL lame_set_analysis(lame_global_flags *, int); 233 | int CDECL lame_get_analysis(const lame_global_flags *); 234 | 235 | /* 236 | 1 = write a Xing VBR header frame. 237 | default = 1 238 | this variable must have been added by a Hungarian notation Windows programmer :-) 239 | */ 240 | int CDECL lame_set_bWriteVbrTag(lame_global_flags *, int); 241 | int CDECL lame_get_bWriteVbrTag(const lame_global_flags *); 242 | 243 | /* 1=decode only. use lame/mpglib to convert mp3/ogg to wav. default=0 */ 244 | int CDECL lame_set_decode_only(lame_global_flags *, int); 245 | int CDECL lame_get_decode_only(const lame_global_flags *); 246 | 247 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 248 | #else 249 | /* 1=encode a Vorbis .ogg file. default=0 */ 250 | /* DEPRECATED */ 251 | int CDECL lame_set_ogg(lame_global_flags *, int); 252 | int CDECL lame_get_ogg(const lame_global_flags *); 253 | #endif 254 | 255 | /* 256 | internal algorithm selection. True quality is determined by the bitrate 257 | but this variable will effect quality by selecting expensive or cheap algorithms. 258 | quality=0..9. 0=best (very slow). 9=worst. 259 | recommended: 2 near-best quality, not too slow 260 | 5 good quality, fast 261 | 7 ok quality, really fast 262 | */ 263 | int CDECL lame_set_quality(lame_global_flags *, int); 264 | int CDECL lame_get_quality(const lame_global_flags *); 265 | 266 | /* 267 | mode = 0,1,2,3 = stereo, jstereo, dual channel (not supported), mono 268 | default: lame picks based on compression ration and input channels 269 | */ 270 | int CDECL lame_set_mode(lame_global_flags *, MPEG_mode); 271 | MPEG_mode CDECL lame_get_mode(const lame_global_flags *); 272 | 273 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 274 | #else 275 | /* 276 | mode_automs. Use a M/S mode with a switching threshold based on 277 | compression ratio 278 | DEPRECATED 279 | */ 280 | int CDECL lame_set_mode_automs(lame_global_flags *, int); 281 | int CDECL lame_get_mode_automs(const lame_global_flags *); 282 | #endif 283 | 284 | /* 285 | force_ms. Force M/S for all frames. For testing only. 286 | default = 0 (disabled) 287 | */ 288 | int CDECL lame_set_force_ms(lame_global_flags *, int); 289 | int CDECL lame_get_force_ms(const lame_global_flags *); 290 | 291 | /* use free_format? default = 0 (disabled) */ 292 | int CDECL lame_set_free_format(lame_global_flags *, int); 293 | int CDECL lame_get_free_format(const lame_global_flags *); 294 | 295 | /* perform ReplayGain analysis? default = 0 (disabled) */ 296 | int CDECL lame_set_findReplayGain(lame_global_flags *, int); 297 | int CDECL lame_get_findReplayGain(const lame_global_flags *); 298 | 299 | /* decode on the fly. Search for the peak sample. If the ReplayGain 300 | * analysis is enabled then perform the analysis on the decoded data 301 | * stream. default = 0 (disabled) 302 | * NOTE: if this option is set the build-in decoder should not be used */ 303 | int CDECL lame_set_decode_on_the_fly(lame_global_flags *, int); 304 | int CDECL lame_get_decode_on_the_fly(const lame_global_flags *); 305 | 306 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 307 | #else 308 | /* DEPRECATED: now does the same as lame_set_findReplayGain() 309 | default = 0 (disabled) */ 310 | int CDECL lame_set_ReplayGain_input(lame_global_flags *, int); 311 | int CDECL lame_get_ReplayGain_input(const lame_global_flags *); 312 | 313 | /* DEPRECATED: now does the same as 314 | lame_set_decode_on_the_fly() && lame_set_findReplayGain() 315 | default = 0 (disabled) */ 316 | int CDECL lame_set_ReplayGain_decode(lame_global_flags *, int); 317 | int CDECL lame_get_ReplayGain_decode(const lame_global_flags *); 318 | 319 | /* DEPRECATED: now does the same as lame_set_decode_on_the_fly() 320 | default = 0 (disabled) */ 321 | int CDECL lame_set_findPeakSample(lame_global_flags *, int); 322 | int CDECL lame_get_findPeakSample(const lame_global_flags *); 323 | #endif 324 | 325 | /* counters for gapless encoding */ 326 | int CDECL lame_set_nogap_total(lame_global_flags*, int); 327 | int CDECL lame_get_nogap_total(const lame_global_flags*); 328 | 329 | int CDECL lame_set_nogap_currentindex(lame_global_flags* , int); 330 | int CDECL lame_get_nogap_currentindex(const lame_global_flags*); 331 | 332 | 333 | /* 334 | * OPTIONAL: 335 | * Set printf like error/debug/message reporting functions. 336 | * The second argument has to be a pointer to a function which looks like 337 | * void my_debugf(const char *format, va_list ap) 338 | * { 339 | * (void) vfprintf(stdout, format, ap); 340 | * } 341 | * If you use NULL as the value of the pointer in the set function, the 342 | * lame buildin function will be used (prints to stderr). 343 | * To quiet any output you have to replace the body of the example function 344 | * with just "return;" and use it in the set function. 345 | */ 346 | int CDECL lame_set_errorf(lame_global_flags *, lame_report_function); 347 | int CDECL lame_set_debugf(lame_global_flags *, lame_report_function); 348 | int CDECL lame_set_msgf (lame_global_flags *, lame_report_function); 349 | 350 | 351 | 352 | /* set one of brate compression ratio. default is compression ratio of 11. */ 353 | int CDECL lame_set_brate(lame_global_flags *, int); 354 | int CDECL lame_get_brate(const lame_global_flags *); 355 | int CDECL lame_set_compression_ratio(lame_global_flags *, float); 356 | float CDECL lame_get_compression_ratio(const lame_global_flags *); 357 | 358 | 359 | int CDECL lame_set_preset( lame_global_flags* gfp, int ); 360 | int CDECL lame_set_asm_optimizations( lame_global_flags* gfp, int, int ); 361 | 362 | 363 | 364 | /******************************************************************** 365 | * frame params 366 | ***********************************************************************/ 367 | /* mark as copyright. default=0 */ 368 | int CDECL lame_set_copyright(lame_global_flags *, int); 369 | int CDECL lame_get_copyright(const lame_global_flags *); 370 | 371 | /* mark as original. default=1 */ 372 | int CDECL lame_set_original(lame_global_flags *, int); 373 | int CDECL lame_get_original(const lame_global_flags *); 374 | 375 | /* error_protection. Use 2 bytes from each frame for CRC checksum. default=0 */ 376 | int CDECL lame_set_error_protection(lame_global_flags *, int); 377 | int CDECL lame_get_error_protection(const lame_global_flags *); 378 | 379 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 380 | #else 381 | /* padding_type. 0=pad no frames 1=pad all frames 2=adjust padding(default) */ 382 | int CDECL lame_set_padding_type(lame_global_flags *, Padding_type); 383 | Padding_type CDECL lame_get_padding_type(const lame_global_flags *); 384 | #endif 385 | 386 | /* MP3 'private extension' bit Meaningless. default=0 */ 387 | int CDECL lame_set_extension(lame_global_flags *, int); 388 | int CDECL lame_get_extension(const lame_global_flags *); 389 | 390 | /* enforce strict ISO compliance. default=0 */ 391 | int CDECL lame_set_strict_ISO(lame_global_flags *, int); 392 | int CDECL lame_get_strict_ISO(const lame_global_flags *); 393 | 394 | 395 | /******************************************************************** 396 | * quantization/noise shaping 397 | ***********************************************************************/ 398 | 399 | /* disable the bit reservoir. For testing only. default=0 */ 400 | int CDECL lame_set_disable_reservoir(lame_global_flags *, int); 401 | int CDECL lame_get_disable_reservoir(const lame_global_flags *); 402 | 403 | /* select a different "best quantization" function. default=0 */ 404 | int CDECL lame_set_quant_comp(lame_global_flags *, int); 405 | int CDECL lame_get_quant_comp(const lame_global_flags *); 406 | int CDECL lame_set_quant_comp_short(lame_global_flags *, int); 407 | int CDECL lame_get_quant_comp_short(const lame_global_flags *); 408 | 409 | int CDECL lame_set_experimentalX(lame_global_flags *, int); /* compatibility*/ 410 | int CDECL lame_get_experimentalX(const lame_global_flags *); 411 | 412 | /* another experimental option. for testing only */ 413 | int CDECL lame_set_experimentalY(lame_global_flags *, int); 414 | int CDECL lame_get_experimentalY(const lame_global_flags *); 415 | 416 | /* another experimental option. for testing only */ 417 | int CDECL lame_set_experimentalZ(lame_global_flags *, int); 418 | int CDECL lame_get_experimentalZ(const lame_global_flags *); 419 | 420 | /* Naoki's psycho acoustic model. default=0 */ 421 | int CDECL lame_set_exp_nspsytune(lame_global_flags *, int); 422 | int CDECL lame_get_exp_nspsytune(const lame_global_flags *); 423 | 424 | void CDECL lame_set_msfix(lame_global_flags *, double); 425 | float CDECL lame_get_msfix(const lame_global_flags *); 426 | 427 | 428 | /******************************************************************** 429 | * VBR control 430 | ***********************************************************************/ 431 | /* Types of VBR. default = vbr_off = CBR */ 432 | int CDECL lame_set_VBR(lame_global_flags *, vbr_mode); 433 | vbr_mode CDECL lame_get_VBR(const lame_global_flags *); 434 | 435 | /* VBR quality level. 0=highest 9=lowest */ 436 | int CDECL lame_set_VBR_q(lame_global_flags *, int); 437 | int CDECL lame_get_VBR_q(const lame_global_flags *); 438 | 439 | /* VBR quality level. 0=highest 9=lowest, Range [0,...,10[ */ 440 | int CDECL lame_set_VBR_quality(lame_global_flags *, float); 441 | float CDECL lame_get_VBR_quality(const lame_global_flags *); 442 | 443 | /* Ignored except for VBR=vbr_abr (ABR mode) */ 444 | int CDECL lame_set_VBR_mean_bitrate_kbps(lame_global_flags *, int); 445 | int CDECL lame_get_VBR_mean_bitrate_kbps(const lame_global_flags *); 446 | 447 | int CDECL lame_set_VBR_min_bitrate_kbps(lame_global_flags *, int); 448 | int CDECL lame_get_VBR_min_bitrate_kbps(const lame_global_flags *); 449 | 450 | int CDECL lame_set_VBR_max_bitrate_kbps(lame_global_flags *, int); 451 | int CDECL lame_get_VBR_max_bitrate_kbps(const lame_global_flags *); 452 | 453 | /* 454 | 1=strictly enforce VBR_min_bitrate. Normally it will be violated for 455 | analog silence 456 | */ 457 | int CDECL lame_set_VBR_hard_min(lame_global_flags *, int); 458 | int CDECL lame_get_VBR_hard_min(const lame_global_flags *); 459 | 460 | /* for preset */ 461 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 462 | #else 463 | int CDECL lame_set_preset_expopts(lame_global_flags *, int); 464 | #endif 465 | 466 | /******************************************************************** 467 | * Filtering control 468 | ***********************************************************************/ 469 | /* freq in Hz to apply lowpass. Default = 0 = lame chooses. -1 = disabled */ 470 | int CDECL lame_set_lowpassfreq(lame_global_flags *, int); 471 | int CDECL lame_get_lowpassfreq(const lame_global_flags *); 472 | /* width of transition band, in Hz. Default = one polyphase filter band */ 473 | int CDECL lame_set_lowpasswidth(lame_global_flags *, int); 474 | int CDECL lame_get_lowpasswidth(const lame_global_flags *); 475 | 476 | /* freq in Hz to apply highpass. Default = 0 = lame chooses. -1 = disabled */ 477 | int CDECL lame_set_highpassfreq(lame_global_flags *, int); 478 | int CDECL lame_get_highpassfreq(const lame_global_flags *); 479 | /* width of transition band, in Hz. Default = one polyphase filter band */ 480 | int CDECL lame_set_highpasswidth(lame_global_flags *, int); 481 | int CDECL lame_get_highpasswidth(const lame_global_flags *); 482 | 483 | 484 | /******************************************************************** 485 | * psycho acoustics and other arguments which you should not change 486 | * unless you know what you are doing 487 | ***********************************************************************/ 488 | 489 | /* only use ATH for masking */ 490 | int CDECL lame_set_ATHonly(lame_global_flags *, int); 491 | int CDECL lame_get_ATHonly(const lame_global_flags *); 492 | 493 | /* only use ATH for short blocks */ 494 | int CDECL lame_set_ATHshort(lame_global_flags *, int); 495 | int CDECL lame_get_ATHshort(const lame_global_flags *); 496 | 497 | /* disable ATH */ 498 | int CDECL lame_set_noATH(lame_global_flags *, int); 499 | int CDECL lame_get_noATH(const lame_global_flags *); 500 | 501 | /* select ATH formula */ 502 | int CDECL lame_set_ATHtype(lame_global_flags *, int); 503 | int CDECL lame_get_ATHtype(const lame_global_flags *); 504 | 505 | /* lower ATH by this many db */ 506 | int CDECL lame_set_ATHlower(lame_global_flags *, float); 507 | float CDECL lame_get_ATHlower(const lame_global_flags *); 508 | 509 | /* select ATH adaptive adjustment type */ 510 | int CDECL lame_set_athaa_type( lame_global_flags *, int); 511 | int CDECL lame_get_athaa_type( const lame_global_flags *); 512 | 513 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 514 | #else 515 | /* select the loudness approximation used by the ATH adaptive auto-leveling */ 516 | int CDECL lame_set_athaa_loudapprox( lame_global_flags *, int); 517 | int CDECL lame_get_athaa_loudapprox( const lame_global_flags *); 518 | #endif 519 | 520 | /* adjust (in dB) the point below which adaptive ATH level adjustment occurs */ 521 | int CDECL lame_set_athaa_sensitivity( lame_global_flags *, float); 522 | float CDECL lame_get_athaa_sensitivity( const lame_global_flags* ); 523 | 524 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 525 | #else 526 | /* OBSOLETE: predictability limit (ISO tonality formula) */ 527 | int CDECL lame_set_cwlimit(lame_global_flags *, int); 528 | int CDECL lame_get_cwlimit(const lame_global_flags *); 529 | #endif 530 | 531 | /* 532 | allow blocktypes to differ between channels? 533 | default: 0 for jstereo, 1 for stereo 534 | */ 535 | int CDECL lame_set_allow_diff_short(lame_global_flags *, int); 536 | int CDECL lame_get_allow_diff_short(const lame_global_flags *); 537 | 538 | /* use temporal masking effect (default = 1) */ 539 | int CDECL lame_set_useTemporal(lame_global_flags *, int); 540 | int CDECL lame_get_useTemporal(const lame_global_flags *); 541 | 542 | /* use temporal masking effect (default = 1) */ 543 | int CDECL lame_set_interChRatio(lame_global_flags *, float); 544 | float CDECL lame_get_interChRatio(const lame_global_flags *); 545 | 546 | /* disable short blocks */ 547 | int CDECL lame_set_no_short_blocks(lame_global_flags *, int); 548 | int CDECL lame_get_no_short_blocks(const lame_global_flags *); 549 | 550 | /* force short blocks */ 551 | int CDECL lame_set_force_short_blocks(lame_global_flags *, int); 552 | int CDECL lame_get_force_short_blocks(const lame_global_flags *); 553 | 554 | /* Input PCM is emphased PCM (for instance from one of the rarely 555 | emphased CDs), it is STRONGLY not recommended to use this, because 556 | psycho does not take it into account, and last but not least many decoders 557 | ignore these bits */ 558 | int CDECL lame_set_emphasis(lame_global_flags *, int); 559 | int CDECL lame_get_emphasis(const lame_global_flags *); 560 | 561 | 562 | 563 | /************************************************************************/ 564 | /* internal variables, cannot be set... */ 565 | /* provided because they may be of use to calling application */ 566 | /************************************************************************/ 567 | /* version 0=MPEG-2 1=MPEG-1 (2=MPEG-2.5) */ 568 | int CDECL lame_get_version(const lame_global_flags *); 569 | 570 | /* encoder delay */ 571 | int CDECL lame_get_encoder_delay(const lame_global_flags *); 572 | 573 | /* 574 | padding appended to the input to make sure decoder can fully decode 575 | all input. Note that this value can only be calculated during the 576 | call to lame_encoder_flush(). Before lame_encoder_flush() has 577 | been called, the value of encoder_padding = 0. 578 | */ 579 | int CDECL lame_get_encoder_padding(const lame_global_flags *); 580 | 581 | /* size of MPEG frame */ 582 | int CDECL lame_get_framesize(const lame_global_flags *); 583 | 584 | /* number of PCM samples buffered, but not yet encoded to mp3 data. */ 585 | int CDECL lame_get_mf_samples_to_encode( const lame_global_flags* gfp ); 586 | 587 | /* 588 | size (bytes) of mp3 data buffered, but not yet encoded. 589 | this is the number of bytes which would be output by a call to 590 | lame_encode_flush_nogap. NOTE: lame_encode_flush() will return 591 | more bytes than this because it will encode the reamining buffered 592 | PCM samples before flushing the mp3 buffers. 593 | */ 594 | int CDECL lame_get_size_mp3buffer( const lame_global_flags* gfp ); 595 | 596 | /* number of frames encoded so far */ 597 | int CDECL lame_get_frameNum(const lame_global_flags *); 598 | 599 | /* 600 | lame's estimate of the total number of frames to be encoded 601 | only valid if calling program set num_samples 602 | */ 603 | int CDECL lame_get_totalframes(const lame_global_flags *); 604 | 605 | /* RadioGain value. Multiplied by 10 and rounded to the nearest. */ 606 | int CDECL lame_get_RadioGain(const lame_global_flags *); 607 | 608 | /* AudiophileGain value. Multipled by 10 and rounded to the nearest. */ 609 | int CDECL lame_get_AudiophileGain(const lame_global_flags *); 610 | 611 | /* the peak sample */ 612 | float CDECL lame_get_PeakSample(const lame_global_flags *); 613 | 614 | /* Gain change required for preventing clipping. The value is correct only if 615 | peak sample searching was enabled. If negative then the waveform 616 | already does not clip. The value is multiplied by 10 and rounded up. */ 617 | int CDECL lame_get_noclipGainChange(const lame_global_flags *); 618 | 619 | /* user-specified scale factor required for preventing clipping. Value is 620 | correct only if peak sample searching was enabled and no user-specified 621 | scaling was performed. If negative then either the waveform already does 622 | not clip or the value cannot be determined */ 623 | float CDECL lame_get_noclipScale(const lame_global_flags *); 624 | 625 | /* returns the limit of PCM samples, which one can pass in an encode call 626 | under the constrain of a provided buffer of size buffer_size */ 627 | int CDECL lame_get_maximum_number_of_samples(lame_t gfp, size_t buffer_size); 628 | 629 | 630 | 631 | 632 | /* 633 | * REQUIRED: 634 | * sets more internal configuration based on data provided above. 635 | * returns -1 if something failed. 636 | */ 637 | int CDECL lame_init_params(lame_global_flags *); 638 | 639 | 640 | /* 641 | * OPTIONAL: 642 | * get the version number, in a string. of the form: 643 | * "3.63 (beta)" or just "3.63". 644 | */ 645 | const char* CDECL get_lame_version ( void ); 646 | const char* CDECL get_lame_short_version ( void ); 647 | const char* CDECL get_lame_very_short_version ( void ); 648 | const char* CDECL get_psy_version ( void ); 649 | const char* CDECL get_lame_url ( void ); 650 | const char* CDECL get_lame_os_bitness ( void ); 651 | 652 | /* 653 | * OPTIONAL: 654 | * get the version numbers in numerical form. 655 | */ 656 | typedef struct { 657 | /* generic LAME version */ 658 | int major; 659 | int minor; 660 | int alpha; /* 0 if not an alpha version */ 661 | int beta; /* 0 if not a beta version */ 662 | 663 | /* version of the psy model */ 664 | int psy_major; 665 | int psy_minor; 666 | int psy_alpha; /* 0 if not an alpha version */ 667 | int psy_beta; /* 0 if not a beta version */ 668 | 669 | /* compile time features */ 670 | const char *features; /* Don't make assumptions about the contents! */ 671 | } lame_version_t; 672 | void CDECL get_lame_version_numerical(lame_version_t *); 673 | 674 | 675 | /* 676 | * OPTIONAL: 677 | * print internal lame configuration to message handler 678 | */ 679 | void CDECL lame_print_config(const lame_global_flags* gfp); 680 | 681 | void CDECL lame_print_internals( const lame_global_flags *gfp); 682 | 683 | 684 | /* 685 | * input pcm data, output (maybe) mp3 frames. 686 | * This routine handles all buffering, resampling and filtering for you. 687 | * 688 | * return code number of bytes output in mp3buf. Can be 0 689 | * -1: mp3buf was too small 690 | * -2: malloc() problem 691 | * -3: lame_init_params() not called 692 | * -4: psycho acoustic problems 693 | * 694 | * The required mp3buf_size can be computed from num_samples, 695 | * samplerate and encoding rate, but here is a worst case estimate: 696 | * 697 | * mp3buf_size in bytes = 1.25*num_samples + 7200 698 | * 699 | * I think a tighter bound could be: (mt, March 2000) 700 | * MPEG1: 701 | * num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512 702 | * MPEG2: 703 | * num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256 704 | * 705 | * but test first if you use that! 706 | * 707 | * set mp3buf_size = 0 and LAME will not check if mp3buf_size is 708 | * large enough. 709 | * 710 | * NOTE: 711 | * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels 712 | * will be averaged into the L channel before encoding only the L channel 713 | * This will overwrite the data in buffer_l[] and buffer_r[]. 714 | * 715 | */ 716 | int CDECL lame_encode_buffer ( 717 | lame_global_flags* gfp, /* global context handle */ 718 | const short int buffer_l [], /* PCM data for left channel */ 719 | const short int buffer_r [], /* PCM data for right channel */ 720 | const int nsamples, /* number of samples per channel */ 721 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 722 | const int mp3buf_size ); /* number of valid octets in this 723 | stream */ 724 | 725 | /* 726 | * as above, but input has L & R channel data interleaved. 727 | * NOTE: 728 | * num_samples = number of samples in the L (or R) 729 | * channel, not the total number of samples in pcm[] 730 | */ 731 | int CDECL lame_encode_buffer_interleaved( 732 | lame_global_flags* gfp, /* global context handlei */ 733 | short int pcm[], /* PCM data for left and right 734 | channel, interleaved */ 735 | int num_samples, /* number of samples per channel, 736 | _not_ number of samples in 737 | pcm[] */ 738 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 739 | int mp3buf_size ); /* number of valid octets in this 740 | stream */ 741 | 742 | 743 | /* as lame_encode_buffer, but for 'float's. 744 | * !! NOTE: !! data must still be scaled to be in the same range as 745 | * short int, +/- 32768 746 | */ 747 | int CDECL lame_encode_buffer_float( 748 | lame_global_flags* gfp, /* global context handle */ 749 | const float pcm_l [], /* PCM data for left channel */ 750 | const float pcm_r [], /* PCM data for right channel */ 751 | const int nsamples, /* number of samples per channel */ 752 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 753 | const int mp3buf_size ); /* number of valid octets in this 754 | stream */ 755 | 756 | /* as lame_encode_buffer, but for 'float's. 757 | * !! NOTE: !! data must be scaled to +/- 1 full scale 758 | */ 759 | int CDECL lame_encode_buffer_ieee_float( 760 | lame_t gfp, 761 | const float pcm_l [], /* PCM data for left channel */ 762 | const float pcm_r [], /* PCM data for right channel */ 763 | const int nsamples, 764 | unsigned char * mp3buf, 765 | const int mp3buf_size); 766 | int CDECL lame_encode_buffer_interleaved_ieee_float( 767 | lame_t gfp, 768 | const float pcm[], /* PCM data for left and right 769 | channel, interleaved */ 770 | const int nsamples, 771 | unsigned char * mp3buf, 772 | const int mp3buf_size); 773 | 774 | /* as lame_encode_buffer, but for 'double's. 775 | * !! NOTE: !! data must be scaled to +/- 1 full scale 776 | */ 777 | int CDECL lame_encode_buffer_ieee_double( 778 | lame_t gfp, 779 | const double pcm_l [], /* PCM data for left channel */ 780 | const double pcm_r [], /* PCM data for right channel */ 781 | const int nsamples, 782 | unsigned char * mp3buf, 783 | const int mp3buf_size); 784 | int CDECL lame_encode_buffer_interleaved_ieee_double( 785 | lame_t gfp, 786 | const double pcm[], /* PCM data for left and right 787 | channel, interleaved */ 788 | const int nsamples, 789 | unsigned char * mp3buf, 790 | const int mp3buf_size); 791 | 792 | /* as lame_encode_buffer, but for long's 793 | * !! NOTE: !! data must still be scaled to be in the same range as 794 | * short int, +/- 32768 795 | * 796 | * This scaling was a mistake (doesn't allow one to exploit full 797 | * precision of type 'long'. Use lame_encode_buffer_long2() instead. 798 | * 799 | */ 800 | int CDECL lame_encode_buffer_long( 801 | lame_global_flags* gfp, /* global context handle */ 802 | const long buffer_l [], /* PCM data for left channel */ 803 | const long buffer_r [], /* PCM data for right channel */ 804 | const int nsamples, /* number of samples per channel */ 805 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 806 | const int mp3buf_size ); /* number of valid octets in this 807 | stream */ 808 | 809 | /* Same as lame_encode_buffer_long(), but with correct scaling. 810 | * !! NOTE: !! data must still be scaled to be in the same range as 811 | * type 'long'. Data should be in the range: +/- 2^(8*size(long)-1) 812 | * 813 | */ 814 | int CDECL lame_encode_buffer_long2( 815 | lame_global_flags* gfp, /* global context handle */ 816 | const long buffer_l [], /* PCM data for left channel */ 817 | const long buffer_r [], /* PCM data for right channel */ 818 | const int nsamples, /* number of samples per channel */ 819 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 820 | const int mp3buf_size ); /* number of valid octets in this 821 | stream */ 822 | 823 | /* as lame_encode_buffer, but for int's 824 | * !! NOTE: !! input should be scaled to the maximum range of 'int' 825 | * If int is 4 bytes, then the values should range from 826 | * +/- 2147483648. 827 | * 828 | * This routine does not (and cannot, without loosing precision) use 829 | * the same scaling as the rest of the lame_encode_buffer() routines. 830 | * 831 | */ 832 | int CDECL lame_encode_buffer_int( 833 | lame_global_flags* gfp, /* global context handle */ 834 | const int buffer_l [], /* PCM data for left channel */ 835 | const int buffer_r [], /* PCM data for right channel */ 836 | const int nsamples, /* number of samples per channel */ 837 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 838 | const int mp3buf_size ); /* number of valid octets in this 839 | stream */ 840 | 841 | /* 842 | * as above, but for interleaved data. 843 | * !! NOTE: !! data must still be scaled to be in the same range as 844 | * type 'int32_t'. Data should be in the range: +/- 2^(8*size(int32_t)-1) 845 | * NOTE: 846 | * num_samples = number of samples in the L (or R) 847 | * channel, not the total number of samples in pcm[] 848 | */ 849 | int 850 | lame_encode_buffer_interleaved_int( 851 | lame_t gfp, 852 | const int pcm [], /* PCM data for left and right 853 | channel, interleaved */ 854 | const int nsamples, /* number of samples per channel, 855 | _not_ number of samples in 856 | pcm[] */ 857 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 858 | const int mp3buf_size ); /* number of valid octets in this 859 | stream */ 860 | 861 | 862 | 863 | /* 864 | * REQUIRED: 865 | * lame_encode_flush will flush the intenal PCM buffers, padding with 866 | * 0's to make sure the final frame is complete, and then flush 867 | * the internal MP3 buffers, and thus may return a 868 | * final few mp3 frames. 'mp3buf' should be at least 7200 bytes long 869 | * to hold all possible emitted data. 870 | * 871 | * will also write id3v1 tags (if any) into the bitstream 872 | * 873 | * return code = number of bytes output to mp3buf. Can be 0 874 | */ 875 | int CDECL lame_encode_flush( 876 | lame_global_flags * gfp, /* global context handle */ 877 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 878 | int size); /* number of valid octets in this stream */ 879 | 880 | /* 881 | * OPTIONAL: 882 | * lame_encode_flush_nogap will flush the internal mp3 buffers and pad 883 | * the last frame with ancillary data so it is a complete mp3 frame. 884 | * 885 | * 'mp3buf' should be at least 7200 bytes long 886 | * to hold all possible emitted data. 887 | * 888 | * After a call to this routine, the outputed mp3 data is complete, but 889 | * you may continue to encode new PCM samples and write future mp3 data 890 | * to a different file. The two mp3 files will play back with no gaps 891 | * if they are concatenated together. 892 | * 893 | * This routine will NOT write id3v1 tags into the bitstream. 894 | * 895 | * return code = number of bytes output to mp3buf. Can be 0 896 | */ 897 | int CDECL lame_encode_flush_nogap( 898 | lame_global_flags * gfp, /* global context handle */ 899 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 900 | int size); /* number of valid octets in this stream */ 901 | 902 | /* 903 | * OPTIONAL: 904 | * Normally, this is called by lame_init_params(). It writes id3v2 and 905 | * Xing headers into the front of the bitstream, and sets frame counters 906 | * and bitrate histogram data to 0. You can also call this after 907 | * lame_encode_flush_nogap(). 908 | */ 909 | int CDECL lame_init_bitstream( 910 | lame_global_flags * gfp); /* global context handle */ 911 | 912 | 913 | 914 | /* 915 | * OPTIONAL: some simple statistics 916 | * a bitrate histogram to visualize the distribution of used frame sizes 917 | * a stereo mode histogram to visualize the distribution of used stereo 918 | * modes, useful in joint-stereo mode only 919 | * 0: LR left-right encoded 920 | * 1: LR-I left-right and intensity encoded (currently not supported) 921 | * 2: MS mid-side encoded 922 | * 3: MS-I mid-side and intensity encoded (currently not supported) 923 | * 924 | * attention: don't call them after lame_encode_finish 925 | * suggested: lame_encode_flush -> lame_*_hist -> lame_close 926 | */ 927 | 928 | void CDECL lame_bitrate_hist( 929 | const lame_global_flags * gfp, 930 | int bitrate_count[14] ); 931 | void CDECL lame_bitrate_kbps( 932 | const lame_global_flags * gfp, 933 | int bitrate_kbps [14] ); 934 | void CDECL lame_stereo_mode_hist( 935 | const lame_global_flags * gfp, 936 | int stereo_mode_count[4] ); 937 | 938 | void CDECL lame_bitrate_stereo_mode_hist ( 939 | const lame_global_flags * gfp, 940 | int bitrate_stmode_count[14][4] ); 941 | 942 | void CDECL lame_block_type_hist ( 943 | const lame_global_flags * gfp, 944 | int btype_count[6] ); 945 | 946 | void CDECL lame_bitrate_block_type_hist ( 947 | const lame_global_flags * gfp, 948 | int bitrate_btype_count[14][6] ); 949 | 950 | #if (DEPRECATED_OR_OBSOLETE_CODE_REMOVED && 0) 951 | #else 952 | /* 953 | * OPTIONAL: 954 | * lame_mp3_tags_fid will rewrite a Xing VBR tag to the mp3 file with file 955 | * pointer fid. These calls perform forward and backwards seeks, so make 956 | * sure fid is a real file. Make sure lame_encode_flush has been called, 957 | * and all mp3 data has been written to the file before calling this 958 | * function. 959 | * NOTE: 960 | * if VBR tags are turned off by the user, or turned off by LAME because 961 | * the output is not a regular file, this call does nothing 962 | * NOTE: 963 | * LAME wants to read from the file to skip an optional ID3v2 tag, so 964 | * make sure you opened the file for writing and reading. 965 | * NOTE: 966 | * You can call lame_get_lametag_frame instead, if you want to insert 967 | * the lametag yourself. 968 | */ 969 | void CDECL lame_mp3_tags_fid(lame_global_flags *, FILE* fid); 970 | #endif 971 | 972 | /* 973 | * OPTIONAL: 974 | * lame_get_lametag_frame copies the final LAME-tag into 'buffer'. 975 | * The function returns the number of bytes copied into buffer, or 976 | * the required buffer size, if the provided buffer is too small. 977 | * Function failed, if the return value is larger than 'size'! 978 | * Make sure lame_encode flush has been called before calling this function. 979 | * NOTE: 980 | * if VBR tags are turned off by the user, or turned off by LAME, 981 | * this call does nothing and returns 0. 982 | * NOTE: 983 | * LAME inserted an empty frame in the beginning of mp3 audio data, 984 | * which you have to replace by the final LAME-tag frame after encoding. 985 | * In case there is no ID3v2 tag, usually this frame will be the very first 986 | * data in your mp3 file. If you put some other leading data into your 987 | * file, you'll have to do some bookkeeping about where to write this buffer. 988 | */ 989 | size_t CDECL lame_get_lametag_frame( 990 | const lame_global_flags *, unsigned char* buffer, size_t size); 991 | 992 | /* 993 | * REQUIRED: 994 | * final call to free all remaining buffers 995 | */ 996 | int CDECL lame_close (lame_global_flags *); 997 | 998 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 999 | #else 1000 | /* 1001 | * OBSOLETE: 1002 | * lame_encode_finish combines lame_encode_flush() and lame_close() in 1003 | * one call. However, once this call is made, the statistics routines 1004 | * will no longer work because the data will have been cleared, and 1005 | * lame_mp3_tags_fid() cannot be called to add data to the VBR header 1006 | */ 1007 | int CDECL lame_encode_finish( 1008 | lame_global_flags* gfp, 1009 | unsigned char* mp3buf, 1010 | int size ); 1011 | #endif 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | /********************************************************************* 1019 | * 1020 | * decoding 1021 | * 1022 | * a simple interface to mpglib, part of mpg123, is also included if 1023 | * libmp3lame is compiled with HAVE_MPGLIB 1024 | * 1025 | *********************************************************************/ 1026 | 1027 | struct hip_global_struct; 1028 | typedef struct hip_global_struct hip_global_flags; 1029 | typedef hip_global_flags *hip_t; 1030 | 1031 | 1032 | typedef struct { 1033 | int header_parsed; /* 1 if header was parsed and following data was 1034 | computed */ 1035 | int stereo; /* number of channels */ 1036 | int samplerate; /* sample rate */ 1037 | int bitrate; /* bitrate */ 1038 | int mode; /* mp3 frame type */ 1039 | int mode_ext; /* mp3 frame type */ 1040 | int framesize; /* number of samples per mp3 frame */ 1041 | 1042 | /* this data is only computed if mpglib detects a Xing VBR header */ 1043 | unsigned long nsamp; /* number of samples in mp3 file. */ 1044 | int totalframes; /* total number of frames in mp3 file */ 1045 | 1046 | /* this data is not currently computed by the mpglib routines */ 1047 | int framenum; /* frames decoded counter */ 1048 | } mp3data_struct; 1049 | 1050 | /* required call to initialize decoder */ 1051 | hip_t CDECL hip_decode_init(void); 1052 | 1053 | /* cleanup call to exit decoder */ 1054 | int CDECL hip_decode_exit(hip_t gfp); 1055 | 1056 | /* HIP reporting functions */ 1057 | void CDECL hip_set_errorf(hip_t gfp, lame_report_function f); 1058 | void CDECL hip_set_debugf(hip_t gfp, lame_report_function f); 1059 | void CDECL hip_set_msgf (hip_t gfp, lame_report_function f); 1060 | 1061 | /********************************************************************* 1062 | * input 1 mp3 frame, output (maybe) pcm data. 1063 | * 1064 | * nout = hip_decode(hip, mp3buf,len,pcm_l,pcm_r); 1065 | * 1066 | * input: 1067 | * len : number of bytes of mp3 data in mp3buf 1068 | * mp3buf[len] : mp3 data to be decoded 1069 | * 1070 | * output: 1071 | * nout: -1 : decoding error 1072 | * 0 : need more data before we can complete the decode 1073 | * >0 : returned 'nout' samples worth of data in pcm_l,pcm_r 1074 | * pcm_l[nout] : left channel data 1075 | * pcm_r[nout] : right channel data 1076 | * 1077 | *********************************************************************/ 1078 | int CDECL hip_decode( hip_t gfp 1079 | , unsigned char * mp3buf 1080 | , size_t len 1081 | , short pcm_l[] 1082 | , short pcm_r[] 1083 | ); 1084 | 1085 | /* same as hip_decode, and also returns mp3 header data */ 1086 | int CDECL hip_decode_headers( hip_t gfp 1087 | , unsigned char* mp3buf 1088 | , size_t len 1089 | , short pcm_l[] 1090 | , short pcm_r[] 1091 | , mp3data_struct* mp3data 1092 | ); 1093 | 1094 | /* same as hip_decode, but returns at most one frame */ 1095 | int CDECL hip_decode1( hip_t gfp 1096 | , unsigned char* mp3buf 1097 | , size_t len 1098 | , short pcm_l[] 1099 | , short pcm_r[] 1100 | ); 1101 | 1102 | /* same as hip_decode1, but returns at most one frame and mp3 header data */ 1103 | int CDECL hip_decode1_headers( hip_t gfp 1104 | , unsigned char* mp3buf 1105 | , size_t len 1106 | , short pcm_l[] 1107 | , short pcm_r[] 1108 | , mp3data_struct* mp3data 1109 | ); 1110 | 1111 | /* same as hip_decode1_headers, but also returns enc_delay and enc_padding 1112 | from VBR Info tag, (-1 if no info tag was found) */ 1113 | int CDECL hip_decode1_headersB( hip_t gfp 1114 | , unsigned char* mp3buf 1115 | , size_t len 1116 | , short pcm_l[] 1117 | , short pcm_r[] 1118 | , mp3data_struct* mp3data 1119 | , int *enc_delay 1120 | , int *enc_padding 1121 | ); 1122 | 1123 | 1124 | 1125 | /* OBSOLETE: 1126 | * lame_decode... functions are there to keep old code working 1127 | * but it is strongly recommended to replace calls by hip_decode... 1128 | * function calls, see above. 1129 | */ 1130 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 1131 | #else 1132 | int CDECL lame_decode_init(void); 1133 | int CDECL lame_decode( 1134 | unsigned char * mp3buf, 1135 | int len, 1136 | short pcm_l[], 1137 | short pcm_r[] ); 1138 | int CDECL lame_decode_headers( 1139 | unsigned char* mp3buf, 1140 | int len, 1141 | short pcm_l[], 1142 | short pcm_r[], 1143 | mp3data_struct* mp3data ); 1144 | int CDECL lame_decode1( 1145 | unsigned char* mp3buf, 1146 | int len, 1147 | short pcm_l[], 1148 | short pcm_r[] ); 1149 | int CDECL lame_decode1_headers( 1150 | unsigned char* mp3buf, 1151 | int len, 1152 | short pcm_l[], 1153 | short pcm_r[], 1154 | mp3data_struct* mp3data ); 1155 | int CDECL lame_decode1_headersB( 1156 | unsigned char* mp3buf, 1157 | int len, 1158 | short pcm_l[], 1159 | short pcm_r[], 1160 | mp3data_struct* mp3data, 1161 | int *enc_delay, 1162 | int *enc_padding ); 1163 | int CDECL lame_decode_exit(void); 1164 | 1165 | #endif /* obsolete lame_decode API calls */ 1166 | 1167 | 1168 | /********************************************************************* 1169 | * 1170 | * id3tag stuff 1171 | * 1172 | *********************************************************************/ 1173 | 1174 | /* 1175 | * id3tag.h -- Interface to write ID3 version 1 and 2 tags. 1176 | * 1177 | * Copyright (C) 2000 Don Melton. 1178 | * 1179 | * This library is free software; you can redistribute it and/or 1180 | * modify it under the terms of the GNU Library General Public 1181 | * License as published by the Free Software Foundation; either 1182 | * version 2 of the License, or (at your option) any later version. 1183 | * 1184 | * This library is distributed in the hope that it will be useful, 1185 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 1186 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1187 | * Library General Public License for more details. 1188 | * 1189 | * You should have received a copy of the GNU Library General Public 1190 | * License along with this library; if not, write to the Free Software 1191 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 1192 | */ 1193 | 1194 | /* utility to obtain alphabetically sorted list of genre names with numbers */ 1195 | void CDECL id3tag_genre_list( 1196 | void (*handler)(int, const char *, void *), 1197 | void* cookie); 1198 | 1199 | void CDECL id3tag_init (lame_t gfp); 1200 | 1201 | /* force addition of version 2 tag */ 1202 | void CDECL id3tag_add_v2 (lame_t gfp); 1203 | 1204 | /* add only a version 1 tag */ 1205 | void CDECL id3tag_v1_only (lame_t gfp); 1206 | 1207 | /* add only a version 2 tag */ 1208 | void CDECL id3tag_v2_only (lame_t gfp); 1209 | 1210 | /* pad version 1 tag with spaces instead of nulls */ 1211 | void CDECL id3tag_space_v1 (lame_t gfp); 1212 | 1213 | /* pad version 2 tag with extra 128 bytes */ 1214 | void CDECL id3tag_pad_v2 (lame_t gfp); 1215 | 1216 | /* pad version 2 tag with extra n bytes */ 1217 | void CDECL id3tag_set_pad (lame_t gfp, size_t n); 1218 | 1219 | void CDECL id3tag_set_title(lame_t gfp, const char* title); 1220 | void CDECL id3tag_set_artist(lame_t gfp, const char* artist); 1221 | void CDECL id3tag_set_album(lame_t gfp, const char* album); 1222 | void CDECL id3tag_set_year(lame_t gfp, const char* year); 1223 | void CDECL id3tag_set_comment(lame_t gfp, const char* comment); 1224 | 1225 | /* return -1 result if track number is out of ID3v1 range 1226 | and ignored for ID3v1 */ 1227 | int CDECL id3tag_set_track(lame_t gfp, const char* track); 1228 | 1229 | /* return non-zero result if genre name or number is invalid 1230 | result 0: OK 1231 | result -1: genre number out of range 1232 | result -2: no valid ID3v1 genre name, mapped to ID3v1 'Other' 1233 | but taken as-is for ID3v2 genre tag */ 1234 | int CDECL id3tag_set_genre(lame_t gfp, const char* genre); 1235 | 1236 | /* return non-zero result if field name is invalid */ 1237 | int CDECL id3tag_set_fieldvalue(lame_t gfp, const char* fieldvalue); 1238 | 1239 | /* return non-zero result if image type is invalid */ 1240 | int CDECL id3tag_set_albumart(lame_t gfp, const char* image, size_t size); 1241 | 1242 | /* lame_get_id3v1_tag copies ID3v1 tag into buffer. 1243 | * Function returns number of bytes copied into buffer, or number 1244 | * of bytes rquired if buffer 'size' is too small. 1245 | * Function fails, if returned value is larger than 'size'. 1246 | * NOTE: 1247 | * This functions does nothing, if user/LAME disabled ID3v1 tag. 1248 | */ 1249 | size_t CDECL lame_get_id3v1_tag(lame_t gfp, unsigned char* buffer, size_t size); 1250 | 1251 | /* lame_get_id3v2_tag copies ID3v2 tag into buffer. 1252 | * Function returns number of bytes copied into buffer, or number 1253 | * of bytes rquired if buffer 'size' is too small. 1254 | * Function fails, if returned value is larger than 'size'. 1255 | * NOTE: 1256 | * This functions does nothing, if user/LAME disabled ID3v2 tag. 1257 | */ 1258 | size_t CDECL lame_get_id3v2_tag(lame_t gfp, unsigned char* buffer, size_t size); 1259 | 1260 | /* normaly lame_init_param writes ID3v2 tags into the audio stream 1261 | * Call lame_set_write_id3tag_automatic(gfp, 0) before lame_init_param 1262 | * to turn off this behaviour and get ID3v2 tag with above function 1263 | * write it yourself into your file. 1264 | */ 1265 | void CDECL lame_set_write_id3tag_automatic(lame_global_flags * gfp, int); 1266 | int CDECL lame_get_write_id3tag_automatic(lame_global_flags const* gfp); 1267 | 1268 | /* experimental */ 1269 | int CDECL id3tag_set_textinfo_latin1(lame_t gfp, char const *id, char const *text); 1270 | 1271 | /* experimental */ 1272 | int CDECL id3tag_set_comment_latin1(lame_t gfp, char const *lang, char const *desc, char const *text); 1273 | 1274 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 1275 | #else 1276 | /* experimental */ 1277 | int CDECL id3tag_set_textinfo_ucs2(lame_t gfp, char const *id, unsigned short const *text); 1278 | 1279 | /* experimental */ 1280 | int CDECL id3tag_set_comment_ucs2(lame_t gfp, char const *lang, 1281 | unsigned short const *desc, unsigned short const *text); 1282 | 1283 | /* experimental */ 1284 | int CDECL id3tag_set_fieldvalue_ucs2(lame_t gfp, const unsigned short *fieldvalue); 1285 | #endif 1286 | 1287 | /* experimental */ 1288 | int CDECL id3tag_set_fieldvalue_utf16(lame_t gfp, const unsigned short *fieldvalue); 1289 | 1290 | /* experimental */ 1291 | int CDECL id3tag_set_textinfo_utf16(lame_t gfp, char const *id, unsigned short const *text); 1292 | 1293 | /* experimental */ 1294 | int CDECL id3tag_set_comment_utf16(lame_t gfp, char const *lang, unsigned short const *desc, unsigned short const *text); 1295 | 1296 | 1297 | /*********************************************************************** 1298 | * 1299 | * list of valid bitrates [kbps] & sample frequencies [Hz]. 1300 | * first index: 0: MPEG-2 values (sample frequencies 16...24 kHz) 1301 | * 1: MPEG-1 values (sample frequencies 32...48 kHz) 1302 | * 2: MPEG-2.5 values (sample frequencies 8...12 kHz) 1303 | ***********************************************************************/ 1304 | 1305 | extern const int bitrate_table [3][16]; 1306 | extern const int samplerate_table [3][ 4]; 1307 | 1308 | /* access functions for use in DLL, global vars are not exported */ 1309 | int CDECL lame_get_bitrate(int mpeg_version, int table_index); 1310 | int CDECL lame_get_samplerate(int mpeg_version, int table_index); 1311 | 1312 | 1313 | /* maximum size of albumart image (128KB), which affects LAME_MAXMP3BUFFER 1314 | as well since lame_encode_buffer() also returns ID3v2 tag data */ 1315 | #define LAME_MAXALBUMART (128 * 1024) 1316 | 1317 | /* maximum size of mp3buffer needed if you encode at most 1152 samples for 1318 | each call to lame_encode_buffer. see lame_encode_buffer() below 1319 | (LAME_MAXMP3BUFFER is now obsolete) */ 1320 | #define LAME_MAXMP3BUFFER (16384 + LAME_MAXALBUMART) 1321 | 1322 | 1323 | typedef enum { 1324 | LAME_OKAY = 0, 1325 | LAME_NOERROR = 0, 1326 | LAME_GENERICERROR = -1, 1327 | LAME_NOMEM = -10, 1328 | LAME_BADBITRATE = -11, 1329 | LAME_BADSAMPFREQ = -12, 1330 | LAME_INTERNALERROR = -13, 1331 | 1332 | FRONTEND_READERROR = -80, 1333 | FRONTEND_WRITEERROR = -81, 1334 | FRONTEND_FILETOOLARGE = -82 1335 | 1336 | } lame_errorcodes_t; 1337 | 1338 | #if defined(__cplusplus) 1339 | } 1340 | #endif 1341 | #endif /* LAME_LAME_H */ 1342 | 1343 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/lame/libmp3lame.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/lame/libmp3lame.a -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TestAVFoundation 4 | // 5 | // Created by FlyOceanFish on 2018/5/2. 6 | // Copyright © 2018年 FlyOceanFish. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/test.aac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/test.aac -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/video.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/video.mp4 -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/女声.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/女声.mp3 -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/宿命者.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/宿命者.mp3 -------------------------------------------------------------------------------- /TestAVFoundation/TestAVFoundation/男声.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/TestAVFoundation/TestAVFoundation/男声.mp3 -------------------------------------------------------------------------------- /微信小视频截取.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/微信小视频截取.gif -------------------------------------------------------------------------------- /效果.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyOceanFish/StudyAVFoundation/3c0fe5fd0e94c0fb0e313581304bc4ebb91d56c1/效果.gif --------------------------------------------------------------------------------