根据项目要求,视频可以暂停然后继续录制。选择了视频合成。后面有链接
导入AVFoundation库文件用于支持:
AVCaptureSession 链接输入输出设备
AVCaptureDeviceInput 从设备获取输入设备
AVCaptureMovieFileOutput 视频输出
AVCaptureVideoPreviewLayer 录制预览layer
AVMutableComposition 根据MediaType返回音视频轨道
AVMutableVideoComposition 设施输出内容属性,大小,帧数。。。
AVAssetTrack 素材通道
AVURLAsset 获取音视频信息
AVAssetExportSession 输出视频
导入MediaPlayer库用于支持:
MPMoviePlayerController 视频播放控件
info.plist文件需要添加下面内容获取相应权限
Privacy - Camera Usage Description (是否允许此App使用你的相机?)
Privacy - Microphone Usage Description (是否允许此App使用你的麦克风?)
视频合成过程需要时间,这里没做处理,可以根据自己需要添加一个UIActivityIndicatorView
//
// ViewController.m
// VideoRecordText
//
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<AVCaptureFileOutputRecordingDelegate>
@property (strong,nonatomic) AVCaptureSession *captureSession;//负责输入和输出设置之间的数据传递
@property (strong,nonatomic) AVCaptureDeviceInput *captureDeviceInput;//负责从AVCaptureDevice获得输入数据
@property (strong,nonatomic) AVCaptureMovieFileOutput *captureMovieFileOutput;//视频输出流
@property (strong,nonatomic) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;//相机拍摄预览图层
@property (nonatomic,strong)NSString * fileName;//文件夹名
@property (nonatomic,assign)int fileNum;//文件名
@property (nonatomic,strong)NSMutableArray * fileUrlArr;//文件路径数组
@property (nonatomic,strong)MPMoviePlayerController * mediaV;//播放器
@property (nonatomic,strong)UIView * playBcgV;//播放页面
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_fileUrlArr = [[NSMutableArray alloc]init];
_fileName = [NSString stringWithFormat:@"%d",(int)[[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970]];
_fileNum = 0;
[self createPlayBcgV];//播放视图
[self createUI];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)createUI{
UIView * layerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-140)];
layerView.backgroundColor = [UIColor blackColor];
//初始化会话
_captureSession=[[AVCaptureSession alloc]init];
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
}else{
NSLog(@"未获取摄像头权限");
}
}];
//获得输入设备(视频)
AVCaptureDevice *captureDevice=[self getCameraDeviceWithPosition:AVCaptureDevicePositionBack];//取得后置摄像头
if (!captureDevice) {
NSLog(@"取得后置摄像头时出现问题.");
return;
}
NSError