gpt4 book ai didi

ios - 使用 AVFoundation iOS 编辑后,从安卓手机拍摄的视频被毁了

转载 作者:可可西里 更新时间:2023-11-01 02:59:34 24 4
gpt4 key购买 nike

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

});
}
}];
}

谁能帮我解决这个问题?

最佳答案

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

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

关于ios - 使用 AVFoundation iOS 编辑后,从安卓手机拍摄的视频被毁了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38259186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com