AVFoundation iOS 编辑后的安卓手机拍摄视频质量变差

9

我正在开发一个需要编辑视频(设置覆盖层)的应用程序。现在,尽管从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]]]];

                });
        }
    }];
}

你能帮我解决这个问题吗?


好的,没问题。请稍等一下。 - Reckoner
嗯,这是一个社交网络应用程序,当有人在安卓设备上发布视频时,我会在我的iPhone上播放该视频。播放正常,但不支持任何视频编辑功能。有些视频会变成空白,而其他一些视频则无法通过AVExportSession导出。 - Reckoner
1
让我们在聊天中继续这个讨论 - Reckoner
有人可以回答这个问题吗?我还没有找到任何解决方案。 - Reckoner
@RhythmicFistman 那会很好,但不幸的是这不是问题所在。我很困惑为什么只有安卓视频出了问题。iPhone 视频和安卓视频有什么区别?AVFoundation 没有捕捉到什么吗? - Reckoner
显示剩余5条评论
1个回答

1
首先,我建议您检查durationrange值。这似乎是与CMTime和解码有关的问题。 其次,尝试使用选项初始化您的AVURLAsset以强制提取持续时间:
AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @(YES)}];

仍然是同样的问题。 - Reckoner
可以在处理之前和之后附上视频吗? - dive
是的,我今天稍后会附上那个。但我想我已经找到了问题所在。问题在于当我尝试调整instructionLayer以调整视频方向时,我遇到了这个问题。但问题是:为什么只对Android视频有效? - Reckoner
抱歉耽搁了。我被卡在另一个问题上了。会在几个小时内更新。 - Reckoner
抱歉,我无法上传图片,但是屏幕会变黑,声音仍然存在。 - Reckoner

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接