添加ios参数

This commit is contained in:
zher52 2021-10-11 16:32:39 +08:00
parent d9c125bd1c
commit 84879154f9
7 changed files with 40 additions and 59 deletions

View File

@ -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];
//ratech
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 };
//

View File

@ -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

View File

@ -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]) {

View File

@ -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

View File

@ -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

View File

@ -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];

View File

@ -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]);
}
};