Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HatsuneMikuFansYSQ
LYAVFoundation
提交
8a373ef9
L
LYAVFoundation
项目概览
HatsuneMikuFansYSQ
/
LYAVFoundation
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
LYAVFoundation
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8a373ef9
编写于
8月 23, 2021
作者:
杨
杨时权
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【需求】帧率可配置。
上级
e923efea
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
7 deletion
+42
-7
project/iPhone/LWAVFoundation/LWAVFoundation/AVFoundation/LWVideoCaptureSession.m
...ation/LWAVFoundation/AVFoundation/LWVideoCaptureSession.m
+29
-2
project/iPhone/LWAVFoundation/LWAVFoundation/Model/LWVideoCaptureConfig.h
...WAVFoundation/LWAVFoundation/Model/LWVideoCaptureConfig.h
+5
-0
project/iPhone/LWAVFoundation/LWAVFoundation/Model/LWVideoCaptureConfig.m
...WAVFoundation/LWAVFoundation/Model/LWVideoCaptureConfig.m
+1
-0
project/iPhone/LWAVFoundation/LWAVFoundation/View/LWCheckBoxView.m
...Phone/LWAVFoundation/LWAVFoundation/View/LWCheckBoxView.m
+2
-2
project/iPhone/LWAVFoundation/LWAVFoundation/ViewController/CaptureViewController.m
...ion/LWAVFoundation/ViewController/CaptureViewController.m
+5
-3
未找到文件。
project/iPhone/LWAVFoundation/LWAVFoundation/AVFoundation/LWVideoCaptureSession.m
浏览文件 @
8a373ef9
...
...
@@ -23,8 +23,10 @@
#pragma mark private
-
(
void
)
initAVCaptureSession
{
NSError
*
error
=
nil
;
self
.
session
=
[[
AVCaptureSession
alloc
]
init
];
// 设置视频分辨率
if
(
!
[
self
.
session
canSetSessionPreset
:
self
.
config
.
preset
])
{
if
(
!
[
self
.
session
canSetSessionPreset
:
AVCaptureSessionPresetiFrame960x540
])
{
if
(
!
[
self
.
session
canSetSessionPreset
:
AVCaptureSessionPreset640x480
])
{
...
...
@@ -40,7 +42,7 @@
}
[
self
.
session
setSessionPreset
:
self
.
config
.
preset
];
[
self
.
session
beginConfiguration
];
// 获取系统设备信息
AVCaptureDeviceDiscoverySession
*
deviceDiscoverySession
=
[
AVCaptureDeviceDiscoverySession
discoverySessionWithDeviceTypes
:@[
AVCaptureDeviceTypeBuiltInWideAngleCamera
]
mediaType
:
AVMediaTypeVideo
position
:
self
.
config
.
position
];
NSArray
*
devices
=
deviceDiscoverySession
.
devices
;
for
(
AVCaptureDevice
*
device
in
devices
)
{
...
...
@@ -50,17 +52,38 @@
}
}
NSError
*
error
=
nil
;
// 设置帧率
BOOL
frameRateSupport
=
NO
;
NSArray
*
ranges
=
[
self
.
device
.
activeFormat
videoSupportedFrameRateRanges
];
for
(
AVFrameRateRange
*
range
in
ranges
)
{
if
(
CMTIME_COMPARE_INLINE
(
self
.
config
.
duration
,
>=
,
range
.
minFrameDuration
)
&&
CMTIME_COMPARE_INLINE
(
self
.
config
.
duration
,
<=
,
range
.
maxFrameDuration
))
{
frameRateSupport
=
YES
;
}
}
if
(
frameRateSupport
&&
[
self
.
device
lockForConfiguration
:
&
error
])
{
[
self
.
device
setActiveVideoMaxFrameDuration
:
self
.
config
.
duration
];
[
self
.
device
setActiveVideoMinFrameDuration
:
self
.
config
.
duration
];
[
self
.
device
unlockForConfiguration
];
}
// 开始配置参数
[
self
.
session
beginConfiguration
];
// 从设备中创建输入,之后需要设置到session
self
.
videoInput
=
[[
AVCaptureDeviceInput
alloc
]
initWithDevice
:
self
.
device
error
:
&
error
];
if
(
error
)
{
NSLog
(
@"%s:%d init input error!!!"
,
__func__
,
__LINE__
);
return
;
}
// 设置session的输入
if
([
self
.
session
canAddInput
:
self
.
videoInput
])
{
[
self
.
session
addInput
:
self
.
videoInput
];
}
// 配置session的输出
self
.
videoOutput
=
[[
AVCaptureVideoDataOutput
alloc
]
init
];
self
.
videoOutput
.
alwaysDiscardsLateVideoFrames
=
NO
;
[
self
.
videoOutput
setVideoSettings
:@{
...
...
@@ -73,12 +96,16 @@
[
self
.
session
addOutput
:
self
.
videoOutput
];
}
// 设置连接器
AVCaptureConnection
*
connect
=
[
self
.
videoOutput
connectionWithMediaType
:
AVMediaTypeVideo
];
// 设置图片的位置
connect
.
videoOrientation
=
self
.
config
.
orientation
;
if
([
connect
isVideoStabilizationSupported
])
{
connect
.
preferredVideoStabilizationMode
=
AVCaptureVideoStabilizationModeAuto
;
}
connect
.
videoScaleAndCropFactor
=
connect
.
videoMaxScaleAndCropFactor
;
// 提交采集相关配置
[
self
.
session
commitConfiguration
];
self
.
captureLayer
=
[[
AVCaptureVideoPreviewLayer
alloc
]
initWithSession
:
self
.
session
];
...
...
project/iPhone/LWAVFoundation/LWAVFoundation/Model/LWVideoCaptureConfig.h
浏览文件 @
8a373ef9
...
...
@@ -5,6 +5,8 @@
typedef
NS_ENUM
(
NSUInteger
,
AVCaptureOutputPixelBufferType
)
{
kAVCaptureOutputPixelBufferType_420v
=
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
,
kAVCaptureOutputPixelBufferType_420f
=
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
,
kAVCaptureOutputPixelBufferType_bgra
=
kCVPixelFormatType_32BGRA
,
};
@interface
LWVideoCaptureConfig
:
NSObject
...
...
@@ -21,6 +23,9 @@ typedef NS_ENUM(NSUInteger, AVCaptureOutputPixelBufferType) {
// 视频的方向
@property
(
assign
,
nonatomic
)
AVCaptureVideoOrientation
orientation
;
// 设置每一帧的时间间隔,其的分子为时间,单位秒,分母为帧率。
@property
(
assign
,
nonatomic
)
CMTime
duration
;
-
(
instancetype
)
init
;
@end
...
...
project/iPhone/LWAVFoundation/LWAVFoundation/Model/LWVideoCaptureConfig.m
浏览文件 @
8a373ef9
...
...
@@ -13,6 +13,7 @@
self
.
preset
=
AVCaptureSessionPreset1280x720
;
self
.
pixelBufferType
=
kAVCaptureOutputPixelBufferType_420v
;
self
.
orientation
=
AVCaptureVideoOrientationPortrait
;
self
.
duration
=
CMTimeMake
(
1
,
30
);
}
return
self
;
}
...
...
project/iPhone/LWAVFoundation/LWAVFoundation/View/LWCheckBoxView.m
浏览文件 @
8a373ef9
...
...
@@ -56,11 +56,11 @@
[
self
.
btnItems
addObject
:[[
LWCheckBoxButton
alloc
]
init
]];
self
.
btnItems
[
i
].
contentMode
=
UIViewContentModeScaleAspectFit
;
self
.
btnItems
[
i
].
delegate
=
self
;
self
.
btnItems
[
i
].
tag
=
i
;
[
self
.
labelItems
addObject
:[[
UILabel
alloc
]
init
]];
}
self
.
btnItems
[
i
].
tag
=
i
;
self
.
btnItems
[
i
].
image
=
[
self
.
btnNoSelectImage
imageWithRenderingMode
:
UIImageRenderingModeAlwaysOriginal
];
self
.
btnItems
[
i
].
frame
=
CGRectMake
(
checkBoxItemX
,
checkBoxItemY
,
30
,
30
);
...
...
@@ -93,7 +93,7 @@
self
.
selectItem
=
self
.
items
[
index
];
if
(
self
.
delegate
&&
[
self
.
delegate
respondsToSelector
:
@selector
(
onSelect
:
item
:
)])
{
[
self
.
delegate
onSelect
:
index
item
:
self
.
items
[
index
]
];
[
self
.
delegate
onSelect
:
index
item
:
self
.
selectItem
];
}
}
...
...
project/iPhone/LWAVFoundation/LWAVFoundation/ViewController/CaptureViewController.m
浏览文件 @
8a373ef9
...
...
@@ -36,6 +36,7 @@
self
.
checkBoxView
=
[[
LWCheckBoxView
alloc
]
initWithItems
:
array
];
self
.
checkBoxView
.
frame
=
CGRectMake
(
checkBoxViewX
,
checkBoxViewY
,
checkBoxViewW
,
checkBoxViewH
);
self
.
checkBoxView
.
displayType
=
kLWCheckBoxViewDisplayType_LR
;
self
.
checkBoxView
.
delegate
=
self
;
[
self
.
view
addSubview
:
self
.
checkBoxView
];
self
.
captureTypeLabel
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
checkBoxViewY
,
100
,
30
)];
...
...
@@ -59,9 +60,6 @@
[
self
.
stopBtn
setBackgroundColor
:[
UIColor
whiteColor
]];
[
self
.
stopBtn
addTarget
:
self
action
:
@selector
(
stopSender
:
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
view
addSubview
:
self
.
stopBtn
];
self
.
captureSessionConfig
=
[[
LWVideoCaptureConfig
alloc
]
init
];
self
.
captureSession
=
[[
LWVideoCaptureSession
alloc
]
initWithConfig
:
self
.
captureSessionConfig
];
}
-
(
void
)
viewDidDisappear
:(
BOOL
)
animated
{
...
...
@@ -69,6 +67,9 @@
}
-
(
IBAction
)
startSender
:(
id
)
sender
{
self
.
captureSessionConfig
=
[[
LWVideoCaptureConfig
alloc
]
init
];
self
.
captureSession
=
[[
LWVideoCaptureSession
alloc
]
initWithConfig
:
self
.
captureSessionConfig
];
[
self
.
captureSession
startCapture
];
AVCaptureVideoPreviewLayer
*
layer
=
[
self
.
captureSession
layer
];
...
...
@@ -84,6 +85,7 @@
[
layer
removeFromSuperlayer
];
[
self
.
captureSession
stopCapture
];
self
.
captureSession
=
nil
;
}
#pragma mark LWVideoCaptureSessionDelegate
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录