首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVURLAsset不能使用iphone

AVURLAsset不能使用iphone
EN

Stack Overflow用户
提问于 2011-08-08 15:52:43
回答 2查看 870关注 0票数 0

即时通讯同步的音频和视频文件使用AVURLAsset.Im得到导出的文件,但只有音频导出,而不是video.How来解决这个issue.please帮助me.Thanks提前。

我正在使用下面的代码:

代码语言:javascript
复制
moviePlayer = [[VideoPlay alloc]initWithNibName:@"VideoPlay" bundle:nil];


    if(sp==1){
           NSURL *VUrl = [NSURL URLWithString:elements.videoUrl];
        NSURL *AUrl = [NSURL URLWithString:elements.audioUrl1 ];
        NSLog(@"%@--%@",AUrl,VUrl);




        AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:AUrl options:nil];
        AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:VUrl options:nil];

        AVMutableComposition* mixComposition = [AVMutableComposition composition];

        AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio                                                                                                     preferredTrackID:kCMPersistentTrackID_Invalid];
        [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) 
                                            ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] 
                                             atTime:kCMTimeZero error:nil];

        AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo                                                                                                preferredTrackID:kCMPersistentTrackID_Invalid];
        [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) 
                                       ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
                                        atTime:kCMTimeZero error:nil];

        AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition 
                                                                              presetName:AVAssetExportPresetPassthrough];   

        NSString *videoName = @"export.m4v";

        NSString *exportPath = [NSTemporaryDirectory() stringByAppendingPathComponent:videoName];
        NSURL    *exportUrl = [NSURL fileURLWithPath:exportPath];

        if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) 
        {
            [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
        }
         NSLog(@"Export Status %d-- ", _assetExport.status);
        _assetExport.outputFileType = @"com.apple.quicktime-movie";
        NSLog(@"file type %@",_assetExport.outputFileType);
        _assetExport.outputURL = exportUrl;
        _assetExport.shouldOptimizeForNetworkUse = YES;

        [_assetExport exportAsynchronouslyWithCompletionHandler:
         ^(void ) { 

             NSLog(@"hello");
             switch (_assetExport.status) 
             {
                 case AVAssetExportSessionStatusFailed:
                 {
                     NSLog (@"FAIL %@",_assetExport.error);
                     if ([[NSFileManager defaultManager] fileExistsAtPath:[_assetExport.outputURL path]]) 
                     {
                         [[NSFileManager defaultManager] removeItemAtPath:[_assetExport.outputURL path] error:nil];
                     }

                     //                            // [self performSelectorOnMainThread:@selector (ritenta)
                     //                                                    withObject:nil
                     //                                                 waitUntilDone:NO];
                     break;
                 }
                 case AVAssetExportSessionStatusCompleted: 
                 {

                     //                            // [self performSelectorOnMainThread:@selector (saveVideoToAlbum:)
                     //                                                    withObject:exportPath
                     //                                                 waitUntilDone:NO];
                     break;
                 }
                 case AVAssetExportSessionStatusCancelled: 
                 {
                     NSLog (@"CANCELED");

                     break;
                 }
             }
             NSLog(@"Export Status %d-- %@", _assetExport.status, _assetExport.outputURL);
             if(_assetExport.status==3){
                moviePlayer.videolink = _assetExport.outputURL;
                 [self presentModalViewController:moviePlayer animated:YES];    
                 [moviePlayer readyPlayer];
             }

            }


         ];                
           }
EN

回答 2

Stack Overflow用户

发布于 2011-08-08 15:56:27

  1. 将您的代码简化为显示问题的smallest working sample
  2. 检查返回的错误。
  3. 尝试使用不同的导出预设代替AVAssetExportPresetPassthrough.
票数 2
EN

Stack Overflow用户

发布于 2016-04-06 17:38:36

尝试不同的导出预设,而不是AVAssetExportPresetPassthrough和NSString *videoName = @"export.mp4“,而不是NSString *videoName = @"export.m4v";

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6979143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档