我正在尝试使用UIVideoEditorController修剪视频。修剪或保存后,使用UIVideoEditorController丢失了我的视频分辨率。我使用UIImagePickerController
将设置分辨率的视频转换为UIImagePickerControllerQualityTypeIFrame1280x720
,并将url路径设置为UIVideoEditorController,其属性为videoQuality(iPhone 5)UIImagePickerControllerQualityTypeIFrame1280x720
。当我使用AVFoudation框架捕获视频时,同样的效果。为什么我失去了决心?
我的代码:
if ([UIVideoEditorController canEditVideoAtPath:self.videoPath]) {
//video quality 1280x720
self.editor = [UIVideoEditorController new];
self.editor.videoPath = self.videoPath;
self.editor.videoMaximumDuration = 180.0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
self.editor.videoQuality =
UIImagePickerControllerQualityTypeIFrame1280x720;
#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
self.editor.videoQuality =
UIImagePickerControllerQualityType640x480; // VGA quality
#endif
self.editor.delegate = self;
[self.navigationController presentViewController:self.editor
animated:NO
completion:nil];
} else {
DLog(@"can't edit video at %@", self.videoPath);
}
代表中的:
- (void)videoEditorController:(UIVideoEditorController *)editor
didSaveEditedVideoToPath:(NSString *)editedVideoPath {
[self removeImage:editor.videoPath];
[editor dismissViewControllerAnimated:YES
completion:^{
}];
#if DEBUG
AVAssetTrack *videoTrack = nil;
AVURLAsset *asset =
[AVAsset assetWithURL:[NSURL fileURLWithPath:editedVideoPath]];
NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
CMFormatDescriptionRef formatDescription = NULL;
NSArray *formatDescriptions = [videoTrack formatDescriptions];
if ([formatDescriptions count] > 0)
formatDescription =
(__bridge CMFormatDescriptionRef)[formatDescriptions objectAtIndex : 0];
if ([videoTracks count] > 0)
videoTrack = [videoTracks objectAtIndex:0];
CGSize trackDimensions = {
.width = 0.0, .height = 0.0,
};
trackDimensions = [videoTrack naturalSize];
int width = trackDimensions.width;
int height = trackDimensions.height;
DLog(@"Resolution = %d X %d", width, height); <- 640x320
#endif
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(editedVideoPath)) {
[self convertVideo:[NSURL fileURLWithPath:editedVideoPath]];
} else {
DLog(@"cannot save video on path %@", editedVideoPath);
}
}