xcode – AvMutableComposition在最后发出黑框

xcode – AvMutableComposition在最后发出黑框,第1张

概述我在iOS应用程序中使用AVCaptureConnection捕获视频.之后,我在视频中添加一些图像作为CALayers.一切都运行正常,但在添加图像后,在结果视频的最后得到一个黑框.在此没有影响实际音频/视频的帧.对于音频我正在提取它并改变它的音高然后使用AVMutableComposition添加它.这是我正在使用的代码.请帮我解决我做错了什么,或者我需要添加其他东西. cmp = [AVMu 我在iOS应用程序中使用AVCaptureConnection捕获视频.之后,我在视频中添加一些图像作为CALayers.一切都运行正常,但在添加图像后,在结果视频的最后得到一个黑框.在此没有影响实际音频/视频的帧.对于音频我正在提取它并改变它的音高然后使用AVMutableComposition添加它.这是我正在使用的代码.请帮我解决我做错了什么,或者我需要添加其他东西.

cmp = [AVMutableComposition composition];    AVMutableCompositionTrack *vIDeoComposition = [cmp addMutableTrackWithMediaType:AVMediaTypeVIDeo preferredTrackID:kCMPersistentTrackID_InvalID];    AVMutableCompositionTrack *audioComposition = [cmp addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_InvalID];    AVAssetTrack *sourceVIDeoTrack = [[asset tracksWithMediaType:AVMediaTypeVIDeo] objectAtIndex:0];    AVAssetTrack *sourceAudioTrack = [[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];    [vIDeoComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero,[asset duration]) ofTrack:sourceVIDeoTrack atTime:kCMTimeZero error:nil] ;    [audioComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero,[asset duration]) ofTrack:sourceAudioTrack atTime:kCMTimeZero error:nil];    animComp = [AVMutableVIDeoComposition vIDeoComposition];    animComp.renderSize = CGSizeMake(320,320);    animComp.frameDuration = CMTimeMake(1,30);    animComp.animationTool = [AVVIDeoCompositionCoreAnimationTool vIDeoCompositionCoreAnimationToolWithPostProcessingAsVIDeolayer:vIDeolayer  inLayer:parentLayer];    // to gather the audio part of the vIDeo    NSArray *tracksToDuck = [cmp tracksWithMediaType:AVMediaTypeAudio];    NSMutableArray *trackMixArray = [NSMutableArray array];    for (NSInteger i = 0; i < [tracksToDuck count]; i++) {        AVMutableAudioMixinputParameters *trackMix = [AVMutableAudioMixinputParameters audioMixinputParametersWithTrack:[tracksToDuck objectAtIndex:i]];        [trackMix setVolume:5 atTime:kCMTimeZero];        [trackMixArray addobject:trackMix];    }    audioMix = [AVMutableAudioMix audioMix];    audioMix.inputParameters = trackMixArray;    AVMutableVIDeoCompositionInstruction *instruction = [AVMutableVIDeoCompositionInstruction vIDeoCompositionInstruction];    instruction.timeRange = CMTimeRangeMake(kCMTimeZero,[asset duration]);    AVMutableVIDeoCompositionLayerInstruction *layerVIDeoInstruction = [AVMutableVIDeoCompositionLayerInstruction vIDeoCompositionLayerInstructionWithAssetTrack:vIDeoComposition];    [layerVIDeoInstruction setopacity:1.0 atTime:kCMTimeZero];    instruction.layerInstructions = [NSArray arrayWithObject:layerVIDeoInstruction] ;    animComp.instructions = [NSArray arrayWithObject:instruction];    [self exportMovIE:self];

这是我导出视频的方法

-(IBAction) exportMovIE:(ID)sender{    //successCheck = NO;    NSArray *docPaths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);    Nsstring *tempPath = [docPaths objectAtIndex:0];    //NSLog(@"Temp Path: %@",tempPath);    Nsstring *filename = [Nsstring stringWithFormat:@"%@/Final.MP4",tempPath];    NSfileManager *fileManager = [NSfileManager defaultManager] ;    if([fileManager fileExistsAtPath:filename ]){        NSError *ferror = nil ;        [fileManager removeItemAtPath:filename error:&ferror];    }    NSURL *exportURL = [NSURL fileURLWithPath:filename];    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:cmp presetname:AVAssetExportPresetMediumQuality]  ;    exporter.outputURL = exportURL;    exporter.vIDeoComposition = animComp;    //exporter.audioMix = audioMix;    exporter.outputfileType = AVfileTypeQuickTimeMovIE;    [exporter exportAsynchronouslyWithCompletionHandler:^(voID){        switch (exporter.status) {            case AVAssetExportSessionStatusFailed:{                NSLog(@"Fail");                break;            }            case AVAssetExportSessionStatusCompleted:{                NSLog(@"Success vIDeo");                                });                break;            }            default:                break;        }           }];    NSLog(@"outsIDe");}
解决方法 有一个出口的属性给出时间范围,尝试给时间范围少于实际时间(少几纳秒) 总结

以上是内存溢出为你收集整理的xcode – AvMutableComposition在最后发出黑框全部内容,希望文章能够帮你解决xcode – AvMutableComposition在最后发出黑框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1026398.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存