美文网首页
视频的录制

视频的录制

作者: KAKA_move | 来源:发表于2016-12-23 11:31 被阅读0次

#import "ViewController.h"#import@interface ViewController ()/* 输入设备 摄像头*/@property (strong, nonatomic) AVCaptureDeviceInput *videoInput;/* 输入设备 麦克风 */@property (strong, nonatomic) AVCaptureDeviceInput *audioInput;/* 输出设备 */@property (strong, nonatomic) AVCaptureMovieFileOutput *outPut;/* 会话 */@property (strong, nonatomic) AVCaptureSession *session;/* 预览的图层 */@property (weak, nonatomic) AVCaptureVideoPreviewLayer *previewLayer;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // 输入设备  摄像头  麦克风    // 摄像头的输入设备    AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];    self.videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoDevice error:nil];    // 麦克风的输入设备    AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];    self.audioInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];            // 输出设备    self.outPut = [[AVCaptureMovieFileOutput alloc] init];        // 会话  -->链接输入和输出设备    self.session = [[AVCaptureSession alloc] init];    // 添加输入和输出设备    if ([self.session canAddInput:self.videoInput]) {        [self.session addInput:self.videoInput];    }    if ([self.session canAddInput:self.audioInput]) {        [self.session addInput:self.audioInput];    }    if ([self.session canAddOutput:self.outPut]) {        [self.session addOutput:self.outPut];    }        // 预览的图层    AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];    self.previewLayer = previewLayer;    self.previewLayer.frame = self.view.bounds;    [self.view.layer addSublayer:previewLayer];        // 开启会话    [self.session startRunning];}- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event

{

if (self.outPut.isRecording == YES) {

// 停止录制

[self.outPut stopRecording];

}else{

// 文件保存的路径

NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"123.mov"];

// 转换类型

NSURL *url = [NSURL fileURLWithPath:path];

// 开始录制视频  url:视频保存的位置

[self.outPut startRecordingToOutputFileURL:url recordingDelegate:self];

}

}

/// 开始录制视频

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didStartRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections

{

NSLog(@"开始录制视频");

}

/// 录制视频成功

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error

{

NSLog(@"录制视频成功");

}

@end

相关文章

  • 专业正版一键解锁,不要太爽,低调使用...

    录制视频是一个很常见的需求,比如给别人录制操作步骤,做B站等视频平台需要录制视频,录制网课等教学课程,录制游戏视频...

  • 视频的录制

    #import "ViewController.h"#import@interface ViewControlle...

  • 《录制视频》

    讲师四期翟冲【原创】分享第604天2018.08.29今天我们几个伙伴一块录制视频,完成幸福家第三阶的作业。因为昨...

  • 视频录制

    https://www.jianshu.com/p/fe00883ad3d2https://www.jianshu...

  • 视频录制

    视频录制需要导入AVFoundation框架,视频录制的基本步骤: <1>创建视频、音频设备<2>指定视频、音频设...

  • 视频录制

    本篇来自 **WizardDragon **的投稿,分享了他对于四大组件启动时一些方法的调用顺序的研究结果,并且深...

  • 视频录制

    最终诉求? 拍摄、保存、播放、上传。就这四个步骤,当然首先拍摄就有许许多多的优化小功能,切换摄像头、单击跳帧焦距、...

  • 视频录制

    视频录制控件布局文件就是一个surfaceView attrs文件

  • 视频录制

    视频录制上传步骤 登陆平台,查看题目 复制链接到浏览器,建议在谷歌浏览器打开: http://www.baichu...

  • 录制视频

    【幸福老师 李秀清 坚持原创分享 第215天 20190714 星期日】 今晚,我在家里自拍《少年中国说》...

网友评论

      本文标题:视频的录制

      本文链接:https://www.haomeiwen.com/subject/hxrkvttx.html