添加ios参数
This commit is contained in:
parent
d9c125bd1c
commit
84879154f9
@ -8,20 +8,24 @@
|
||||
|
||||
#import "SGRecordEncoder.h"
|
||||
#import "SGMotionManager.h"
|
||||
#import "SGRecordOptions.h"
|
||||
|
||||
@interface SGRecordEncoder()
|
||||
@property (nonatomic, strong) AVAssetWriter *writer;//媒体写入对象
|
||||
@property (nonatomic, strong) AVAssetWriterInput *videoInput;//视频写入
|
||||
@property (nonatomic, strong) AVAssetWriterInput *audioInput;//音频写入
|
||||
@property (nonatomic, strong) NSString *path;//写入路径
|
||||
@property (nonatomic, strong) SGRecordOptions * options;
|
||||
@end
|
||||
@implementation SGRecordEncoder
|
||||
|
||||
+ (SGRecordEncoder*)encoderForPath:(NSString*) path Height:(NSInteger) cy width:(NSInteger) cx channels: (int) ch samples:(Float64) rate{
|
||||
+ (SGRecordEncoder*)encoderForPath:(NSString*) path Options:(SGRecordOptions*) options channels: (int) ch samples:(Float64) rate{
|
||||
SGRecordEncoder* enc = [SGRecordEncoder alloc];
|
||||
return [enc initPath:path Height:cy width:cx channels:ch samples:rate];
|
||||
enc.options = options;
|
||||
return [enc initPath:path channels:ch samples:rate];
|
||||
}
|
||||
|
||||
- (instancetype)initPath:(NSString*)path Height:(NSInteger)cy width:(NSInteger)cx channels:(int)ch samples:(Float64) rate{
|
||||
- (instancetype)initPath:(NSString*)path channels:(int)ch samples:(Float64) rate{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.path = path;
|
||||
@ -33,7 +37,7 @@
|
||||
//使其更适合在网络上播放
|
||||
_writer.shouldOptimizeForNetworkUse = YES;
|
||||
//初始化视频输出
|
||||
[self initVideoInputHeight:cy width:cx];
|
||||
[self initVideoInputHeight];
|
||||
//确保采集到rate和ch
|
||||
if (rate != 0 && ch != 0) {
|
||||
//初始化音频输出
|
||||
@ -45,22 +49,16 @@
|
||||
}
|
||||
|
||||
//初始化视频输入
|
||||
- (void)initVideoInputHeight:(NSInteger)cy width:(NSInteger)cx {
|
||||
//录制视频的一些配置,分辨率,编码方式等等
|
||||
NSInteger numPixels = cx * cy;
|
||||
//每像素比特
|
||||
CGFloat bitsPerPixel = 6.0;
|
||||
NSInteger bitsPerSecond = numPixels * bitsPerPixel;
|
||||
|
||||
- (void)initVideoInputHeight {
|
||||
// 码率和帧率设置
|
||||
NSDictionary *compressionProperties = @{ AVVideoAverageBitRateKey:@(bitsPerSecond),
|
||||
AVVideoExpectedSourceFrameRateKey:@(30),
|
||||
AVVideoMaxKeyFrameIntervalKey:@(30),
|
||||
NSDictionary *compressionProperties = @{ AVVideoAverageBitRateKey:@(self.options.bitRate),
|
||||
AVVideoExpectedSourceFrameRateKey:@(self.options.frameRate),
|
||||
AVVideoMaxKeyFrameIntervalKey:@(self.options.frameRate),
|
||||
AVVideoProfileLevelKey:AVVideoProfileLevelH264BaselineAutoLevel };
|
||||
NSDictionary* settings = @{AVVideoCodecKey:AVVideoCodecH264,
|
||||
AVVideoScalingModeKey:AVVideoScalingModeResizeAspectFill,
|
||||
AVVideoWidthKey:@(cx),
|
||||
AVVideoHeightKey:@(cy),
|
||||
AVVideoWidthKey:@(self.options.width),
|
||||
AVVideoHeightKey:@(self.options.height),
|
||||
AVVideoCompressionPropertiesKey:compressionProperties };
|
||||
|
||||
//初始化视频写入类
|
||||
|
@ -10,6 +10,9 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <AVFoundation/AVCaptureVideoPreviewLayer.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
@class SGRecordOptions;
|
||||
|
||||
@protocol SGRecordEngineDelegate <NSObject>
|
||||
|
||||
- (void)recordProgress:(CGFloat)progress;
|
||||
@ -23,6 +26,7 @@
|
||||
@property (weak, nonatomic) id<SGRecordEngineDelegate>delegate;
|
||||
@property (atomic, strong) NSString *videoPath;//视频路径
|
||||
@property (nonatomic, readonly,getter=isRunning) BOOL isRunning; // 捕捉图像
|
||||
@property SGRecordOptions* options;
|
||||
|
||||
/**
|
||||
捕获到的视频呈现的layer
|
||||
|
@ -10,9 +10,8 @@
|
||||
#import "SGRecordEncoder.h"
|
||||
#import <Photos/Photos.h>
|
||||
#import "SGMotionManager.h"
|
||||
#define VIDEO_WIDTH 360
|
||||
#define VIDEO_HEIGHT 640
|
||||
#define MAX_TIME 10
|
||||
#import "SGRecordOptions.h"
|
||||
|
||||
typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
|
||||
@interface SGRecordManager ()<AVCaptureVideoDataOutputSampleBufferDelegate,AVCaptureAudioDataOutputSampleBufferDelegate, CAAnimationDelegate> {
|
||||
CMTime _timeOffset;//录制的偏移CMTime
|
||||
@ -48,7 +47,7 @@ typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.maxRecordTime = MAX_TIME;
|
||||
self.maxRecordTime = self.options.duration;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -199,8 +198,8 @@ typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
|
||||
//添加视频输出
|
||||
if ([_recordSession canAddOutput:self.videoOutput]) {
|
||||
[_recordSession addOutput:self.videoOutput];
|
||||
_cx = VIDEO_WIDTH;
|
||||
_cy = VIDEO_HEIGHT;
|
||||
_cx = self.options.width;
|
||||
_cy = self.options.height;
|
||||
}
|
||||
//添加音频输出
|
||||
if ([_recordSession canAddOutput:self.audioOutput]) {
|
||||
|
@ -11,18 +11,12 @@
|
||||
|
||||
@property (nonatomic, weak) id <CDVCommandDelegate> commandDelegate;
|
||||
@property (strong) NSString* callbackId;
|
||||
@property (strong) NSNumber* quality;
|
||||
@property (assign) UIImagePickerControllerSourceType sourceType;
|
||||
@property (assign) CGSize targetSize;
|
||||
@property (assign) BOOL allowsEditing;
|
||||
@property (assign) BOOL correctOrientation;
|
||||
@property (assign) BOOL saveToPhotoAlbum;
|
||||
@property (strong) NSDictionary* popoverOptions;
|
||||
@property (assign) UIImagePickerControllerCameraDevice cameraDirection;
|
||||
|
||||
@property (assign) BOOL popoverSupported;
|
||||
@property (assign) BOOL usesGeolocation;
|
||||
@property (assign) BOOL cropToSize;
|
||||
@property (assign) NSInteger frameRate;
|
||||
@property (assign) NSInteger bitRate;
|
||||
@property (assign) NSInteger width;
|
||||
@property (assign) NSInteger height;
|
||||
@property (assign) NSInteger limit;// 录制视频最短时间
|
||||
@property (assign) NSInteger duration;
|
||||
|
||||
+ (instancetype) createFromArguments:(CDVInvokedUrlCommand*)command;
|
||||
@end
|
||||
|
@ -14,25 +14,12 @@
|
||||
{
|
||||
SGRecordOptions* options = [[SGRecordOptions alloc] init];
|
||||
options.callbackId = command.callbackId;
|
||||
options.quality = [command argumentAtIndex:0 withDefault:@(50)];
|
||||
options.sourceType = [[command argumentAtIndex:2 withDefault:@(UIImagePickerControllerSourceTypeCamera)] unsignedIntegerValue];
|
||||
|
||||
NSNumber* targetWidth = [command argumentAtIndex:3 withDefault:nil];
|
||||
NSNumber* targetHeight = [command argumentAtIndex:4 withDefault:nil];
|
||||
options.targetSize = CGSizeMake(0, 0);
|
||||
if ((targetWidth != nil) && (targetHeight != nil)) {
|
||||
options.targetSize = CGSizeMake([targetWidth floatValue], [targetHeight floatValue]);
|
||||
}
|
||||
|
||||
options.allowsEditing = [[command argumentAtIndex:7 withDefault:@(NO)] boolValue];
|
||||
options.correctOrientation = [[command argumentAtIndex:8 withDefault:@(NO)] boolValue];
|
||||
options.saveToPhotoAlbum = [[command argumentAtIndex:9 withDefault:@(NO)] boolValue];
|
||||
options.popoverOptions = [command argumentAtIndex:10 withDefault:nil];
|
||||
options.cameraDirection = [[command argumentAtIndex:11 withDefault:@(UIImagePickerControllerCameraDeviceRear)] unsignedIntegerValue];
|
||||
|
||||
options.popoverSupported = NO;
|
||||
options.usesGeolocation = NO;
|
||||
|
||||
options.width = [command argumentAtIndex:0 withDefault:@(360)];
|
||||
options.height = [command argumentAtIndex:1 withDefault:@(640)];
|
||||
options.frameRate = [command argumentAtIndex:2 withDefault:@(30)];
|
||||
options.bitRate = [command argumentAtIndex:3 withDefault: @(options.height * options.width * 6)];
|
||||
options.limit = [command argumentAtIndex:4 withDefault:@(3)];
|
||||
options.duration = [command argumentAtIndex:5 withDefault:@(10)];
|
||||
return options;
|
||||
}
|
||||
@end
|
||||
|
@ -17,11 +17,9 @@
|
||||
#import "SGRecordOptions.h"
|
||||
#import "SGRecordOptions.h"
|
||||
#import "SGMotionManager.h"
|
||||
#define WEAKSELF __weak typeof(self) weakSelf = self;
|
||||
#define STRONGSELF __strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
|
||||
#define TIMER_INTERVAL 0.5 //定时器时间间隔
|
||||
#define RECORD_TIME 0.5 //开始录制视频的时间
|
||||
#define VIDEO_MIN_TIME 3 // 录制视频最短时间
|
||||
@interface SGRecordViewController ()<SGRecordEngineDelegate,UIGestureRecognizerDelegate,SGMotionManagerDeviceOrientationDelegate>
|
||||
@property (nonatomic ,strong) SGRecordManager *recordManger;
|
||||
@property (nonatomic ,assign) BOOL allowRecord;//允许录制
|
||||
@ -164,6 +162,7 @@
|
||||
- (SGRecordManager *)recordManger {
|
||||
if (!_recordManger) {
|
||||
_recordManger = [[SGRecordManager alloc] init];
|
||||
_recordManger.options = self.options;
|
||||
_recordManger.delegate = self;
|
||||
}
|
||||
return _recordManger;
|
||||
@ -365,7 +364,7 @@
|
||||
NSLog(@"开始录制视频");
|
||||
[self.recordButton setScale];
|
||||
[self startRecord];
|
||||
} else if (_timeInterval >= RECORD_TIME + VIDEO_MIN_TIME) {
|
||||
} else if (_timeInterval >= RECORD_TIME + self.options.limit) {
|
||||
[self removeTimer];
|
||||
}
|
||||
}
|
||||
@ -380,7 +379,7 @@
|
||||
- (void)toucheUpInsideOrOutSide:(UIButton *)button{
|
||||
NSLog(@"抬起按钮:__timeInterval==:%f",_timeInterval);
|
||||
[self removeTimer];
|
||||
if (_timeInterval >= RECORD_TIME && _timeInterval < RECORD_TIME + VIDEO_MIN_TIME) {
|
||||
if (_timeInterval >= RECORD_TIME && _timeInterval < RECORD_TIME + self.options.limit) {
|
||||
// 录制时间太短
|
||||
NSLog(@"录制时间太短");
|
||||
[self stopRecord:NO];
|
||||
|
@ -2,6 +2,6 @@ var exec = require('cordova/exec');
|
||||
|
||||
module.exports = {
|
||||
capture(option, success, error) {
|
||||
exec(success, error, 'CapturePlugin', 'capture', [option]);
|
||||
exec(success, error, 'CapturePlugin', 'capture', [option.width,option.height,option.frameRate,option.bitRate,option.limit,option.duration]);
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user