Don't know where else to ask this, so I thought to start here.
I have two video clips. Neither video clip has any audio.
One video clip is captured from the iPhone's camera via AVCaptureSession.
The second video clip is stored locally on the device.
I want to merge the two videos in a way that plays the captured video in its entirety, followed immediately by one second of the second video clip. I then merge the new video clip with a predetermined audio file and segue to my share menu where I save to the camera roll.
The final result plays exactly as it should in the camera roll. However, when I share the video to Facebook, the first video clip is distorted as a green or sometimes gray screen. The second clip plays fine when its time arrives. And the audio is fine throughout the entire thing.
I have no idea what is causing this.
Any help?
func mergeVideos() { let videoAsset = AVAsset(URL: recordedVideoURL) let videoAsset2 = AVAsset(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Credits", ofType: "mp4")!)) let audioAsset = AVAsset(URL: finalAudioURL) // 1 - Create AVMutableComposition object. let mixComposition = AVMutableComposition() // 2 - Audio track do { let audioTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeAudio, preferredTrackID: 0) try audioTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, audioAsset.duration + CMTime(seconds: 1, preferredTimescale: 30)), ofTrack: audioAsset.tracksWithMediaType(AVMediaTypeAudio)[0], atTime: kCMTimeZero) } catch { print(error) } // 3 - Video tracks do { let videoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)) try videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), ofTrack: videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0], atTime: kCMTimeZero) try videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, audioAsset.duration-videoAsset.duration + CMTime(seconds: 1, preferredTimescale: 30)), ofTrack: videoAsset2.tracksWithMediaType(AVMediaTypeVideo)[0], atTime: videoAsset.duration) } catch { print(error) } // 5 - Create Exporter let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality) deleteFileAtURL(videoToShareURL) exporter!.outputURL = videoToShareURL exporter!.outputFileType = AVFileTypeMPEG4 exporter!.shouldOptimizeForNetworkUse = true // 6 - Perform the Export exporter!.exportAsynchronouslyWithCompletionHandler() { dispatch_async(dispatch_get_main_queue(), { () -> Void in hideSpinner() self.performSegueWithIdentifier("backToShare", sender: self) }) } }
1 Answers
Answers 1
This is counter intuitive, but are you sure this is a problem with iPhone and not Facebook ? There are cases where Facebook videos are not getting played properly and getting played with green screen and proper audio.
It's worth a shot to follow these links on Facebook Help Center and confirm
1 . Green screen on videos on facebook
2 . When I try to play a video I get sound but screen turns green
0 comments:
Post a Comment