无法设置不同的视频时长,以便在ios中捕获和编辑视频

时间:2015-06-01 04:19:16

标签: ios objective-c video avfoundation

我正在制作项目,我需要设置1分钟进行视频录制,但用户应该编辑并选择30秒持续时间的视频。

以下是我用来启用30秒最长编辑时间的代码。

-(BOOL)startCameraControllerFromViewController: (UIViewController*) controller
                                   usingDelegate: (id <UIImagePickerControllerDelegate,
                                                   UINavigationControllerDelegate>) delegate
{

    if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil))
    {
        return NO;
    }

    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

    // Displays a control that allows the user to choose movie capture
    cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];

    // Hides the controls for moving & scaling pictures, or for
    // trimming movies. To instead show the controls, use YES.
    cameraUI.allowsEditing = YES;
    cameraUI.videoMaximumDuration = 30;
    cameraUI.delegate = delegate;

    [controller presentModalViewController: cameraUI animated: YES];
    return YES;
}

任何帮助都将受到高度赞赏。

3 个答案:

答案 0 :(得分:0)

Apple提供了视频编辑示例。您可以参考一下AVEditDemo示例是在WWDC 2010示例代码包中我认为是这样....

答案 1 :(得分:0)

videoMaximumDuration只能限制UIImagePickerController的录制时间。

一种解决方案可能是滚动您自己的相机控件 - 即将showsCameraControls属性设置为NO并使用cameraOverlayView属性在自定义视图中提供您自己的控件 - 并让您的“捕获”按钮调用图像选择控制器的-startVideoCapture和-stopVideoCapture由NSTimer

监管

答案 2 :(得分:0)

用于选择视频并使修剪功能启用最大长度为30秒,您可以尝试以下代码:

-(IBAction)tapSelectVideo:(id)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = @[(NSString *) kUTTypeMovie];
        imagePicker.allowsEditing = YES;
        [imagePicker setVideoMaximumDuration:30];
        [imagePicker setVideoQuality:UIImagePickerControllerQualityTypeMedium];

        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}