Swift
// //安全校验
// var asset_reader : AVAssetReader? = nil
// do {
//
// let compose = try draft.compose()
// let asset = compose.0
//
// try asset_reader = AVAssetReader.init(asset: asset)
//// //视频
//// let video_track : AVAssetTrack = asset.tracks(withMediaType: AVMediaType.video)[0]
//// var videoDictionary = Dictionary<String, Any>.init()
//// videoDictionary.updateValue(NSNumber.init(value: kCVPixelFormatType_32BGRA), forKey: kCVPixelBufferPixelFormatTypeKey as String)
//// let asset_reader_output : AVAssetReaderTrackOutput = AVAssetReaderTrackOutput.init(track: video_track, outputSettings: videoDictionary)
// //音频
// let audio_track : AVAssetTrack = asset.tracks(withMediaType: AVMediaType.audio)[0]
// var audioDictionary = Dictionary<String, Any>.init()
// audioDictionary.updateValue(NSNumber.init(value: kAudioFormatLinearPCM), forKey: AVFormatIDKey)
// let asset_reader_output_audio : AVAssetReaderTrackOutput = AVAssetReaderTrackOutput.init(track: audio_track, outputSettings: audioDictionary)
// //
// if asset_reader != nil {
// //
//// if (asset_reader?.canAdd(asset_reader_output))! {
//// asset_reader?.add(asset_reader_output)
//// }
// if (asset_reader?.canAdd(asset_reader_output_audio))! {
// asset_reader?.add(asset_reader_output_audio)
// }
// //
// if (asset_reader?.startReading())! {
// var buffer : CMSampleBuffer? = nil
// while asset_reader?.status == AVAssetReaderStatus.reading {
//// buffer = asset_reader_output.copyNextSampleBuffer()
// buffer = asset_reader_output_audio.copyNextSampleBuffer()
//
// if buffer != nil {
// //print(buffer)
//// let pixelBuffer : CVPixelBuffer = CMSampleBufferGetImageBuffer(buffer!)!
//// FUManager.share().renderItems(to: pixelBuffer)
// //
// if let encoderTemp = encoder {
// encoderTemp.encodeFrame(buffer)
// }else{
// //encoder = FURecordEncoder.init(path: draft.dir.path, height: CVPixelBufferGetHeight(pixelBuffer), width: CVPixelBufferGetWidth(pixelBuffer))
// encoder = FURecordEncoder.init(path: draft.dir.path, height: 100, width: 100)
// }
// }
// }
// }
// }
// }catch{
// //error异常对象
// print(error)
// }
OC
// static CALayer *layer=nil;
//
// if(!layer){
//
// layer=[CALayer layer];
//
// layer.frame=CGRectMake(20, 0, 320, 320);
//
// layer.contentsGravity=kCAGravityBottomLeft;
//
// layer.contentsScale=[UIScreen mainScreen].scale;
//
// [self.view.layer addSublayer:layer];
//
// [CATransaction setDisableActions:YES];
//
// }
//
//
//
//
//
// AVURLAsset *set=[AVURLAsset URLAssetWithURL:moviePath options:nil];
//
// NSError *error;
//
// AVAssetReader *asset_reader = [[AVAssetReader alloc]initWithAsset:set error:&error];
//
// AVAssetTrack* video_track = [[set tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
//
// NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
//
// [dictionary setObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(NSString *)kCVPixelBufferPixelFormatTypeKey];
//
// AVAssetReaderTrackOutput *asset_reader_output=[[AVAssetReaderTrackOutput alloc]initWithTrack:video_track outputSettings:dictionary];
//
// if([asset_reader canAddOutput:asset_reader_output]){
//
// [asset_reader addOutput:asset_reader_output];
//
// }
//
//
//
// if([asset_reader startReading]){
//
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//
// CMSampleBufferRef buffer=NULL;
//
// while ([asset_reader status]==AVAssetReaderStatusReading) {
//
// buffer=[asset_reader_output copyNextSampleBuffer];
//
// if(buffer){
//
// CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(buffer);
//
// CVPixelBufferLockBaseAddress(imageBuffer,0);
//
// uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
//
// size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
//
// size_t width = CVPixelBufferGetWidth(imageBuffer);
//
// size_t height = CVPixelBufferGetHeight(imageBuffer);
//
//
//
// CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//
// CGContextRef newContext = CGBitmapContextCreate(baseAddress,
//
// width, height,
//
// 8,
//
// bytesPerRow,
//
// colorSpace,
//
// kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
//
// CGImageRef newImage = CGBitmapContextCreateImage(newContext);
//
// CGContextRelease(newContext);
//
// CGColorSpaceRelease(colorSpace);
//
// [layer performSelectorOnMainThread:@selector(setContents:) withObject:(__bridge id)newImage waitUntilDone:YES];
//
// CFRelease(newImage);
//
//
//
// CFRelease(buffer);
//
// }
//
// }
//
//
//
// });
//
// }