видео, загруженное из приложения iphone на YouTube, не имеет звука - PullRequest
2 голосов
/ 29 марта 2012

Я занимаюсь разработкой приложения для iphone, которое записывает свои действия (запись экрана) и загружает их на YouTube. Во-первых, у видео нет звука, а перед загрузкой приложение смешивает звук с видео. Выходное видео воспроизводится на моем iphone и ipad без каких-либо проблем, но загруженное видео воспроизводится без звука (звук только при запуске). Мой видео формат .mov. мой код для смешивания звука и видео

как в учебнике purplelilgirl

-(NSString*) processVideo: (NSURL*) videoUrl{    NSLog(@"started processing %@",videoUrl);
    AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL: videoUrl options:nil];

    AVMutableComposition* mixComposition = [AVMutableComposition composition];


    NSError * error = nil;

    for (NSMutableDictionary * audioInfo in audioInfoArray){
        // NSString *pathString = [[NSHomeDirectory() stringByAppendingString:@"/Documents/"] stringByAppendingString: [audioInfo objectForKey: @"fileName"]];
       // NSString *pathString =  [audioInfo objectForKey: @"filePath"];
        NSURL *audioUrl=[audioInfo objectForKey: @"filePath"];
       // NSLog(@"audioUrl %@",audioUrl);
        AVURLAsset * urlAsset = [AVURLAsset URLAssetWithURL:audioUrl options:nil];

        AVAssetTrack * audioAssetTrack = [[urlAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
        AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio 
                                                                                       preferredTrackID: kCMPersistentTrackID_Invalid];

       // NSLog(@"%lf", [[audioInfo objectForKey: @"startTime"] doubleValue]);

        CMTime audioStartTime = CMTimeMake(([[audioInfo objectForKey: @"startTime"] doubleValue]*TIME_SCALE), TIME_SCALE);

        [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,urlAsset.duration) ofTrack:audioAssetTrack atTime:audioStartTime error:&error];      
    }


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

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

    NSString* videoName = @"export.mov";

    NSString *exportPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:videoName];
    NSURL    *exportUrl = [NSURL fileURLWithPath:exportPath];

    if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) 
    {
        [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
    }

    _assetExport.outputFileType = @"com.apple.quicktime-movie";
   // _assetExport.outputFileType=AVFileTypeMPEG4;
    NSLog(@"file type %@",_assetExport.outputFileType);
    _assetExport.outputURL = exportUrl;
    _assetExport.shouldOptimizeForNetworkUse = YES;

    [_assetExport exportAsynchronouslyWithCompletionHandler:
     ^(void ) {
         switch (_assetExport.status) 
         {
             case AVAssetExportSessionStatusCompleted:
                 //export complete 
                 NSLog(@"Export Complete");
                 //[self uploadToYouTube];

                 break;
             case AVAssetExportSessionStatusFailed:
                 NSLog(@"Export Failed");
                 NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
                 //export error (see exportSession.error)  
                 break;
             case AVAssetExportSessionStatusCancelled:
                 NSLog(@"Export cancelled");
                 NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
                 //export cancelled  
                 break;
         }
     }];  
    NSLog(@"completed processing exportPath %@ ",exportPath);
    return exportPath;
}

Что не так с моим кодом, вы можете мне помочь

1 Ответ

2 голосов
/ 29 марта 2012

С каким кодеком аудио кодируется? Насколько я понимаю, если вы используете некую форму проприетарного кодека Apple, которая может вызывать ваши проблемы.

...