- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在应用程序中裁剪和合并多个视频。我在步骤的最后部分遇到问题,我需要将视频保存到相机卷轴并且 UIVideoAtPathIsCompatibleWithSavedPhotosAlbum 返回 NO。知道出了什么问题吗?
- (void)video {
self.shouldRotate = NO;
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
NSString* moviePath = nil;
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
// NSLog(@"%@",moviePath);
//NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
}
NSURL* sourceMovieURL = [NSURL fileURLWithPath:moviePath];
NSURL* outputPath = [sourceMovieURL URLByDeletingPathExtension];
outputPath = [outputPath URLByDeletingLastPathComponent];
NSMutableString* last_path_component =
[[NSMutableString alloc] initWithString:[[sourceMovieURL URLByDeletingPathExtension] lastPathComponent]];
[last_path_component appendString:@"~SQUARE"];
outputPath = [outputPath URLByAppendingPathComponent:last_path_component];
outputPath = [outputPath URLByAppendingPathExtension:@"MOV"];
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil];
AVMutableComposition *composition = [AVMutableComposition composition];
[composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
// input clip
AVAssetTrack *clipVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
// make it square
AVMutableVideoComposition* videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.renderSize = CGSizeMake(clipVideoTrack.naturalSize.height, clipVideoTrack.naturalSize.height);
videoComposition.frameDuration = CMTimeMake(1, 30);
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(60, 30) );
// rotate to portrait
AVMutableVideoCompositionLayerInstruction* transformer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:clipVideoTrack];
CGAffineTransform t1 = CGAffineTransformMakeTranslation(clipVideoTrack.naturalSize.height, -(clipVideoTrack.naturalSize.width - clipVideoTrack.naturalSize.height) /2 );
CGAffineTransform t2 = CGAffineTransformRotate(t1, M_PI_2);
CGAffineTransform finalTransform = t2;
[transformer setTransform:finalTransform atTime:kCMTimeZero];
instruction.layerInstructions = [NSArray arrayWithObject:transformer];
videoComposition.instructions = [NSArray arrayWithObject: instruction];
// export
AVAssetExportSession* exporter = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality] ;
exporter.videoComposition = videoComposition;
exporter.outputURL=outputPath;
exporter.outputFileType=AVFileTypeQuickTimeMovie;
VideoButtonView* button = [self.scrollView buttonAdded];
[exporter exportAsynchronouslyWithCompletionHandler:^(void){
AVURLAsset* new_asset = [AVURLAsset URLAssetWithURL:outputPath options:nil];
[button addVideoAsset:new_asset];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (outputPath.absoluteString)) {
UISaveVideoAtPathToSavedPhotosAlbum (outputPath.absoluteString, self, nil, nil);
}
}];
[self dismissViewControllerAnimated:YES completion:nil];
//[picker release];
}
最佳答案
我解决了。使用 assetlibrary 似乎解决了这个问题。
[exporter exportAsynchronouslyWithCompletionHandler:^{
BOOL success = false;
switch ([exporter status]) {
case AVAssetExportSessionStatusCompleted:
success = true;
NSLog(@"Export Completed");
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"Export Waiting");
break;
case AVAssetExportSessionStatusExporting:
NSLog(@"Export Exporting");
break;
case AVAssetExportSessionStatusFailed:
{
NSError *error = [exporter error];
NSLog(@"Export failed: %@", [error localizedDescription]);
break;
}
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
default:
break;
}
if (success == true) {
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary writeVideoAtPathToSavedPhotosAlbum:url completionBlock:^(NSURL *assetURL, NSError *error){
NSError *removeError = nil;
[[NSFileManager defaultManager] removeItemAtURL:url error:&removeError];
}];
}
}];
关于ios - AVAssetExportSession 视频未保存到相机卷轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21275239/
好吧,我有这个静态的导航菜单,但我想让它在用户向下或向上滚动他的页面时流畅地流动...请帮助编写代码,因为我已经尝试过做一些事情,但一切都变坏了。 代码:
我有两个 ionic 滚动标签。在每个 ion-scroll 标签中都有一个列表。这些列表中的每一个都以 10 个项目开始,当用户到达特定 ionic 卷轴的底部时,它应该加载更多。我面临的问题是这无
我的 ionic 应用程序中有一个看起来像这样的模板: {{ monthName }} ... 类为“nav”的
我拼命地试图将目标 div 保持在 float 菜单栏下方。正确的做法是什么? $(document).ready(function () { $('a[href^="#"]').on('cl
我在 silverstripe 网站上运行了无限的 ajax 滚动。我还运行了“NoneLeft”扩展,让人们知道,他们到达了底部。 IAScroll 在 ArticleHolder 页面中显示 Ar
我是一名优秀的程序员,十分优秀!