7

我正在尝试使用 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);
  }
}
4

0 回答 0