PBJVision 0.6.1

PBJVision 0.6.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2019年2月

patrick piemonte 维护。



PBJVision 0.6.1

PBJVision

PBJVision

PBJVision 是一个 iOS 相机库,它允许在您的 iOS 应用中轻松集成特殊捕获特性和自定义相机用户界面。《Next Level》是 Swift 的对应版本。

Build Status Pod Version GitHub license Downloads

特性

  • 触摸录制视频捕获
  • 慢动作捕获(在支持的硬件上为 120 fps)
  • 照片捕获
  • 自定义用户界面和手势交互
  • 上一次录制片段的辉光(洋葱皮肤)效果
  • 闪光灯/手电筒支持
  • 支持自动白平衡、对焦和曝光调整
  • 镜像支持

如果没有使用触摸录制手势交互,也可以进行捕获,如示例项目提供的那样。

关于

这个库最初是在 DIY 上创建的,作为一种让孩子们创作视频和分享他们 技能 的有趣方式。触摸录制交互是由 VineInstagram 率先开发的。

感谢所有为这个有趣的项目和社区做出贡献的人。

快速开始

PBJVision 可用并且推荐使用依赖管理器 CocoaPods 进行安装。

要集成,只需将以下行添加到您的 Podfile

pod 'PBJVision'

用法

导入头文件。

#import "PBJVision.h"

使用 [[PBJVision sharedInstance] previewLayer] 设置摄像头预览。

    // preview and AV layer
    _previewView = [[UIView alloc] initWithFrame:CGRectZero];
    _previewView.backgroundColor = [UIColor blackColor];
    CGRect previewFrame = CGRectMake(0, 60.0f, CGRectGetWidth(self.view.frame), CGRectGetWidth(self.view.frame));
    _previewView.frame = previewFrame;
    _previewLayer = [[PBJVision sharedInstance] previewLayer];
    _previewLayer.frame = _previewView.bounds;
    _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [_previewView.layer addSublayer:_previewLayer];

如果你的视图控制器由 Storyboard 管理,请保持 previewLayer 与设备尺寸同步更新

- (void)viewDidLayoutSubviews
{
    _previewLayer.frame = _previewView.bounds;
}

设置和配置 PBJVision 控制器,然后开始摄像头预览。

- (void)_setup
{
    _longPressGestureRecognizer.enabled = YES;

    PBJVision *vision = [PBJVision sharedInstance];
    vision.delegate = self;
    vision.cameraMode = PBJCameraModeVideo;
    vision.cameraOrientation = PBJCameraOrientationPortrait;
    vision.focusMode = PBJFocusModeContinuousAutoFocus;
    vision.outputFormat = PBJOutputFormatSquare;

    [vision startPreview];
}

开始/暂停/恢复录制。

- (void)_handleLongPressGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
    switch (gestureRecognizer.state) {
      case UIGestureRecognizerStateBegan:
        {
            if (!_recording)
                [[PBJVision sharedInstance] startVideoCapture];
            else
                [[PBJVision sharedInstance] resumeVideoCapture];
            break;
        }
      case UIGestureRecognizerStateEnded:
      case UIGestureRecognizerStateCancelled:
      case UIGestureRecognizerStateFailed:
        {
            [[PBJVision sharedInstance] pauseVideoCapture];
            break;
        }
      default:
        break;
    }
}

结束录制。

    [[PBJVision sharedInstance] endVideoCapture];

根据需要对最终视频输出或错误进行处理。

- (void)vision:(PBJVision *)vision capturedVideo:(NSDictionary *)videoDict error:(NSError *)error
{   
    if (error && [error.domain isEqual:PBJVisionErrorDomain] && error.code == PBJVisionErrorCancelled) {
        NSLog(@"recording session cancelled");
        return;
    } else if (error) {
        NSLog(@"encounted an error in video capture (%@)", error);
        return;
    }

    _currentVideo = videoDict;
    
    NSString *videoPath = [_currentVideo  objectForKey:PBJVisionVideoPathKey];
    [_assetLibrary writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:videoPath] completionBlock:^(NSURL *assetURL, NSError *error1) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Video Saved!" message: @"Saved to the camera roll."
                                                       delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"OK", nil];
        [alert show];
    }];
}

要指定自动结束捕获的最大持续时间,请设置 'PBJVision' 控制器上的以下属性。

    [[PBJVision sharedInstance] setMaximumCaptureDuration:CMTimeMakeWithSeconds(5, 600)]; // ~ 5 seconds

要调整视频质量和压缩比特率,请修改 'PBJVision' 控制器上的以下属性。

    @property (nonatomic, copy) NSString *captureSessionPreset;

    @property (nonatomic) CGFloat videoBitRate;
    @property (nonatomic) NSInteger audioBitRate;
    @property (nonatomic) NSDictionary *additionalCompressionProperties;

社区

欢迎贡献和讨论!

项目

  • 需要帮助?使用带有标签 'pbjvision' 的 Stack Overflow
  • 有问题?使用带有标签 'pbjvision' 的 Stack Overflow
  • 发现了错误?打开 issue
  • 有功能想法?打开 issue
  • 希望做出贡献?提交一个 pull request

相关项目

  • Next Level,Swift中的极简媒体捕获
  • Player,一个简单的Swift版iOS视频播放器
  • PBJVideoPlayer,一个简单的Objective-C版iOS视频播放器

资源

许可证

PBJVision遵循MIT许可证,更多信息请参阅许可证文件