使用AVFoundation iOS编辑后,从Android手机拍摄的视频会被破坏

Rec*_*ner 9 video-editing ios

我正在开发一个需要编辑视频的应用程序(设置叠加层).现在,虽然从iPhone拍摄的视频编辑得很好,但是从Android手机拍摄的视频在编辑后变得空白.

我无法想象问题会是什么.我希望得到立即的帮助.

这是方法之一(修剪功能).

- (IBAction)cutButtonTapped:(id)sender {

    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = @"Encoding...";

    [self.playButton setBackgroundImage:[UIImage imageNamed:@"video_pause.png"] forState:UIControlStateNormal];



    NSString *uniqueString = [[NSProcessInfo processInfo]globallyUniqueString];

//do this to export video
    NSURL *videoFileUrl = [NSURL fileURLWithPath:[AppHelper userDefaultsForKey:@"videoURL"]];

    AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:nil];
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];

    if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) {

        self.exportSession_ = [[AVAssetExportSession alloc]
                           initWithAsset:anAsset presetName:AVAssetExportPresetPassthrough];
    // Implementation continues.

   //        NSURL *furl = [self newURLWithName:[uniqueString stringByAppendingString:@".mov"]];
          NSURL *furl = [self newURLWithName:[uniqueString stringByAppendingString:[NSString stringWithFormat:@".%@",[videoFileUrl pathExtension]]]];

    self.exportSession_.outputURL = furl;
    self.exportSession_.outputFileType = AVFileTypeMPEG4;

    CMTime start = CMTimeMakeWithSeconds(self.startTime, anAsset.duration.timescale);
    CMTime duration = CMTimeMakeWithSeconds(self.stopTime-self.startTime, anAsset.duration.timescale);
    CMTimeRange range = CMTimeRangeMake(start, duration);
    CMTimeShow( self.exportSession_.timeRange.duration);
    self.exportSession_.timeRange = range;
    CMTimeShow( self.exportSession_.timeRange.duration);

    [self.exportSession_ exportAsynchronouslyWithCompletionHandler:^{

        switch ([self.exportSession_ status]) {
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Export failed: %@", [[self.exportSession_ error] localizedDescription]);
                break;
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Export canceled");
                break;
            default:
                NSLog(@"NONE");
                dispatch_async(dispatch_get_main_queue(), ^{

//                            [self playDocumentDirectoryVideoWithURLString:[uniqueString stringByAppendingString:@".mov"]];
                        [self playDocumentDirectoryVideoWithURLString:[uniqueString stringByAppendingString:[NSString stringWithFormat:@".%@",[videoFileUrl pathExtension]]]];

                });
        }
    }];
}
Run Code Online (Sandbox Code Playgroud)

}

有人可以帮我这个吗?

div*_*ive 1

首先,我建议您检查duration&range值。CMTime这似乎是解码的问题。其次,尝试AVURLAsset使用强制持续时间提取的选项来初始化:

AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @(YES)}];
Run Code Online (Sandbox Code Playgroud)