ios - Merging two recorded videos gives opposite orientation output -
i trying merge 2 recorded videos code:
func exportvideo3() { transprentview.hidden = false activityindicator.startanimating() let composition = avmutablecomposition() let trackvideo = composition.addmutabletrackwithmediatype(avmediatypevideo, preferredtrackid: cmpersistenttrackid()) let trackaudio = composition.addmutabletrackwithmediatype(avmediatypeaudio, preferredtrackid: cmpersistenttrackid()) var inserttime = kcmtimezero let path = nsfilemanager.defaultmanager().urlfordirectory(.documentdirectory, indomain: .userdomainmask, appropriateforurl: nil, create: false, error: nil)!.path! index in 1...2 { let movieurl = index == 1 ? video1url : video2url let sourceasset = avurlasset(url: movieurl, options: nil) let tracks = sourceasset.trackswithmediatype(avmediatypevideo) let audios = sourceasset.trackswithmediatype(avmediatypeaudio) if tracks.count > 0{ let assettrack:avassettrack = tracks[0] as! avassettrack trackvideo.inserttimerange(cmtimerangemake(kcmtimezero,sourceasset.duration), oftrack: assettrack, attime: inserttime, error: nil) let assettrackaudio:avassettrack = audios[0] as! avassettrack trackaudio.inserttimerange(cmtimerangemake(kcmtimezero,sourceasset.duration), oftrack: assettrackaudio, attime: inserttime, error: nil) inserttime = cmtimeadd(inserttime, sourceasset.duration) } } let exporter = avassetexportsession(asset: composition, presetname: avassetexportpresethighestquality) exporter.outputurl = documentsdirectoryurl.urlbyappendingpathcomponent("mergedmovie.mp4") if nsfilemanager.defaultmanager().fileexistsatpath(exporter.outputurl.path!) { nsfilemanager.defaultmanager().removeitematurl(exporter.outputurl, error: nil) } mergedvideourl = exporter.outputurl exporter.outputfiletype = avfiletypempeg4 exporter.exportasynchronouslywithcompletionhandler({ switch exporter.status{ case avassetexportsessionstatus.failed: println("failed \(exporter.error)") case avassetexportsessionstatus.cancelled: println("cancelled \(exporter.error)") default: self.transprentview.hidden = true self.activityindicator.stopanimating() println("complete") } }) }
it working fine new video have opposite orientation. i.e when recored both video in portrait , merge new video plays in landscape mode , when record both in landscape , merge new video plays in portrait mode.
so how can solve issue when record video in landscape mode want output in landscape mode , same portrait.
here sample project more reference.
Comments
Post a Comment