AVMutableComposition – Blank/Black frame between videos assets
I’m currently trying to put 5 videos back to back using AVMutableComposition like so:
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset1.duration) ofAsset:asset1 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration) ofAsset:asset2 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset3.duration) ofAsset:asset3 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset4.duration) ofAsset:asset4 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset5.duration) ofAsset:asset5 atTime:[mixComposition duration] error:nil];
I then use an AVAssetExportSession to export the video, which works however between each video I’m getting a blank/black frame which I need to remove. Has anyone had this problem before and if so did you manage to fix it?
Also, the blank frames aren’t in the source video files.
Thanks in advance.
- Exporting mp4 through AVAssetExportSession fails
- Unable to trim a video using AVAssetExportSession
- How do make a reduced size video using AVAssetWriter?
- Long delay before seeing video when AVPlayer created in exportAsynchronouslyWithCompletionHandler
- iOS 5: Error merging 3 videos with AVAssetExportSession
- Square cropping and fixing the video orientation in iOS
2 Solutions Collect From Internet About “AVMutableComposition – Blank/Black frame between videos assets”
I had the same problem the other day.
If you got your assets(asset1, asset2, etc.) by exporting them from other asset which was created using again insertTimeRange, then it’s the same case.
The problem is that when you export assets created using insertTimeRange, the export doesn’t go correct, when you attach such videos black frames appear between them.
Try using “timeRange” option of the AVAssetExportSession, and cut the range you need from the main asset. Then your assets will attach correct.
I just met the same problem. Turn out the solution is using AVMutableCompositionTrack and compositing the video tracks, something like this.
AVMutableCompositionTrack * videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; [videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:composition.duration error:&error];
For the audio part I think you must add a separate track with AVMediaTypeAudio type.
- How can I add properties to an object at runtime?
- Switch container view dynamically
- What gets called when a UISlider value changes?
- Passing data between View Controllers using Segue
- UILocalNotification always shows up as soon as I load my app regardless of the fire date
- AVPlayerViewController black screen when swiping on iOS 11
- external framework File/File.h (Parse/Parse.h) file not found
- Updating MKannotation image without flashing
- UIViewController -dealloc method not called
- How to solve Ambiguous use of 'subscript' in Swift 2?
- Movie player has wrong activation state (1)
- Indenting with white spaces, tabs, and how many spaces or the tab width
- Realm Cleaning Up Old Objects
- iOS 8 Swift Xcode 6 – Set top nav bar bg color and height
- Scrolling background – Sprite Kit