ios自定义视频录制如何设置帧数

最近在研究视频录制,网上找的demo都设置不了帧数,这样就不能通过设置低帧数的方法来达到减小文件大小的目的,网上demo都是这样设置帧数的,以设置最大帧数10为例

//初始化视频输入

NSDictionary*compressionSettings = [NSDictionarydictionaryWithObjectsAndKeys:

[NSNumbernumberWithInteger:300*1000],AVVideoAverageBitRateKey,

[NSNumbernumberWithInteger:10],AVVideoExpectedSourceFrameRateKey,

[NSNumbernumberWithInteger:10],AVVideoMaxKeyFrameIntervalKey,

AVVideoProfileLevelH264HighAutoLevel,AVVideoProfileLevelKey,

nil,nil];

然而你会发现录制出来的还是30帧

正确做法是通过CMTimeperferTimescale来设置,而且得在 添加视频输出和添加音频输出之后设置才有效

//4.1设置采集帧率

CMTimeperferTimescale =CMTimeMake(1,15);

BOOLisSupport =NO;

//获取视频输入设备(摄像头)

AVCaptureDevice*device=[selfbackCamera];//取得后置摄像头

for(AVFrameRateRange*supportFrameindevice.activeFormat.videoSupportedFrameRateRanges) {

int32_tminv =CMTimeCompare(perferTimescale, supportFrame.minFrameDuration);

int32_tmaxv =CMTimeCompare(perferTimescale, supportFrame.maxFrameDuration);

if(maxv <=0&&minv >=0) {

isSupport =YES;

break;

}

}

if(isSupport) {

[devicelockForConfiguration:nil];

device.activeVideoMaxFrameDuration= perferTimescale;

device.activeVideoMinFrameDuration= perferTimescale;

[deviceunlockForConfiguration];

}

你可能感兴趣的:(ios自定义视频录制如何设置帧数)