123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064 |
- public enum createStickersModel: Int {
- case createStickersModelPoint = 1
- case createStickersModelSpeed = 2
- case createStickersModelOnlyMusic = 3
- }
- import BFCommonKit
- import Foundation
- import ObjectMapper
- import Photos
- import RealmSwift
- import UIKit
- class PQStuckPointEditerController: PQBaseViewController {
-
- var isExportVideosSuccess: Bool = false
-
- var isStuckPointDataSuccess: Bool = false
-
- var isSynchroMusicInfoSuccess: Bool = false
-
- var filters: Array = Array<ImageProcessingOperation>.init()
-
- var selectedTotalDuration: Float64 = 0
-
- var selectedDataCount: Int = 0
-
- var selectedImageDataCount: Int = 0
-
- var selectedPhotoData: [PHAsset]? {
- didSet {
- if selectedPhotoData != nil, (selectedPhotoData?.count ?? 0) > 0 {
- selectedMetarialData = Array<PQEditVisionTrackMaterialsModel>.init()
- selectedPhotoData?.forEach { phAsset in
- let metarialData = PQEditVisionTrackMaterialsModel()
- metarialData.asset = phAsset
- metarialData.width = Float(phAsset.pixelWidth)
- metarialData.itemWidth = Float(phAsset.pixelWidth)
- metarialData.height = Float(phAsset.pixelHeight)
- metarialData.itemHeight = Float(phAsset.pixelHeight)
- if phAsset.mediaType == .image {
- metarialData.type = "image"
- } else if phAsset.mediaType == .video {
- metarialData.type = "video"
- metarialData.duration = Float64(phAsset.duration)
- }
- metarialData.canvasFillType = phAsset.canvasFillType ?? ""
- metarialData.locationPath = phAsset.localPath ?? ""
- metarialData.selectedIndex = phAsset.selectedIndex ?? 1
- metarialData.originalData = phAsset.originalData
- selectedMetarialData?.append(metarialData)
- }
- }
- }
- }
- var selectedMetarialData: [PQEditVisionTrackMaterialsModel]?
-
- var stuckPointMusicData: PQVoiceModel?
-
- var projectModel: PQEditProjectModel = PQEditProjectModel()
-
- var draftProjectModel: PQEditProjectModel?
- var mStickers: [PQEditVisionTrackMaterialsModel]?
-
- var playeTimeRange: CMTimeRange = CMTimeRange()
-
- var firstFrameImage: UIImage?{
- didSet{
- if firstFrameImage != nil {
- self.playerView.layer.contents = firstFrameImage?.cgImage
- }
- }
- }
-
- var isReCreate: Bool = false
- public var reCreateVideoData: PQReCreateModel?
-
- var lastEditModelBtn: UIButton?
-
-
- var modelSpeed_maxSpeed: Float = 1.0
- var modelSpeed_minSpeed: Float = 1.0
-
- var modelPoint_speed:Float = 1.0
-
- var lastSpeedSelectIndex: Int = 0
-
- var lastJumpSpeedSelectIndex: Int = 0
-
- var lastCyclesSelectIndex: Int = -1
-
- var currentCreateStickersModel: createStickersModel = .createStickersModelSpeed
-
- var finallyStuckPoints: Array = Array<Float>.init()
- var finallyStuckPointsInt64: Array = Array<Int64>.init()
-
- var finallyUserAudioTime: Float = 0.0
-
-
-
- var stuckPointsTemp: Array = Array<Float>.init()
- var stuckPointsTempInt64: Array = Array<Int64>.init()
-
- lazy var nextBtn: UIButton = {
- let nextBtn = UIButton(type: .custom)
- nextBtn.frame = CGRect(x: cScreenWidth - 16 - cDefaultMargin * 6, y: cDevice_iPhoneStatusBarHei + (cDevice_iPhoneNavBarHei - cDefaultMargin * 3) / 2, width: cDefaultMargin * 6, height: cDefaultMargin * 3)
- nextBtn.setTitle("合成", for: .normal)
- nextBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
- nextBtn.addTarget(self, action: #selector(nextBtnClick(sender:)), for: .touchUpInside)
- nextBtn.backgroundColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
- nextBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#FFFFFF"), for: .normal)
- nextBtn.uxy_acceptEventInterval = 0.5
- nextBtn.addCorner(corner: 3)
- return nextBtn
- }()
-
- lazy var playerView: PQGPUImagePlayerView = {
- let playerView = PQGPUImagePlayerView(frame: .zero)
- playerView.backgroundColor = PQBFConfig.shared.styleBackGroundColor
- playerView.isShowLine = false
- playerView.showGaussianBlur = true
- playerView.pause()
- playerView.renderViewOnClickHandle = { [weak self] in
- self?.musicEditBGView.pausePlayer()
- }
- playerView.playerEmptyView.isHidden = true
- return playerView
- }()
-
- lazy var sustomSwitchView: PQCustomSwitchView = {
- let sustomSwitchView = PQCustomSwitchView(frame: CGRect(x: 16, y: 0, width: 180, height: 30), titles: ["慢节奏", "适中", "快节奏"], defaultIndex: stuckPointMusicData?.speed ?? 2)
- sustomSwitchView.switchChangeHandle = { [weak self] sender in
-
- self?.stuckPointMusicData?.speed = sender.tag
- self?.musicEditBGView.pausePlayer()
- self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.bgmInfo?.rhythmMusicSpeed = sender.tag
-
-
- self?.settingPlayerView()
-
- if self?.currentCreateStickersModel == .createStickersModelPoint {
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_selectMusicVideoRhythm, pageSource: .sp_stuck_previewSyncedUp, extParams: nil, remindmsg: "点击上报:选择节奏")
- } else if self?.currentCreateStickersModel == .createStickersModelSpeed {
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_selectSpeedRhythm, pageSource: .sp_stuck_previewSyncedUp, extParams: nil, remindmsg: "点击上报:选择节奏")
- } else if self?.currentCreateStickersModel == .createStickersModelOnlyMusic {
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_selectMusicVideoRepeatRhythm, pageSource: .sp_stuck_previewSyncedUp, extParams: nil, remindmsg: "点击上报:选择节奏")
- }
- }
- return sustomSwitchView
- }()
-
- lazy var stuckPointCuttingView: PQStuckPointCuttingView = {
- let stuckPointCuttingView = PQStuckPointCuttingView(frame: CGRect(x: 0, y: optionlineView.frame.minY - 85 - 28, width: view.frame.width, height: 80), duration: CGFloat(Float(stuckPointMusicData?.duration ?? "0") ?? 0), suggestRhythmStartTime: CGFloat(stuckPointMusicData?.suggestRhythmStartTime ?? 0))
-
- stuckPointCuttingView.videoDidBeginDrag = { [weak self] in
- BFLog(message: "开始划动")
- self?.playerView.pause()
- }
-
- stuckPointCuttingView.videoProgressDidChanged = { [weak self] progress in
- BFLog(message: "进度更新返回--progress = \(progress) \(String(describing: self?.playerView.mPlayeTimeRange))")
- }
-
- stuckPointCuttingView.videoDidEndDragging = { [weak self] type, startTime, endTime, progress in
- BFLog(1, message: "拖拽结束返回--type = \(type),startTime = \(startTime),endTime = \(endTime),progress = \(progress)")
- self?.playerView.pause()
- self?.musicEditBGView.pausePlayer()
-
- self?.stuckPointMusicData?.startTime = Float64(startTime)
- self?.stuckPointMusicData?.endTime = Float64(endTime)
-
- if type == 3 {
- if CMTimeGetSeconds(self?.playerView.mPlayeTimeRange?.end ?? .zero) == 0 {
- BFLog(message: "mPlayeTimeRange is error")
- return
- }
- let newBeginSconds = (Double(startTime) + (Double(endTime) - Double(startTime)) * Double(progress)) * 600
- BFLog(message: " newBeginSconds is \(newBeginSconds)")
- let seekTimeRange: CMTimeRange = CMTimeRange(start: CMTime(value: CMTimeValue(Int64(newBeginSconds)), timescale: 600), end:
- CMTime(value: CMTimeValue(Int64(endTime * 600)), timescale: 600))
- BFLog(message: "修改的开始 \(CMTimeGetSeconds(seekTimeRange.start)) 结束 \(CMTimeGetSeconds(seekTimeRange.end))")
-
- self?.playerView.configCache(beginTime: CMTimeGetSeconds(seekTimeRange.start))
- self?.playerView.play(pauseFirstFrame: false, playeTimeRange: seekTimeRange)
- } else {
-
- self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.out = Float64(endTime)
- self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.model_in = Float64(startTime)
- self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.timelineIn = Float64(startTime)
- self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.timelineOut = Float64(endTime)
- BFLog(message: "调整后总时长: \(endTime - startTime) startTime:\(startTime) endTime:\(endTime)")
-
- self?.playeTimeRange = CMTimeRange(start: CMTimeMakeWithSeconds(Float64(startTime), preferredTimescale: BASE_FILTER_TIMESCALE), end: CMTimeMakeWithSeconds(Float64(endTime), preferredTimescale: BASE_FILTER_TIMESCALE))
- self?.dealParameter(model: self?.currentCreateStickersModel ?? .createStickersModelSpeed)
- if((self?.finallyStuckPoints.count ?? 0) < 1){
- BFLog(message: "finallyStuckPoints data is error!!!!")
- return
- }
- DispatchQueue.global().async {
- let beginTime = Date()
- self?.mStickers = self?.createStickers(sections: self?.projectModel.sData?.sections ?? List(), inputSize: CGSize(width: CGFloat(self?.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self?.projectModel.sData?.videoMetaData?.videoHeight ?? 0)), model: self?.currentCreateStickersModel ?? .createStickersModelSpeed)
- DispatchQueue.main.async {
- self?.playerView.mStickers = self?.mStickers
- BFLog(message: "endTime is endTimeendTime \(Date().timeIntervalSince(beginTime))")
- self?.playerView.play(pauseFirstFrame: false, playeTimeRange: self!.playeTimeRange)
-
- self?.stuckPointCuttingView.videoDuration = CGFloat(self?.finallyUserAudioTime ?? 0)
- self?.stuckPointCuttingView.stuckPointStartTime = CGFloat(CMTimeGetSeconds(self?.playeTimeRange.start ?? .zero))
- self?.stuckPointCuttingView.stuckPointEndTime = CGFloat(CMTimeGetSeconds(self?.playeTimeRange.end ?? .zero))
- self?.stuckPointCuttingView.tatalTimeLabel.text = "\(Float64(CMTimeGetSeconds(self?.playeTimeRange.end ?? .zero) - CMTimeGetSeconds(self?.playeTimeRange.start ?? .zero)).formatDurationToHMS())"
- }
- }
- }
- }
- return stuckPointCuttingView
- }()
-
- lazy var pointEditRemindLab: UILabel = {
- let pointEditRemindLab = UILabel()
- pointEditRemindLab.backgroundColor = .clear
- pointEditRemindLab.textAlignment = .left
- pointEditRemindLab.font = UIFont.boldSystemFont(ofSize: 14)
- pointEditRemindLab.textColor = .black
- pointEditRemindLab.text = "卡点模式"
- return pointEditRemindLab
- }()
-
- lazy var speedTitleLab: UILabel = {
- let speedTitleLab = UILabel()
- speedTitleLab.backgroundColor = .clear
- speedTitleLab.textAlignment = .left
- speedTitleLab.font = UIFont.boldSystemFont(ofSize: 14)
- speedTitleLab.textColor = .black
- speedTitleLab.text = "节奏变化"
- return speedTitleLab
- }()
-
- lazy var pointEditBGView: UIView = {
- let pointEditBGView = UIView()
- pointEditBGView.backgroundColor = .clear
- return pointEditBGView
- }()
-
- lazy var musicEditBGView: PQSelecteMusicView = {
- let musicEditBGView = PQSelecteMusicView()
- musicEditBGView.backgroundColor = .clear
- musicEditBGView.isUserInteractionEnabled = true
- musicEditBGView.isHidden = true
- musicEditBGView.musicSearchBtn.addTarget(self, action: #selector(musicSearchBtnClick(sender:)), for: .touchUpInside)
- musicEditBGView.didSelectItemHandle = { [weak self] status in
- if status == .isSelected{
- if self?.playerView.status != .playing{
- self?.playerView.RenderViewOnclick()
- }
- }else{
- self?.playerView.pause()
- }
- }
- musicEditBGView.btnClickHandle = { [weak self] _, bgmData in
-
- self?.userstuckPointMusic(musicData: bgmData as? PQVoiceModel)
- }
- return musicEditBGView
- }()
-
- lazy var pointEditerBtn: UIButton = {
- let pointEdterBtn = UIButton(type: .custom)
- pointEdterBtn.setImage(UIImage().BF_Image(named: "pointEditerBtn_n"), for: .normal)
- pointEdterBtn.setImage(UIImage().BF_Image(named: "pointEditerBtn_h").withRenderingMode(.alwaysTemplate), for: .selected)
- pointEdterBtn.tintColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
- pointEdterBtn.addTarget(self, action: #selector(pointEditerBtnClick(sender:)), for: .touchUpInside)
- pointEdterBtn.isSelected = true
- pointEdterBtn.adjustsImageWhenHighlighted = false
- return pointEdterBtn
- }()
-
- lazy var musicEditerBtn: UIButton = {
- let musicEditerBtn = UIButton(type: .custom)
- musicEditerBtn.setImage(UIImage().BF_Image(named: "musicEditerBtn_n"), for: .normal)
- musicEditerBtn.setImage(UIImage().BF_Image(named: "musicEditerBtn_h").withRenderingMode(.alwaysTemplate), for: .selected)
- musicEditerBtn.tintColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
- musicEditerBtn.addTarget(self, action: #selector(musicEditerBtnClick(sender:)), for: .touchUpInside)
- musicEditerBtn.adjustsImageWhenHighlighted = false
- return musicEditerBtn
- }()
-
- lazy var speedStuckBtn: UIButton = {
- let speedStuckBtn = UIButton(type: .custom)
- speedStuckBtn.addTarget(self, action: #selector(editModelClick1(sender:)), for: .touchUpInside)
- speedStuckBtn.setTitle("快慢速卡点", for: .normal)
- speedStuckBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .regular)
- jumpPointBtn.backgroundColor = PQBFConfig.shared.pointEditNamalBackgroundColor
- speedStuckBtn.setTitleColor(UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue), for: .selected)
- speedStuckBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#959595"), for: .normal)
- speedStuckBtn.addCorner(corner: 5)
- speedStuckBtn.imagePosition(at: .top, space: 8)
- speedStuckBtn.tag = 1
- speedStuckBtn.adjustsImageWhenHighlighted = false
- speedStuckBtn.setImage(UIImage.moduleImage(named: PQBFConfig.shared.speedStuckBtnImage_N, moduleName: "BFFramework", isAssets: false), for: .normal)
- speedStuckBtn.setImage(UIImage.moduleImage(named: PQBFConfig.shared.speedStuckBtnImage_H, moduleName: "BFFramework", isAssets: false), for: .selected)
- return speedStuckBtn
- }()
-
- lazy var jumpPointBtn: UIButton = {
- let jumpPointBtn = UIButton(type: .custom)
-
- jumpPointBtn.setTitle("跳跃卡点", for: .normal)
- jumpPointBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .regular)
- jumpPointBtn.backgroundColor = PQBFConfig.shared.pointEditNamalBackgroundColor
- jumpPointBtn.setTitleColor(UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue), for: .selected)
- jumpPointBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#959595"), for: .normal)
- jumpPointBtn.imagePosition(at: .top, space: 8)
- jumpPointBtn.addCorner(corner: 5)
- jumpPointBtn.tag = 2
- jumpPointBtn.addTarget(self, action: #selector(editModelClick1(sender:)), for: .touchUpInside)
- jumpPointBtn.adjustsImageWhenHighlighted = false
-
- jumpPointBtn.setImage(UIImage.moduleImage(named: PQBFConfig.shared.jumpPointBtnImage_N, moduleName: "BFFramework", isAssets: false), for: .normal)
- jumpPointBtn.setImage(UIImage.moduleImage(named: PQBFConfig.shared.jumpPointBtnImage_H, moduleName: "BFFramework", isAssets: false), for: .selected)
- return jumpPointBtn
- }()
-
- lazy var onlyMusicBtn: UIButton = {
- let onlyMusicBtn = UIButton(type: .custom)
-
- onlyMusicBtn.setTitle("仅配乐", for: .normal)
- onlyMusicBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .regular)
- onlyMusicBtn.backgroundColor = PQBFConfig.shared.pointEditNamalBackgroundColor
- onlyMusicBtn.setTitleColor(UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue), for: .selected)
- onlyMusicBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#959595"), for: .normal)
- onlyMusicBtn.addCorner(corner: 5)
- onlyMusicBtn.tag = 3
- onlyMusicBtn.addTarget(self, action: #selector(editModelClick1(sender:)), for: .touchUpInside)
- onlyMusicBtn.adjustsImageWhenHighlighted = false
-
- onlyMusicBtn.setImage(UIImage.moduleImage(named: PQBFConfig.shared.onlyMusicBtnImage_N, moduleName: "BFFramework", isAssets: false), for: .normal)
- onlyMusicBtn.setImage(UIImage.moduleImage(named: PQBFConfig.shared.onlyMusicBtnImage_H, moduleName: "BFFramework", isAssets: false), for: .selected)
- return onlyMusicBtn
- }()
-
- lazy var optionlineView: UIView = {
- let optionlineView = UIView()
- optionlineView.backgroundColor = PQBFConfig.shared.pointEditNamalBackgroundColor
- return optionlineView
- }()
-
- lazy var speedSettingView: PQSpeedSettingView = {
- let speedSetView = PQSpeedSettingView()
- speedSetView.backgroundColor = .clear
- speedSetView.selectSpeedCallBack = { [weak self] maxSpeed, minSpeed, selectIndex, isSettingPlayer in
- BFLog(message: "固定maxSpeed is\(maxSpeed) minSpeed \(minSpeed)")
- self?.musicEditBGView.pausePlayer()
- if maxSpeed == -1.0 && minSpeed == -1.0 {
- self?.customSpeedSettingView.isHidden = false
- self?.customSpeedSettingView.viewType = self?.speedSettingView.viewType ?? 2
- } else {
- if maxSpeed != 0.0 {
-
- if self?.speedSettingView.viewType == 1 {
- self?.lastSpeedSelectIndex = selectIndex
- self?.modelSpeed_maxSpeed = maxSpeed
- self?.modelSpeed_minSpeed = minSpeed
- } else if self?.speedSettingView.viewType == 2 {
- self?.lastJumpSpeedSelectIndex = selectIndex
- self?.modelPoint_speed = maxSpeed
- } else {
- self?.lastCyclesSelectIndex = selectIndex
- }
-
- } else {
- BFLog(message: "设置速度无效")
- }
- }
- if isSettingPlayer {
- self?.settingPlayerView()
- }
- }
- return speedSetView
- }()
-
- lazy var customSpeedSettingView: PQCustomSpeedSettingView = {
- let customSpeedSetView = PQCustomSpeedSettingView(frame: CGRect(x: 0, y: cScreenHeigth - 354, width: cScreenWidth, height: 354))
- customSpeedSetView.isHidden = true
- customSpeedSetView.selectSpeedCallBack = { [weak self, weak customSpeedSetView] maxSpeed, minSpeed, isJumpSpeedModel, isCancle in
- if !isCancle {
-
- BFLog(message: "自定义速度maxSpeed is\(maxSpeed) minSpeed \(minSpeed) \(isJumpSpeedModel)")
- self?.musicEditBGView.pausePlayer()
-
- if self?.speedSettingView.viewType == 1 {
- self?.lastSpeedSelectIndex = -1
- self?.modelSpeed_maxSpeed = maxSpeed
- self?.modelSpeed_minSpeed = minSpeed
- } else if self?.speedSettingView.viewType == 2 {
- self?.lastJumpSpeedSelectIndex = -1
- self?.modelPoint_speed = maxSpeed
- } else {
- self?.lastCyclesSelectIndex = Int(maxSpeed - 1)
- }
- self?.settingPlayerView()
-
- self?.speedSettingView.selectCustom()
- } else {
-
- if self?.speedSettingView.viewType == 1 {
- self?.speedSettingView.setSelectItem(index: self?.lastSpeedSelectIndex ?? 0, isSettingPlayer: false)
- } else if self?.speedSettingView.viewType == 2 {
- self?.speedSettingView.setSelectItem(index: self?.lastJumpSpeedSelectIndex ?? 0, isSettingPlayer: false)
- } else {
- self?.speedSettingView.setSelectItem(index: self?.lastCyclesSelectIndex ?? 0, isSettingPlayer: false)
- }
- customSpeedSetView?.isHidden = true
- }
- }
- return customSpeedSetView
- }()
-
- lazy var musicNameView: UIView = {
- let musicNameView = UIView()
- musicNameView.addSubview(musicNameLab)
- let nameWidth: CGFloat = musicNameLab.frame.width + (25 + cDefaultMargin * 3)
- musicNameView.frame = CGRect(x: (view.frame.width - nameWidth) / 2, y: cDevice_iPhoneStatusBarHei + (cDevice_iPhoneNavBarHei - cDefaultMargin * 3) / 2, width: nameWidth, height: cDefaultMargin * 3)
- musicNameView.addCorner(corner: musicNameView.frame.height / 2)
- let musicImageView = UIImageView()
- musicImageView.tintColor = PQBFConfig.shared.styleTitleColor
- musicImageView.image = UIImage.moduleImage(named: "stuckPoint_reCreate_music", moduleName: "BFFramework", isAssets: false)?.withRenderingMode(.alwaysTemplate)
- musicImageView.frame = CGRect(x: musicNameView.frame.height / 2 - 5, y: (musicNameView.frame.height - 22) / 2, width: 22, height: 22)
- musicNameView.addSubview(musicImageView)
- musicNameLab.frame.origin.x = musicImageView.frame.maxX + 5
- return musicNameView
- }()
-
- lazy var musicNameLab: LMJHorizontalScrollText = {
- let nameWidth: CGFloat = sizeWithText(text: "\(stuckPointMusicData?.musicName ?? "")", font: UIFont.systemFont(ofSize: 13), size: CGSize(width: view.frame.width - ((cDefaultMargin * 6 + 16 * 2) * 2) - (25 + cDefaultMargin * 3), height: cDefaultMargin * 3)).width
- let musicNameLab = LMJHorizontalScrollText(frame: CGRect(x: 0, y: 0, width: nameWidth < cDefaultMargin * 4 ? cDefaultMargin * 4 : nameWidth, height: cDefaultMargin * 3))
- musicNameLab.textColor = PQBFConfig.shared.styleTitleColor
- musicNameLab.textFont = UIFont.systemFont(ofSize: 13)
- musicNameLab.speed = 0.03
- musicNameLab.moveDirection = LMJTextScrollMoveLeft
- musicNameLab.moveMode = LMJTextScrollContinuous
- if nameWidth < cDefaultMargin * 4 {
- musicNameLab.text = " \(stuckPointMusicData?.musicName ?? "") "
- } else {
- musicNameLab.text = " \(stuckPointMusicData?.musicName ?? "") "
- }
- return musicNameLab
- }()
-
- lazy var synchroMarskView: PQStuckPointLoadingView = {
- var synchroMarskView = PQStuckPointLoadingView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
- synchroMarskView.cancelHandle = { [weak self] _ in
- self?.navigationController?.popViewController(animated: true)
- }
- return synchroMarskView
- }()
- @objc func willEnterForeground() {
- BFLog(message: "进入到前台")
- if(self.navigationController?.topViewController == self){
- if projectModel.sData!.sections.count > 0 {
- settingPlayerView()
- }else {
- prepareMeta()
- }
- }
- }
-
- @objc func enterBackground() {
- BFLog(message: "进入到后台")
-
- if(self.navigationController?.topViewController == self){
- playerView.pause()
- }
- }
- override func backBtnClick() {
- super.backBtnClick()
-
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_back, pageSource: .sp_stuck_previewSyncedUp, extParams: nil, remindmsg: "卡点视频数据上报-(点击上报:返回按钮)")
- }
-
- func userstuckPointMusic(musicData: PQVoiceModel?) {
-
- stuckPointMusicData = musicData
-
- synchroMusicInfoData(resetSelectIndex: false)
-
- let nameWidth: CGFloat = sizeWithText(text: "\(stuckPointMusicData?.musicName ?? "")", font: UIFont.systemFont(ofSize: 13), size: CGSize(width: (view.frame.width) - ((cDefaultMargin * 6 + 16 * 2) * 2) - (25 + cDefaultMargin * 3), height: cDefaultMargin * 3)).width
- if nameWidth < cDefaultMargin * 4 {
- musicNameLab.text = " \(stuckPointMusicData?.musicName ?? "") "
- } else {
- musicNameLab.text = " \(stuckPointMusicData?.musicName ?? "") "
- }
-
- sustomSwitchView.selectOneBtn(Index: (stuckPointMusicData?.speed ?? 2))
- }
-
- @objc func musicSearchBtnClick(sender _: UIButton) {
- let searchVC = PQEditMusicSearchController()
- searchVC.btnClickHandle = { [weak self] _, bgmData in
-
- BFLog(message: "搜索音乐点击了使用")
- self?.musicEditBGView.insertSearchMusic(model: bgmData as! PQVoiceModel)
- self?.userstuckPointMusic(musicData: bgmData as? PQVoiceModel)
- }
- let navigationController: UINavigationController = UINavigationController(rootViewController: searchVC)
- navigationController.modalPresentationStyle = .fullScreen
- present(navigationController, animated: true, completion: nil)
- }
-
- @objc func pointEditerBtnClick(sender: UIButton) {
- if sender.isSelected { return }
- sender.isSelected = !sender.isSelected
- musicEditerBtn.isSelected = false
- pointEditBGView.isHidden = false
- musicEditBGView.isHidden = true
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_videoTab, pageSource: .sp_shanyinApp_main, extParams: nil, remindmsg: "")
- }
-
- @objc func musicEditerBtnClick(sender: UIButton) {
- if sender.isSelected { return }
- sender.isSelected = !sender.isSelected
- pointEditerBtn.isSelected = false
- pointEditBGView.isHidden = true
- musicEditBGView.showData()
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_musicTab, pageSource: .sp_shanyinApp_main, extParams: nil, remindmsg: "")
- }
- @objc func editModelClick1(sender: UIButton) {
- editModelClick(sender: sender)
- }
-
- @objc func editModelClick(sender: UIButton, reportLog: Bool = true) {
- self.musicEditBGView.pausePlayer()
- sharedImageProcessingContext.framebufferCache.purgeAllUnassignedFramebuffers()
- if sender == jumpPointBtn && selectedTotalDuration < 6 && selectedDataCount != selectedImageDataCount && reCreateVideoData == nil{
- cShowHUB(superView: view, msg: "素材时长需要大于6秒才\n可选择“跳跃卡点”模式")
- return
- }
- lastEditModelBtn?.isSelected = false
-
- lastEditModelBtn?.backgroundColor = PQBFConfig.shared.pointEditNamalBackgroundColor
- sender.isSelected = !sender.isSelected
- lastEditModelBtn = sender
-
- let styleColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
- lastEditModelBtn?.backgroundColor = UIColor(red: styleColor.rgbaf[0], green: styleColor.rgbaf[1], blue: styleColor.rgbaf[2], alpha: 0.15)
-
- BFLog(message: "sender tag is \(sender.tag)")
-
- if sender.tag == 1 || sender.tag == 2 {
- speedSettingView.viewType = sender.tag
- customSpeedSettingView.viewType = speedSettingView.viewType
- speedSettingView.snp.remakeConstraints { make in
- make.left.equalToSuperview().offset(16)
- make.right.equalToSuperview()
- make.top.equalTo(onlyMusicBtn.snp.bottom).offset(10)
- make.height.equalTo(sender.tag == 1 ? 44 : 30)
- }
- speedSettingView.isHidden = false
- speedTitleLab.isHidden = false
- sustomSwitchView.isHidden = false
- } else {
- speedTitleLab.isHidden = true
- speedSettingView.isHidden = true
- sustomSwitchView.isHidden = true
- }
-
- if selectedDataCount == selectedImageDataCount {
- speedSettingView.viewType = 3
- customSpeedSettingView.viewType = speedSettingView.viewType
- speedSettingView.snp.remakeConstraints { make in
- make.left.equalToSuperview().offset(16)
- make.right.equalToSuperview()
- make.top.equalTo(onlyMusicBtn.snp.bottom).offset(10)
- make.height.equalTo(30)
- }
- speedSettingView.isHidden = false
- speedTitleLab.isHidden = false
- sustomSwitchView.isHidden = false
- if lastCyclesSelectIndex != -1 {
- speedSettingView.setSelectItem(index: lastCyclesSelectIndex, isSettingPlayer: false)
- }
- } else {
- if sender.tag == 1 {
- speedSettingView.setSelectItem(index: lastSpeedSelectIndex, isSettingPlayer: false, setDisable: (selectedTotalDuration < 6 && selectedDataCount != selectedImageDataCount) ? true : false)
- } else if sender.tag == 2 {
- speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex, isSettingPlayer: false)
- } else if sender.tag == 3 {
- }
- }
-
- var speedStuckBtnGifName = ""
- var jumpPointBtnGifName = ""
- if sender.tag == 1 {
- speedStuckBtnGifName = "speedstuck_h_pq"
- jumpPointBtnGifName = "jumpPoint_n_pq"
- currentCreateStickersModel = .createStickersModelSpeed
- if reportLog {
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_selectPatternSpeed, pageSource: .sp_shanyinApp_main, extParams: nil, remindmsg: "")
- }
- } else if sender.tag == 2 {
- speedStuckBtnGifName = "speedstuck_n_pq"
- jumpPointBtnGifName = "jumpPoint_h_pq"
- currentCreateStickersModel = .createStickersModelPoint
- if reportLog {
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_selectPatternMusicVideo, pageSource: .sp_shanyinApp_main, extParams: nil, remindmsg: "")
- }
- } else if sender.tag == 3 {
- speedStuckBtnGifName = "speedstuck_n_pq"
- jumpPointBtnGifName = "jumpPoint_n_pq"
- currentCreateStickersModel = .createStickersModelOnlyMusic
- if reportLog {
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_selectPatternBgm, pageSource: .sp_shanyinApp_main, extParams: nil, remindmsg: "")
- }
- }
- settingPlayerView()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- lineView?.isHidden = true
- DispatchQueue.main.async {
- UIApplication.shared.isIdleTimerDisabled = true
- }
- musicNameLab.move()
- PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
- PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
- }
-
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- DispatchQueue.main.async {
- UIApplication.shared.isIdleTimerDisabled = false
- }
- musicNameLab.stop()
- playerView.pause()
- musicEditBGView.pausePlayer()
- PQNotification.removeObserver(self)
-
- self.synchroMarskView.removeMarskView()
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- leftButton(image: nil, tintColor: PQBFConfig.shared.styleTitleColor)
- navHeadImageView?.addSubview(nextBtn)
- navHeadImageView?.addSubview(musicNameView)
-
- addSubViews()
-
- prepareMeta()
-
-
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_windowView, objectType: .ot_view_previewSyncedUp, pageSource: .sp_stuck_previewSyncedUp, extParams: nil, remindmsg: "卡点视频数据上报-(曝光上报:预览页面曝光上报)")
-
-
- if selectedPhotoData != nil && selectedPhotoData!.count > 0 {
- let photo = selectedPhotoData!.first!
- let option = PHImageRequestOptions()
- option.isNetworkAccessAllowed = true
- option.resizeMode = .none
- option.deliveryMode = .highQualityFormat
- PHImageManager.default().requestImage(for: photo,
- targetSize: CGSize(width: 1920, height: 1920),
- contentMode: .aspectFit,
- options: option)
- { [weak self] (image, nil) in
-
- if image != nil {
- self?.firstFrameImage = image
- }
- }
- }
- }
-
- override func viewDidLayoutSubviews() {
- super.viewDidLayoutSubviews()
- playerView.resetCanvasFrame(frame: coculationPlayViewRect())
- }
-
- func prepareMeta(){
-
- exportPhotoData()
-
- synchroMusicInfoData()
-
- musicEditBGView.firstInsertVoiceModel = stuckPointMusicData!
- }
-
-
- func addSubViews() {
- if (stuckPointMusicData?.rhythmSdata.count ?? 0) <= 0 {
- return
- }
- view.addSubview(playerView)
- view.addSubview(pointEditBGView)
- view.addSubview(musicEditBGView)
- view.addSubview(optionlineView)
- view.addSubview(pointEditerBtn)
- view.addSubview(musicEditerBtn)
- view.addSubview(customSpeedSettingView)
-
- pointEditBGView.addSubview(pointEditRemindLab)
- pointEditBGView.addSubview(speedTitleLab)
- pointEditBGView.addSubview(speedStuckBtn)
- pointEditBGView.addSubview(jumpPointBtn)
- pointEditBGView.addSubview(onlyMusicBtn)
- pointEditBGView.addSubview(speedSettingView)
- pointEditBGView.addSubview(sustomSwitchView)
-
- musicEditBGView.addSubview(stuckPointCuttingView)
- pointEditerBtn.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(100)
- make.bottom.equalToSuperview().offset(-(14 + cAKSafeAreaHeight))
- make.height.equalTo(24)
- make.width.equalTo(24)
- }
- musicEditerBtn.snp.makeConstraints { make in
- make.right.equalToSuperview().offset(-100)
- make.top.equalTo(pointEditerBtn.snp.top)
- make.height.equalTo(24)
- make.width.equalTo(24)
- }
- pointEditBGView.snp.makeConstraints { make in
- make.left.right.equalTo(view)
- make.bottom.equalTo(pointEditerBtn.snp.top).offset(-7)
- make.height.equalTo(290)
- }
- musicEditBGView.snp.makeConstraints { make in
- make.left.right.equalToSuperview()
- make.bottom.equalTo(pointEditerBtn.snp.top).offset(-7)
- make.height.equalTo(290)
- }
-
- optionlineView.snp.makeConstraints { make in
- make.left.right.equalToSuperview()
- make.bottom.equalTo(pointEditBGView.snp.bottom).offset(-1)
- make.height.equalTo(1)
- }
- stuckPointCuttingView.snp.makeConstraints { make in
- make.left.right.equalToSuperview()
- make.bottom.equalTo(musicEditBGView.snp.bottom).offset(-1)
- make.height.equalTo(85)
- }
- pointEditRemindLab.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(16)
- make.top.equalToSuperview().offset(16)
- make.height.equalTo(20)
- make.width.equalTo(80)
- }
- speedStuckBtn.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(16)
- make.top.equalTo(pointEditRemindLab.snp.bottom).offset(8)
- make.height.equalTo(80)
- make.width.equalTo(80)
- }
-
- jumpPointBtn.snp.makeConstraints { make in
- make.left.equalTo(speedStuckBtn.snp.right).offset(10)
- make.top.equalTo(speedStuckBtn.snp.top)
- make.height.equalTo(80)
- make.width.equalTo(80)
- }
-
- onlyMusicBtn.snp.makeConstraints { make in
- make.left.equalTo(jumpPointBtn.snp.right).offset(10)
- make.top.equalTo(speedStuckBtn.snp.top)
- make.height.equalTo(80)
- make.width.equalTo(64)
- }
-
- speedStuckBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -(speedStuckBtn.imageView?.frame.size.width ?? 0) , bottom: -(speedStuckBtn.imageView?.frame.size.height ?? 0), right: 0);
- speedStuckBtn.imageEdgeInsets = UIEdgeInsets(top: -(speedStuckBtn.titleLabel?.intrinsicContentSize.height ?? 0), left: 0, bottom: 0, right: -(speedStuckBtn.titleLabel?.intrinsicContentSize.width ?? 0));
- jumpPointBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -(jumpPointBtn.imageView?.frame.size.width ?? 0) , bottom: -(jumpPointBtn.imageView?.frame.size.height ?? 0), right: 0);
- jumpPointBtn.imageEdgeInsets = UIEdgeInsets(top: -(jumpPointBtn.titleLabel?.intrinsicContentSize.height ?? 0), left: 0, bottom: 0, right: -(jumpPointBtn.titleLabel?.intrinsicContentSize.width ?? 0));
-
- onlyMusicBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -(onlyMusicBtn.imageView?.frame.size.width ?? 0) , bottom: -(onlyMusicBtn.imageView?.frame.size.height ?? 0), right: 0);
- onlyMusicBtn.imageEdgeInsets = UIEdgeInsets(top: -(onlyMusicBtn.titleLabel?.intrinsicContentSize.height ?? 0), left: 0, bottom: 0, right: -(onlyMusicBtn.titleLabel?.intrinsicContentSize.width ?? 0));
- speedSettingView.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(16)
- make.right.equalToSuperview()
- make.top.equalTo(onlyMusicBtn.snp.bottom).offset(10)
- make.height.equalTo(44)
- }
- speedTitleLab.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(16)
- make.top.equalToSuperview().offset(190)
- make.height.equalTo(20)
- make.width.equalTo(80)
- }
- sustomSwitchView.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(16)
- make.top.equalTo(speedTitleLab.snp.bottom).offset(8)
- make.height.equalTo(30)
- make.width.equalTo(180)
- }
- }
- @objc func nextBtnClick(sender _: UIButton) {
- BFLog(message: "去发布")
- playerView.pause()
-
- let json = projectModel.toJSONString(prettyPrint: false)
- if json == nil {
- BFLog(message: "数据转换有问题 跳转")
- return
- }
- let tempModel: PQEditProjectModel? = Mapper<PQEditProjectModel>().map(JSONString: json!)
- let materialVC: PQStuckPointMaterialController? = navigationController?.viewControllers.first(where: { (vc) -> Bool in
- vc is PQStuckPointMaterialController
- }) as? PQStuckPointMaterialController
- if materialVC != nil, materialVC?.isToPublicHandle != nil {
- materialVC?.isToPublicHandle!(isReCreate, selectedTotalDuration, selectedDataCount, selectedImageDataCount, mStickers, stuckPointMusicData, tempModel)
- } else {
- if finallyStuckPoints.count == 0 {
- cShowHUB(superView: nil, msg: "无卡点信息,返回重新选择音乐")
- return
- }
- let videoExporter = PQStuckPointPublicController()
- videoExporter.rhythmMode = currentCreateStickersModel
- videoExporter.syncedUpVideoSpeedMin = modelSpeed_maxSpeed
- videoExporter.syncedUpVideoSpeedMax = modelSpeed_minSpeed
- videoExporter.isReCreate = isReCreate
- videoExporter.selectedTotalDuration = selectedTotalDuration
- videoExporter.selectedDataCount = selectedDataCount
- videoExporter.selectedImageDataCount = selectedImageDataCount
- videoExporter.finallyUserAudioTime = Float(finallyStuckPoints.last ?? 0) - Float(finallyStuckPoints.first ?? 0)
- videoExporter.clipAudioRange = getClipAudioRange()
- videoExporter.playeTimeRange = playeTimeRange
- videoExporter.mStickers = mStickers
- videoExporter.audioMixModel = stuckPointMusicData
- videoExporter.editProjectModel = tempModel
- navigationController?.pushViewController(videoExporter, animated: true)
- }
-
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_commit, pageSource: .sp_stuck_previewSyncedUp, extParams: ["musicName": stuckPointMusicData?.musicName ?? "", "musicId": stuckPointMusicData?.musicId ?? "", "rhythmNumber": stuckPointMusicData?.speed ?? 2, "duration": ((stuckPointMusicData?.endTime ?? 0) - (stuckPointMusicData?.startTime ?? 0)) * 1000], remindmsg: "点击上报:去合成")
- }
-
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- super.touchesBegan(touches, with: event)
- if touches.first?.view != self.customSpeedSettingView {
- if !customSpeedSettingView.isHidden {
- customSpeedSettingView.isHidden = true
- }
- }
- }
-
-
-
- func seekPlayer(playeTimeRange: CMTimeRange) {
- playerView.setEnableSeek(isSeek: true)
- playerView.play(pauseFirstFrame: false, playeTimeRange: playeTimeRange)
- }
-
- func createPorjectData() {
-
- if projectModel.sData?.sections.count == 0 {
- let section: PQEditSectionModel = PQEditSectionModel()
- selectedMetarialData?.forEach { model in
- let json = model.toJSONString(prettyPrint: false)
- if json == nil {
- BFLog(message: "数据转换有问题 跳转")
- return
- }
- let tempModel: PQEditVisionTrackMaterialsModel = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: json!)!
- section.sectionTimeline?.visionTrack?.visionTrackMaterials.append(tempModel)
- }
- projectModel.sData?.sections.append(section)
- }
-
- projectModel.sData?.addBGM(audioMix: stuckPointMusicData!)
- }
-
- func getClipAudioRange() -> CMTimeRange {
-
- if stuckPointMusicData!.rhythmSdata.count > 0 && stuckPointMusicData?.rhythmSdata[0].pointTimes.count ?? 0 > 2 {
- let lastSecondPoint = Float((stuckPointMusicData!.rhythmSdata[0].pointTimes[stuckPointMusicData!.rhythmSdata[0].pointTimes.count - 2])) / Float(BASE_FILTER_TIMESCALE)
- let clipAudioRange =
- CMTimeRange(start: CMTime(value: CMTimeValue(Float(stuckPointMusicData?.startTime ?? 0) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE), end: CMTime(value: CMTimeValue((Float(lastSecondPoint)) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE))
-
- return clipAudioRange
- }
- return CMTimeRange(start: CMTime(value: 0, timescale: 1), duration: CMTime(value: 1, timescale: 1))
- }
-
- func coculationPlayViewRect() -> CGRect {
- let playerShowHeight = pointEditBGView.frame.minY - (navHeadImageView?.frame.maxY ?? 0)
- var showRect: CGRect = CGRect(x: (cScreenWidth - playerShowHeight) / 2, y: 0, width: playerShowHeight, height: playerShowHeight)
- if self.firstFrameImage != nil {
- let w = self.firstFrameImage!.size.width
- let h = self.firstFrameImage!.size.height
- let ratioMaterial: Float = Float(w / max(h, 1))
- if ratioMaterial > 1 {
-
- let tempPlayerHeight = min(cScreenWidth * CGFloat(h / w), playerShowHeight)
- showRect = CGRect(x: (cScreenWidth - tempPlayerHeight * CGFloat(ratioMaterial)) / 2, y: (playerShowHeight - tempPlayerHeight) / 2, width: tempPlayerHeight * CGFloat(ratioMaterial), height: tempPlayerHeight)
- } else {
-
- let playerViewWidth = (CGFloat(w) / CGFloat(h)) * playerShowHeight
- showRect = CGRect(x: (cScreenWidth - playerViewWidth) / 2, y: 0, width: playerViewWidth, height: playerShowHeight)
- }
- }
- if showRect.size.width == showRect.size.height {
- if cScreenWidth > playerShowHeight {
- showRect.origin.x = (cScreenWidth - playerShowHeight) / 2
- showRect.size.width = playerShowHeight
- showRect.size.height = playerShowHeight
- } else {
- showRect.origin.x = 0
- showRect.size.width = cScreenWidth
- showRect.size.height = cScreenWidth
- }
- }
-
- if showRect.size.width != 0, showRect.size.height != 0 {
- if(Int(showRect.height) % 2 != 0){
- showRect.size.height = showRect.size.height + 1.0
- }
- if(Int(showRect.width) % 2 != 0){
- showRect.size.width = showRect.size.width + 1.0
- }
-
- }
- showRect.origin.y = (playerShowHeight - showRect.size.height) / 2.0 + (navHeadImageView?.frame.maxY ?? 0)
-
- return showRect
- }
-
- func settingPlayerView() {
- stuckPointCuttingView.resetDefaultsColor()
- synchroMarskView.show()
-
-
- playerView.pause()
-
- var firstModel: PQEditVisionTrackMaterialsModel?
- for part in projectModel.sData!.sections {
- if part.sectionTimeline?.visionTrack?.getEnableVisionTrackMaterials().count ?? 0 > 0 {
- firstModel = part.sectionTimeline?.visionTrack?.getEnableVisionTrackMaterials().first
- break
- }
- }
- var videoSize: CGSize = CGSize(width: Int(firstModel?.width ?? 0), height: Int(firstModel?.height ?? 0))
- var minSlider = min(videoSize.width, videoSize.height)
- var maxSlider = max(videoSize.width, videoSize.height)
- let ration = 1080 / minSlider
- minSlider = minSlider * ration
- maxSlider = maxSlider * ration
- if videoSize.width > videoSize.height {
- videoSize = CGSize(width: maxSlider, height: minSlider)
- } else {
- videoSize = CGSize(width: minSlider, height: maxSlider)
- }
- if videoSize.width.isNaN || videoSize.height.isNaN {
- BFLog(1, message: "宽高无效NaN")
- return
- }
- let maxValue = max(videoSize.width, videoSize.height ?? 0)
- if maxValue > 1920 {
- let maxRation = 1920 / maxValue
- videoSize = CGSize(width: videoSize.width * CGFloat(maxRation), height: videoSize.height * CGFloat(maxRation))
- BFLog(message: "最长边已经超过 1920 要等比缩小 缩放后\(videoSize)")
- }
- if (Int(videoSize.width) % 2) != 0 {
- videoSize.width = videoSize.width - 1
- }
- if (Int(videoSize.height) % 2) != 0 {
- videoSize.height = videoSize.height - 1
- }
- projectModel.sData?.videoMetaData?.videoWidth = Int(videoSize.width)
- projectModel.sData?.videoMetaData?.videoHeight = Int(videoSize.height)
- let beginTime = Date()
- dealParameter(model: currentCreateStickersModel)
-
- stuckPointCuttingView.videoDuration = max(CGFloat(finallyUserAudioTime), CGFloat(finallyStuckPoints.last!))
- let counn = (stuckPointMusicData?.rhythmSdata[0].pointTimes.count)! - 2
- let suggestRhythmStartTime = CGFloat(stuckPointMusicData?.suggestRhythmStartTime ?? 0)
- let suggestRhythmEndTime = max(suggestRhythmStartTime, CGFloat(stuckPointMusicData?.rhythmSdata[0].pointTimes[max(counn, 0)] ?? 0)/CGFloat(BASE_FILTER_TIMESCALE))
- stuckPointCuttingView.updateEndTime(
- startTime: CGFloat(CMTimeGetSeconds(playeTimeRange.start)),
- endTime: CGFloat(CMTimeGetSeconds(playeTimeRange.end)),
- suggestRhythmStartTime: suggestRhythmStartTime,
- suggestRhythmEndTime: suggestRhythmEndTime)
-
- DispatchQueue.global().async {
- self.mStickers = self.createStickers(sections: self.projectModel.sData?.sections ?? List(), inputSize: CGSize(width: CGFloat(self.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self.projectModel.sData?.videoMetaData?.videoHeight ?? 0)), model: self.currentCreateStickersModel)
- DispatchQueue.main.async {
- self.playerView.mStickers = self.mStickers
- BFLog(message: "createStickers tiskskskskme \(Date().timeIntervalSince(beginTime))")
-
- let audioPath = self.stuckPointMusicData?.localPath ?? ""
- BFLog(message: "初始化音频播放器的音频地址为:\(audioPath)")
- self.playerView.stop()
-
-
- self.playerView.updateAsset(URL(fileURLWithPath: documensDirectory + audioPath), videoComposition: nil, audioMixModel: nil, originMusicDuration: self.finallyUserAudioTime, clipAudioRange: self.getClipAudioRange())
-
- self.playerView.movie?.mShowVidoSize = CGSize(width: CGFloat(self.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self.projectModel.sData?.videoMetaData?.videoHeight ?? 0))
-
-
-
- let fir = Int64(self.stuckPointsTemp.first ?? 0)
- let endd = Int64(self.stuckPointsTemp.last ?? 0)
- self.playerView.movie?.orginStuckRange = CMTimeRange(start: CMTime(value: Int64(fir) * Int64(BASE_FILTER_TIMESCALE), timescale: BASE_FILTER_TIMESCALE), end: CMTime(value: Int64(endd) * Int64(BASE_FILTER_TIMESCALE), timescale: BASE_FILTER_TIMESCALE))
-
- self.playerView.isLoop = false
- self.playerView.showProgressLab = true
-
- BFLog(message: "播放的器 开始\(String(describing: CMTimeGetSeconds(self.playeTimeRange.start))) 结束 \(String(describing: CMTimeGetSeconds(self.playeTimeRange.end)))")
- let end3: TimeInterval = Date().timeIntervalSince1970
- self.playerView.play(pauseFirstFrame: false, playeTimeRange: CMTimeRange(start: self.playeTimeRange.start, end: self.playeTimeRange.end))
- self.stuckPointCuttingView.updateProgress(progress: 0)
- self.synchroMarskView.removeMarskView()
- let end4: TimeInterval = Date().timeIntervalSince1970
- BFLog(message: " playerView.play tiskskskskme \(end4 - end3)")
-
- self.playerView.progress = { [weak self] currentTime, tatolTime, percent in
- if percent == 1 {
- self?.stuckPointCuttingView.resetDefaultsColor(clearData: false)
- sharedImageProcessingContext.framebufferCache.purgeAllUnassignedFramebuffers()
- return
- }
- if(CMTimeGetSeconds(self?.playeTimeRange.duration ?? .zero) <= 0.0){
- BFLog(message: "时长错误!!!!")
- return
- }
-
- let progress = (currentTime - CMTimeGetSeconds(self?.playeTimeRange.start ?? .zero)) / CMTimeGetSeconds(self?.playeTimeRange.duration ?? .zero)
- BFLog(message: "\(currentTime) \(tatolTime) 显示播放器进度为: \(progress)")
- self?.stuckPointCuttingView.updateProgress(progress: CGFloat(progress))
- }
- }
- }
- }
- deinit {
- musicNameLab.stop()
-
- PQSingletoMemoryUtil.shared.allExportSession.forEach { _, exportSession in
- exportSession.cancelExport()
- }
- self.synchroMarskView.removeMarskView()
- sharedImageProcessingContext.framebufferCache.purgeAllUnassignedFramebuffers()
- BFLog(1, message: "卡点视频预览界面release")
- }
- }
- extension PQStuckPointEditerController {
-
-
-
-
- func clipVideoMerage(section: PQEditSectionModel, stuckPoints: [Float]) -> [PQEditVisionTrackMaterialsModel] {
- var stickers: Array = Array<PQEditVisionTrackMaterialsModel>.init()
-
-
-
- let kongduan: Int = Int(stuckPoints.count - 1) - selectedImageDataCount
-
- var videoTotalDuration: Float64 = 0.0
- for video in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "video") {
- let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + video.locationPath), options: nil)
- videoTotalDuration = videoTotalDuration + Float64(CMTimeGetSeconds(asset.duration))
- }
- if videoTotalDuration == 0 {
- BFLog(message: "视频总时长出现错误!!!!这里应该有视频素材的")
- return stickers
- }
- for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
- if sticker.type == StickerType.VIDEO.rawValue {
- let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
-
- let clipNum = Int(max(round(Double(kongduan) * CMTimeGetSeconds(asset.duration) / videoTotalDuration), 1))
- sticker.duration = CMTimeGetSeconds(asset.duration)
- BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(clipNum)")
- for clipindex in 0 ..< clipNum {
-
- let deepCopySticker:PQEditVisionTrackMaterialsModel? = sticker.copy() as? PQEditVisionTrackMaterialsModel
-
-
- deepCopySticker?.generateDefaultValues()
- deepCopySticker?.model_in = clipindex == 0 ? 0 : CMTimeGetSeconds(asset.duration) / Double(clipNum) * Double(clipindex)
- deepCopySticker?.out = (deepCopySticker?.model_in ?? 0) + CMTimeGetSeconds(asset.duration) / Double(clipNum)
- if (deepCopySticker?.model_in ?? 0) >= CMTimeGetSeconds(asset.duration) || (deepCopySticker?.out ?? 0) >= CMTimeGetSeconds(asset.duration) {
- deepCopySticker?.model_in = CMTimeGetSeconds(asset.duration) - CMTimeGetSeconds(asset.duration) / Double(clipNum)
- deepCopySticker?.out = CMTimeGetSeconds(asset.duration)
- }
- BFLog(message: " crilp is in \(deepCopySticker?.model_in ?? 0) out \(deepCopySticker?.out ?? 0) 总时长\(CMTimeGetSeconds(asset.duration))")
- if deepCopySticker != nil {
- stickers.append(deepCopySticker!)
- }
- }
- } else if sticker.type == StickerType.IMAGE.rawValue {
- sticker.generateDefaultValues()
- stickers.append(sticker)
- }
- }
- return stickers
- }
-
-
- func updateTimeInfomation(){
-
- let asset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + (stuckPointMusicData?.localPath ?? "")), options: nil)
-
- let lastSecondPoint = Float((stuckPointMusicData!.rhythmSdata[0].pointTimes[stuckPointMusicData!.rhythmSdata[0].pointTimes.count - 2])) / Float(BASE_FILTER_TIMESCALE)
- finallyUserAudioTime = Float(lastSecondPoint)
- if (finallyStuckPoints.last ?? 0) > Float(CMTimeGetSeconds(asset.duration)) {
- finallyUserAudioTime = Float(finallyStuckPoints.last ?? 0) + (Float(CMTimeGetSeconds(asset.duration)) - Float(lastSecondPoint))
- }
- playeTimeRange = CMTimeRange(start: CMTime(value: CMTimeValue(Float64(finallyStuckPoints.first ?? 0) * Float64(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE), end: CMTime(value: CMTimeValue((Float64(finallyStuckPoints.last ?? 0)) * Float64(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE))
- for (index, usePoint) in finallyStuckPoints.enumerated() {
- BFLog(message: "测试人员最后使用的卡点信息 \(index) : \(usePoint)")
- }
- BFLog(message: "计算后给播放器使用的开始:\(CMTimeGetSeconds(playeTimeRange.start)) 结束时间\(CMTimeGetSeconds(playeTimeRange.end)) 播放总时长:\(CMTimeGetSeconds(playeTimeRange.end) - CMTimeGetSeconds(playeTimeRange.start))")
- }
-
-
-
-
-
- func createStickers(sections: List<PQEditSectionModel>, inputSize _: CGSize = .zero, model: createStickersModel = .createStickersModelPoint) -> [PQEditVisionTrackMaterialsModel] {
-
- let beginDecoderTime: TimeInterval = Date().timeIntervalSince1970
-
- var stickers: Array = Array<PQEditVisionTrackMaterialsModel>.init()
- for section in sections {
- if section.sectionType == "normal" {
-
- if section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "video").count == 0, section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "image").count > 0 {
- for (index, _) in finallyStuckPoints.enumerated() {
- let sticker: PQEditVisionTrackMaterialsModel = section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials()[index % section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().count]
- BFLog(message: "stickerlocationPath sticker : \(sticker.locationPath)")
- let deepCopySticker:PQEditVisionTrackMaterialsModel? = sticker.copy() as? PQEditVisionTrackMaterialsModel
-
- if deepCopySticker!.type == StickerType.IMAGE.rawValue {
- if index + 1 < finallyStuckPoints.count {
-
- deepCopySticker!.timelineIn = Float64(String(format: "%.6f",finallyStuckPoints[index])) ?? 0.0
-
- deepCopySticker!.timelineOut = Float64(String(format: "%.6f",finallyStuckPoints[index + 1])) ?? 0.0
- if deepCopySticker != nil {
- deepCopySticker?.generateDefaultValues()
- stickers.append(deepCopySticker!)
-
- BFLog(1, message: "测试人员index is 纯图片 timelineOut:\(deepCopySticker!.timelineIn) timelineOut :\(deepCopySticker!.timelineOut)")
- }
- }
- }
- }
- } else {
- if model == .createStickersModelPoint {
-
- let clipFilters = clipVideoMerage(section: section, stuckPoints: finallyStuckPoints)
-
- if(clipFilters.count > finallyStuckPoints.count - 1){
- clipPoint(clipNum: clipFilters.count - finallyStuckPoints.count, oldPoints: finallyStuckPoints)
- }else if(clipFilters.count < finallyStuckPoints.count - 1){
-
- while (clipFilters.count < finallyStuckPoints.count - 1) {
- finallyStuckPoints.removeLast()
- }
-
- }
-
- updateTimeInfomation()
-
- BFLog(message: "stikcer count is\(clipFilters.count) finallyStuckPoints count is\(finallyStuckPoints.count)")
- for (index, point) in finallyStuckPoints.enumerated() {
- BFLog(message: "aaaaaindexindeindexxindexindexindex \(index) \(point)")
- if index + 1 < finallyStuckPoints.count, index < clipFilters.count {
- BFLog(message: "bbbbbindexindeindexxindexindexindex \(index) \(point)")
- let sticker: PQEditVisionTrackMaterialsModel = clipFilters[index]
-
- if(sticker.type == StickerType.IMAGE.rawValue){
- BFLog(message: "当前是image filter !!!!!")
- }
- sticker.timelineIn = Float64(String(format: "%.6f",finallyStuckPoints[index])) ?? 0.0
- sticker.timelineOut = Float64(String(format: "%.6f",finallyStuckPoints[index + 1])) ?? 0.0
-
- let timelineInterval = sticker.timelineOut - sticker.timelineIn
- let inOutInterval = sticker.out - sticker.model_in
- if timelineInterval > inOutInterval {
- BFLog(message: "实际要显示卡点时长\(timelineInterval) 素材裁剪时长:\(inOutInterval)")
- sticker.out = sticker.model_in + timelineInterval
-
- let stickerInOut = sticker.out - sticker.model_in
- let stickerTimelineInOut = sticker.timelineOut - sticker.timelineIn
- if stickerInOut != stickerTimelineInOut {
- BFLog(message: "sticker.timelineIn \(sticker.timelineIn) stickerTimelineInOut is\(stickerTimelineInOut) stickerInOut is\(stickerInOut) 相差\(stickerTimelineInOut - stickerInOut)")
- }
- }
-
- let offsetAssetDuration = sticker.out - sticker.duration
- if offsetAssetDuration > 0 {
- sticker.model_in = sticker.model_in - offsetAssetDuration
- sticker.out = sticker.out - offsetAssetDuration
- }
- print("跳跃卡点测试人员index is \(index)分割后 创建 filter timelineIn :\(sticker.timelineIn) timelineOut :\(sticker.timelineOut) in :\(sticker.model_in) out:\(sticker.out) type is \(sticker.type) 显示总时长为:\(sticker.timelineOut - sticker.timelineIn) 裁剪总时长\(sticker.out - sticker.model_in)")
-
- stickers.append(sticker)
- }
- }
- } else if model == .createStickersModelOnlyMusic || model == .createStickersModelSpeed {
- BFLog(message: "stuckPoints count is \(finallyStuckPoints.count)")
-
- for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
- if sticker.type == StickerType.VIDEO.rawValue {
- let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
- BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(sticker.clipCount)")
- var lastOutTime: Float64 = 0.0
- for _ in 1 ... sticker.clipCount {
-
- let deepCopyStickerDecoderTime: TimeInterval = Date().timeIntervalSince1970
-
- let deepCopySticker:PQEditVisionTrackMaterialsModel? = sticker.copy() as? PQEditVisionTrackMaterialsModel
- BFLog(message: "生成stickers 总时长为 aaa\(Date().timeIntervalSince1970 - deepCopyStickerDecoderTime)")
-
- deepCopySticker?.generateDefaultValues()
- deepCopySticker?.materialDurationFit?.fitType = adapterMode.staticFrame.rawValue
-
- var tempSpeed: Float = 1.0
- if model == .createStickersModelSpeed {
-
- tempSpeed = (stickers.count % 2) == 0 ? modelSpeed_maxSpeed : modelSpeed_minSpeed
- }
- if stickers.count + 1 < finallyStuckPoints.count {
- deepCopySticker?.speedRate = tempSpeed
-
-
- let tempTimelineIn:Float64 = Float64(String(format: "%.6f",finallyStuckPoints[stickers.count])) ?? 0.0
-
- let timelineOut:Float64 = Float64(String(format: "%.6f",finallyStuckPoints[stickers.count + 1])) ?? 0.0
-
- let tempModel_In = lastOutTime
- var tempOut = lastOutTime + Float64(tempSpeed) * (timelineOut - tempTimelineIn)
-
- if tempOut > CMTimeGetSeconds(asset.duration) {
-
- let lastAssetDuration = CMTimeGetSeconds(asset.duration) - lastOutTime
- let pointDuration = timelineOut - tempTimelineIn
-
- let needSpeed = lastAssetDuration / pointDuration
-
- BFLog(message: "最后一点视频素材不够卡点时长要做变速C处理 差\(tempOut - CMTimeGetSeconds(asset.duration)) \(needSpeed)")
- deepCopySticker?.speedRate = Float(needSpeed)
- tempOut = CMTimeGetSeconds(asset.duration)
- if(needSpeed == 0){
- BFLog(message: "needSpeed is 0 出现在时长和卡点正好相等")
- continue
- }
- }
- deepCopySticker?.model_in = tempModel_In
- deepCopySticker?.out = tempOut
- deepCopySticker?.timelineIn = tempTimelineIn
- deepCopySticker?.timelineOut = timelineOut
- lastOutTime = deepCopySticker?.out ?? 0
- }
- BFLog(message: "测试人员创建 sticker crilp is in 视频 \(String(format: "%.6f", deepCopySticker?.model_in ?? 0)) out \(String(format: "%.6f", deepCopySticker?.out ?? 0)) ,分段素材时长:\(String(format: "%.6f", (deepCopySticker?.out ?? 0) - (deepCopySticker?.model_in ?? 0))) ,分段显示时长:\(String(format: "%.6f", (deepCopySticker?.timelineOut ?? 0) - (deepCopySticker?.timelineIn ?? 0))), 视频素材原时长\(CMTimeGetSeconds(asset.duration)) clipNum \(sticker.clipCount) timelineIN: \(String(format: "%.6f", deepCopySticker?.timelineIn ?? 0)) timelineOUT:\(String(format: "%.6f", deepCopySticker?.timelineOut ?? 0)) speedRate:\(deepCopySticker?.speedRate ?? 0.0)")
-
- if deepCopySticker != nil {
- if(deepCopySticker?.timelineIn == 0){
- BFLog(message: "timelineIn data is error!!!")
- }
- stickers.append(deepCopySticker!)
-
- }
- }
- } else if sticker.type == StickerType.IMAGE.rawValue {
- if stickers.count + 1 >= finallyStuckPoints.count {
- BFLog(message: "数据出现错误!!!查正")
- break
- }
- sticker.generateDefaultValues()
-
- sticker.timelineIn = Float64(String(format: "%.6f",finallyStuckPoints[stickers.count])) ?? 0.0
- sticker.timelineOut = Float64(String(format: "%.6f",finallyStuckPoints[stickers.count + 1])) ?? 0.0
- stickers.append(sticker)
- BFLog(message: "测试人员创建 sticker crilp is in 图片 \(String(format: "%.6f", sticker.model_in)) out \(String(format: "%.6f", sticker.out)) ,分段素材时长:\(String(format: "%.6f", (sticker.out) - (sticker.model_in))) ,分段显示时长:\(String(format: "%.6f", (sticker.timelineOut) - (sticker.timelineIn))), timelineIN: \(String(format: "%.6f", sticker.timelineIn)) timelineOUT:\(String(format: "%.6f", sticker.timelineOut)) speedRate:\(sticker.speedRate)")
- }
- }
- }
- }
- }
- }
- BFLog(message: "生成stickers 总时长为:\(Date().timeIntervalSince1970 - beginDecoderTime)")
- return stickers
- }
-
-
-
- func getUsedStuckPoint(seed: Int) -> Array<Float> {
- if !(stuckPointMusicData!.rhythmSdata.count > 0 && stuckPointMusicData!.rhythmSdata[0].pointTimes.count > 1){
- return []
- }
-
-
- var stuckPoints: Array = Array<Float>.init()
- var pointsTemp = Array<Float>.init()
-
-
- let lastPoint = stuckPointMusicData!.rhythmSdata[0].pointTimes[stuckPointMusicData!.rhythmSdata[0].pointTimes.count - 2]
- for (index, dunshu) in stuckPointMusicData!.rhythmSdata[0].pointTimes.enumerated() {
- if dunshu >= Int64((stuckPointMusicData?.startTime ?? 0) * Float64(BASE_FILTER_TIMESCALE)) && dunshu < lastPoint {
- let savePointStr = String(format: "%.6f", Float(dunshu) / Float(BASE_FILTER_TIMESCALE))
- BFLog(message: "原所有卡点数:\(index) \(savePointStr)")
-
- pointsTemp.append(Float(savePointStr) ?? 0.0)
- }
- }
-
-
- if seed == 1 {
- stuckPoints = pointsTemp
- } else {
-
- for (index, point) in pointsTemp.enumerated() {
- if index % seed == 0 {
- stuckPoints.append(point)
- }
- }
- }
- for point in stuckPoints {
- BFLog(message: "没有 start end 计算后的卡点数\(point)")
- }
-
- if Float(stuckPointMusicData?.startTime ?? 0) - (stuckPoints.first ?? 0.0) < 0.3 {
- if stuckPoints.first != nil {
- stuckPoints.removeFirst()
- }
- }
- stuckPoints.insert(Float(stuckPointMusicData?.startTime ?? 0), at: 0)
- for point in stuckPoints {
- BFLog(message: "有 start end 计算后的卡点数\(point)")
- }
- BFLog(message: "处理节奏后 stuckPoints count is \(stuckPoints.count) seed \(seed), start time:\(stuckPoints.first ?? 0.0),end time:\(stuckPoints.last ?? 0.0) 总时长为:\((stuckPoints.last ?? 0.0) - (stuckPoints.first ?? 0.0))")
- return stuckPoints
- }
- func clipPoint(clipNum: Int, oldPoints: Array<Float>) {
- BFLog(message: "拼接卡点数:\(clipNum)")
- if(clipNum < 0 || oldPoints.count < 2){
- BFLog(message: "clipNum is error!!!! \(clipNum)")
- return
- }
-
- if finallyStuckPoints.count == 0 {
- finallyStuckPoints.append(stuckPointsTemp.first ?? 0.0)
- }
-
- for i in finallyStuckPoints.count ... clipNum + finallyStuckPoints.count {
- if (i % (oldPoints.count - 1)) != 1 {
- let value = String(format: "%.6f", finallyStuckPoints[i - 1] + oldPoints[((i-1) % (oldPoints.count - 1)) + 1] - oldPoints[((i - 2) % (oldPoints.count - 1)) + 1])
-
- finallyStuckPoints.append(Float(value) ?? 0.0)
- } else {
- let value = String(format: "%.6f", finallyStuckPoints[i - 1] + oldPoints[1] - oldPoints[0])
- finallyStuckPoints.append(Float(value) ?? 0.0)
- }
- }
- }
-
- func dealParameter(model: createStickersModel) {
-
- finallyStuckPoints.removeAll()
-
- var useAssestDuration: Float = 0.0
- switch model {
- case .createStickersModelPoint:
- stuckPointsTemp = getUsedStuckPoint(seed: stuckPointMusicData?.speed ?? 0)
-
- var clipNum: Int = 0
- var i: Int = 0
-
-
- let jumpTime = Float(selectedTotalDuration) / Float(modelPoint_speed + 1)
-
- if jumpTime > 0 {
- while useAssestDuration < Float(jumpTime) {
-
- if i + 1 >= stuckPointsTemp.count {
- i = 0
- }
-
- let LA = (stuckPointsTemp[i + 1] - stuckPointsTemp[i])
- useAssestDuration = useAssestDuration + Float(LA)
- i = i + 1
- clipNum = clipNum + 1
- }
-
- clipPoint(clipNum: clipNum, oldPoints: stuckPointsTemp)
- }
- break
- case .createStickersModelSpeed, .createStickersModelOnlyMusic:
-
- var tempMaxSpeed: Float = 1
- var tempMinSpeed: Float = 1
- if model == .createStickersModelSpeed {
-
- if model == .createStickersModelSpeed && selectedDataCount != selectedImageDataCount {
- stuckPointsTemp = getUsedStuckPoint(seed: (stuckPointMusicData?.speed ?? 0) + 1)
- } else {
- stuckPointsTemp = getUsedStuckPoint(seed: (stuckPointMusicData?.speed ?? 0))
- }
- tempMaxSpeed = modelSpeed_maxSpeed
- tempMinSpeed = modelSpeed_minSpeed
- } else {
- stuckPointsTemp = getUsedStuckPoint(seed: (stuckPointMusicData?.speed ?? 0))
-
- }
-
-
- BFLog(message: "Ax快速为:\(tempMaxSpeed) By慢速为:\(tempMinSpeed) 档位 N为:\(stuckPointMusicData?.speed ?? 0) 使用的卡点总数:\(stuckPointsTemp.count)")
-
- for section in projectModel.sData?.sections ?? List() {
- if section.sectionType == "normal" {
- for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
- if sticker.type == StickerType.VIDEO.rawValue {
- let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
- let assetDuration = Float(CMTimeGetSeconds(asset.duration))
- BFLog(message: "输入素材时长 \(assetDuration)")
- if(finallyStuckPoints.count == 0){
- finallyStuckPoints.append(stuckPointsTemp[0])
- }
- var j = finallyStuckPoints.count
-
- var pointCount:Int = 1
-
- var useAssestDurationTemp: Float = 0.0
- while useAssestDurationTemp < assetDuration {
-
- let useSpeed = (pointCount % 2 != 0 ) ? tempMaxSpeed : tempMinSpeed
-
-
- var sub:Float = 0.0
- if stuckPointsTemp.count > 2 {
- if ((j - 1) % (stuckPointsTemp.count - 1)) != 0{
- sub = stuckPointsTemp[((j - 1) % (stuckPointsTemp.count-1)) + 1] - stuckPointsTemp[(j - 1) % (stuckPointsTemp.count - 1)]
- }else {
- sub = stuckPointsTemp[1] - stuckPointsTemp[0]
- }
-
- finallyStuckPoints.append(finallyStuckPoints[j - 1] + sub)
- j += 1
- }
- useAssestDurationTemp += sub * useSpeed
- if(useAssestDurationTemp > assetDuration){
- useAssestDurationTemp -= sub * useSpeed
- break
- }
- pointCount += 1
- BFLog(2, message: "finallyStuckPoints last ;\((finallyStuckPoints.last ?? 0.0) - (finallyStuckPoints.first ?? 0.0)), tmp:\(useAssestDurationTemp)")
-
- }
-
- sticker.clipCount = pointCount
- if stuckPointsTemp.count < 1 {
-
- BFLog(message: "卡点数据有错误!!!")
- return
- }
- BFLog(message: "finallyStuckPoints\(finallyStuckPoints)")
-
- if useAssestDurationTemp < assetDuration {
-
- }else {
-
- finallyStuckPoints.removeLast()
- }
- }
- }
- }
- }
- break
- }
-
- if selectedImageDataCount > 0 {
- clipPoint(clipNum: selectedImageDataCount - 1, oldPoints: stuckPointsTemp)
- }
-
-
- var oneSelectImageDuration: Float = 0.0
- if selectedDataCount == selectedImageDataCount {
- oneSelectImageDuration = (finallyStuckPoints.last ?? 0) - (finallyStuckPoints.first ?? 0)
- }
-
- if selectedDataCount == selectedImageDataCount{
-
-
- if lastCyclesSelectIndex != -1 {
-
- if(lastCyclesSelectIndex != 0){
- clipPoint(clipNum: selectedImageDataCount * lastCyclesSelectIndex - 1, oldPoints: stuckPointsTemp)
- }
-
- } else {
- if(oneSelectImageDuration < 10 ){
- lastCyclesSelectIndex = 0
- while oneSelectImageDuration < 10 {
-
- clipPoint(clipNum: selectedImageDataCount - 1, oldPoints: stuckPointsTemp)
- oneSelectImageDuration = Float((finallyStuckPoints.last ?? 0) - (finallyStuckPoints.first ?? 0))
- lastCyclesSelectIndex = lastCyclesSelectIndex + 1
- }
- speedSettingView.setSelectItem(index: lastCyclesSelectIndex, isSettingPlayer: false,enableInsert: true)
- }else{
- lastCyclesSelectIndex = 0
- }
- }
- }
-
-
- if speedSettingView.viewType == 1 {
- speedSettingView.setSelectItem(index: lastSpeedSelectIndex, isSettingPlayer: false)
- } else if speedSettingView.viewType == 2 {
- speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex, isSettingPlayer: false)
- } else if speedSettingView.viewType == 3 {
- if lastCyclesSelectIndex != -1 {
- speedSettingView.setSelectItem(index: lastCyclesSelectIndex, isSettingPlayer: false)
- } else {
- speedSettingView.setSelectItem(index: 0, isSettingPlayer: false)
- }
- }
- updateTimeInfomation()
- }
- }
- extension PQStuckPointEditerController {
-
-
- func synchroMusicInfoData(resetSelectIndex:Bool = true) {
- if (stuckPointMusicData?.rhythmSdata.count ?? 0) <= 0 {
- synchroMarskView.show()
- PQStuckPointViewModel.stuckPointMusicDetailData(musicId: stuckPointMusicData?.musicId ?? "", originType: stuckPointMusicData?.originType ?? 1) { [weak self] newMusicData, _ in
- if newMusicData != nil, (newMusicData?.rhythmSdata.count ?? 0) > 0 {
- self?.isStuckPointDataSuccess = true
- self?.stuckPointMusicData?.rhythmSdata = newMusicData?.rhythmSdata ?? []
- self?.stuckPointMusicData?.startTime = newMusicData?.startTime ?? 0
- self?.stuckPointMusicData?.endTime = newMusicData?.endTime ?? 0
- if newMusicData?.speed != nil {
- self?.stuckPointMusicData?.speed = newMusicData?.speed ?? 2
- }
- if self?.stuckPointMusicData?.localPath == nil || (self?.stuckPointMusicData?.localPath?.count ?? 0) > 0 {
- PQDownloadManager.downLoadFile(url: self?.stuckPointMusicData?.musicPath ?? "") { [weak self] filePath, error in
- if error == nil, filePath != nil {
- self?.isSynchroMusicInfoSuccess = true
- self?.stuckPointMusicData?.localPath = filePath?.replacingOccurrences(of: documensDirectory, with: "")
-
- self?.dealWithDataSuccess(resetSelectIndex: resetSelectIndex)
- }
- self?.synchroMarskView.removeMarskView()
- }
- } else {
- self?.isSynchroMusicInfoSuccess = true
-
- self?.dealWithDataSuccess(resetSelectIndex: resetSelectIndex)
- }
-
- self?.addSubViews()
- } else {
- self?.synchroMarskView.removeMarskView()
- cShowHUB(superView: nil, msg: "音乐信息加载失败,请重新选择音乐")
- self?.navigationController?.popViewController(animated: true)
- }
- }
- } else if stuckPointMusicData?.localPath == nil || (stuckPointMusicData?.localPath?.count ?? 0) > 0 {
- synchroMarskView.show()
- isStuckPointDataSuccess = true
-
- PQDownloadManager.downLoadFile(url: stuckPointMusicData?.musicPath ?? "") { [weak self] filePath, error in
- if error == nil, filePath != nil {
- self?.isSynchroMusicInfoSuccess = true
- self?.stuckPointMusicData?.localPath = filePath?.replacingOccurrences(of: documensDirectory, with: "")
-
- self?.dealWithDataSuccess(resetSelectIndex: resetSelectIndex)
- } else {
- self?.synchroMarskView.removeMarskView()
- }
- }
- } else {
- isStuckPointDataSuccess = true
-
- dealWithDataSuccess(resetSelectIndex: resetSelectIndex)
- }
- }
-
-
- func exportPhotoData() {
-
- PQSingletoMemoryUtil.shared.allExportSession.forEach { _, exportSession in
- exportSession.cancelExport()
- }
- var isHaveVideo: Bool = false
- if selectedMetarialData != nil, (selectedMetarialData?.count ?? 0) > 0 {
- if synchroMarskView.superview == nil {
- UIApplication.shared.keyWindow?.addSubview(synchroMarskView)
- }
- let dispatchGroup = DispatchGroup()
- for photo in selectedMetarialData! {
- if photo.asset != nil, photo.asset?.mediaType == .video {
- if !isHaveVideo {
- isHaveVideo = true
- }
- dispatchGroup.enter()
- PQPHAssetVideoParaseUtil.parasToAVAsset(phAsset: photo.asset!) { avAsset, _, _, _ in
- if avAsset is AVURLAsset {
-
- let fileName = (avAsset as! AVURLAsset).url.absoluteString
- BFLog(message: "video fileName is\(fileName)")
- let tempPhoto = self.selectedMetarialData?.first(where: { material in
- material.asset == photo.asset
- })
- if fileName.count > 0 {
- createDirectory(path: photoLibraryDirectory)
- let outFilePath = photoLibraryDirectory + fileName.md5 + ".mp4"
-
- if FileManager.default.fileExists(atPath: outFilePath) {
- do {
- try FileManager.default.removeItem(at: NSURL.fileURL(withPath: outFilePath))
- } catch {
- BFLog(message: "导出相册视频-error == \(error)")
- }
- }
- do {
- try FileManager.default.copyItem(atPath: fileName.replacingOccurrences(of: "file:///", with: ""), toPath: outFilePath)
- print("Success to copy file.")
- } catch {
- print("Failed to copy file.")
- }
- tempPhoto?.locationPath = outFilePath.replacingOccurrences(of: documensDirectory, with: "")
- BFLog(message: "导出视频相册地址为 \(String(describing: tempPhoto?.locationPath))")
- dispatchGroup.leave()
- }
- }else {
-
- DispatchQueue.main.async {
- self.synchroMarskView.removeMarskView()
- }
- }
- }
- }
- }
- dispatchGroup.notify(queue: DispatchQueue.main) { [weak self] in
- self?.isExportVideosSuccess = true
- BFLog(message: "所有相册视频导出成功")
-
- if isHaveVideo {
- self?.dealWithDataSuccess()
- }
- }
-
- if !isHaveVideo {
- isExportVideosSuccess = true
- BFLog(message: "所有相册视频导出成功")
- dealWithDataSuccess()
- }
- }
- }
-
-
-
- func dealWithDataSuccess(resetSelectIndex:Bool = true) {
- BFLog(message: "三组参数:\(isSynchroMusicInfoSuccess) \(isStuckPointDataSuccess) \(isExportVideosSuccess)")
- if !isSynchroMusicInfoSuccess || !isStuckPointDataSuccess || !isExportVideosSuccess {
- return
- }
- createPorjectData()
- BFLog(1, message: "界面编辑界面时参数 选择素材时长:\(selectedTotalDuration) 选择素材总数:\(selectedDataCount) 选择图片总数\(selectedImageDataCount) 再创建类型:\(String(describing: reCreateVideoData?.rhythmMode))")
- if(resetSelectIndex){
-
-
-
- if selectedTotalDuration >= 6 && selectedTotalDuration < 80 {
- lastJumpSpeedSelectIndex = 0
- } else if selectedTotalDuration >= 80 && selectedTotalDuration < 120 {
- lastJumpSpeedSelectIndex = 1
- } else if selectedTotalDuration >= 120 && selectedTotalDuration < 160 {
- lastJumpSpeedSelectIndex = 2
- } else if selectedTotalDuration >= 160 && selectedTotalDuration < 200 {
- lastJumpSpeedSelectIndex = 3
- } else if (selectedTotalDuration >= 200 && selectedTotalDuration < 240) || selectedTotalDuration >= 240 {
- lastJumpSpeedSelectIndex = 4
- }
-
-
- if selectedTotalDuration >= 120 && selectedTotalDuration <= 144 || selectedTotalDuration > 144 {
- lastSpeedSelectIndex = 5
- } else if selectedTotalDuration >= 70 && selectedTotalDuration < 120 {
- lastSpeedSelectIndex = 4
- } else if selectedTotalDuration >= 56 && selectedTotalDuration < 70 {
- lastSpeedSelectIndex = 3
- } else if selectedTotalDuration >= 17.5 && selectedTotalDuration < 56 {
- lastSpeedSelectIndex = 2
- } else if selectedTotalDuration >= 10.5 && selectedTotalDuration < 17.5 {
- lastSpeedSelectIndex = 1
- } else if selectedTotalDuration > 0 && selectedTotalDuration < 10.5 {
- lastSpeedSelectIndex = 0
- }
-
-
- if reCreateVideoData != nil {
- BFLog(message: "是再创作进来的 \(reCreateVideoData!.rhythmMode)")
- switch reCreateVideoData!.rhythmMode {
- case 1:
- editModelClick(sender: jumpPointBtn, reportLog: false)
- break
- case 2:
- editModelClick(sender: speedStuckBtn, reportLog: false)
- break
- case 3:
- editModelClick(sender: onlyMusicBtn, reportLog: false)
- break
- default: break
- }
- return
- }
-
- if selectedTotalDuration < 6 && selectedDataCount != selectedImageDataCount {
-
- let styleColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
- jumpPointBtn.setTitleColor(UIColor.init(red: styleColor.rgbaf[0], green: styleColor.rgbaf[1], blue: styleColor.rgbaf[2], alpha: 0.3), for: .selected)
-
- let pointEditNamalBackgroundColor = PQBFConfig.shared.pointEditNamalBackgroundColor
- jumpPointBtn.backgroundColor = UIColor.init(red: pointEditNamalBackgroundColor.rgbaf[0], green: pointEditNamalBackgroundColor.rgbaf[1], blue: pointEditNamalBackgroundColor.rgbaf[2], alpha: 0.3)
-
- }
-
-
-
- if selectedDataCount == selectedImageDataCount {
- BFLog(message: "全是图片 \(selectedDataCount) \(selectedImageDataCount)")
-
- editModelClick(sender: jumpPointBtn, reportLog: false)
- } else {
-
- if selectedTotalDuration > 0 && selectedTotalDuration <= 144 {
- editModelClick(sender: speedStuckBtn, reportLog: false)
- } else {
-
- editModelClick(sender: jumpPointBtn, reportLog: false)
- }
- }
- }else{
- editModelClick(sender: lastEditModelBtn ?? jumpPointBtn, reportLog: false)
- }
-
-
- }
- }
|