如何使用 VideoCore 创建编码会话?
How do I create an encoding session with VideoCore?
我正在将 VideoCore RTMP 编码器集成到我的应用程序中,但我无法启动新的编码会话。我看到 VCSimpleSession
class,但如何启动编码器并查看输出?
VCSimpleSession *mySession = [[VCSimpleSession alloc] init];
我没有看到预览视图。我做错了什么?
VideoCore 使用简单和复杂的图表。 VCSimpleSession
是设置编码器的最简单方法。
VCSimpleSession
有几个不同的初始值设定项:
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps;
// -----------------------------------------------------------------------------
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps
useInterfaceOrientation:(BOOL)useInterfaceOrientation;
// -----------------------------------------------------------------------------
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps
useInterfaceOrientation:(BOOL)useInterfaceOrientation
cameraState:(VCCameraState) cameraState;
// -----------------------------------------------------------------------------
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps
useInterfaceOrientation:(BOOL)useInterfaceOrientation
cameraState:(VCCameraState) cameraState
aspectMode:(VCAspectMode) aspectMode;
videoSize
是编码视频所需的分辨率。
fps
是视频帧率。根据您的服务器设置,您可能希望将其设为 30,如果您的服务器支持,甚至可能设为 60。
bps
是视频比特率,以比特每秒为单位。
useInterfaceOrientation
用于通知编码器设备方向改变。传入YES
将告诉编码器在您旋转设备时旋转视频。
cameraState
用于使用您想要的相机源启动编码器。 VCCameraState
枚举有两个值:VCCameraStateFront
和 VCCameraStateBack
.
aspectMode
用于设置预览视图的纵横比模式。 VCAspectMode 有两个值:VCAspectModeFit
(您的会话视频预览应 "aspect fit" 进入其父视图,以及 VCAscpectModeFill
(缩放您的视频预览以填充其父视图)。
使用这些初始值设定项之一创建新会话。确保在初始化后将会话保留为 属性 或 ivar。初始化后,将会话的 previewView
属性 作为子视图添加到视图控制器上的某些 UIView
。
要连接到服务器,请在您的会话中使用 startRtmpSessionWithURL:
方法。要停止编码器,请调用 endRtmpSession
.
您的完整设置可能如下所示:
@property (weak, nonatomic) IBOutlet UIView *previewView; // This is a UIView on your view controller
@property (weak, nonatomic) VCSimpleSession* session;
// ...
- (void)viewDidLoad
{
[super viewDidLoad];
self.session = [[VCSimpleSession alloc] initWithVideoSize:CGSizeMake(1280, 720) frameRate:30 bitrate:1000000 useInterfaceOrientation:NO];
[self.previewView addSubview:_session.previewView];
[self.previewView bringSubviewToFront:self.session.previewView]
[_session startRtmpSessionWithURL:@"rtmp://192.168.1.151/live" andStreamKey:@"myStream"];
}
完成后:
[self.session endRtmpSession];
我在 VideoCore 示例应用程序上做了一些工作,您应该查看 sample view controller。
我正在将 VideoCore RTMP 编码器集成到我的应用程序中,但我无法启动新的编码会话。我看到 VCSimpleSession
class,但如何启动编码器并查看输出?
VCSimpleSession *mySession = [[VCSimpleSession alloc] init];
我没有看到预览视图。我做错了什么?
VideoCore 使用简单和复杂的图表。 VCSimpleSession
是设置编码器的最简单方法。
VCSimpleSession
有几个不同的初始值设定项:
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps;
// -----------------------------------------------------------------------------
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps
useInterfaceOrientation:(BOOL)useInterfaceOrientation;
// -----------------------------------------------------------------------------
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps
useInterfaceOrientation:(BOOL)useInterfaceOrientation
cameraState:(VCCameraState) cameraState;
// -----------------------------------------------------------------------------
- (instancetype) initWithVideoSize:(CGSize)videoSize
frameRate:(int)fps
bitrate:(int)bps
useInterfaceOrientation:(BOOL)useInterfaceOrientation
cameraState:(VCCameraState) cameraState
aspectMode:(VCAspectMode) aspectMode;
videoSize
是编码视频所需的分辨率。
fps
是视频帧率。根据您的服务器设置,您可能希望将其设为 30,如果您的服务器支持,甚至可能设为 60。
bps
是视频比特率,以比特每秒为单位。
useInterfaceOrientation
用于通知编码器设备方向改变。传入YES
将告诉编码器在您旋转设备时旋转视频。
cameraState
用于使用您想要的相机源启动编码器。 VCCameraState
枚举有两个值:VCCameraStateFront
和 VCCameraStateBack
.
aspectMode
用于设置预览视图的纵横比模式。 VCAspectMode 有两个值:VCAspectModeFit
(您的会话视频预览应 "aspect fit" 进入其父视图,以及 VCAscpectModeFill
(缩放您的视频预览以填充其父视图)。
使用这些初始值设定项之一创建新会话。确保在初始化后将会话保留为 属性 或 ivar。初始化后,将会话的 previewView
属性 作为子视图添加到视图控制器上的某些 UIView
。
要连接到服务器,请在您的会话中使用 startRtmpSessionWithURL:
方法。要停止编码器,请调用 endRtmpSession
.
您的完整设置可能如下所示:
@property (weak, nonatomic) IBOutlet UIView *previewView; // This is a UIView on your view controller
@property (weak, nonatomic) VCSimpleSession* session;
// ...
- (void)viewDidLoad
{
[super viewDidLoad];
self.session = [[VCSimpleSession alloc] initWithVideoSize:CGSizeMake(1280, 720) frameRate:30 bitrate:1000000 useInterfaceOrientation:NO];
[self.previewView addSubview:_session.previewView];
[self.previewView bringSubviewToFront:self.session.previewView]
[_session startRtmpSessionWithURL:@"rtmp://192.168.1.151/live" andStreamKey:@"myStream"];
}
完成后:
[self.session endRtmpSession];
我在 VideoCore 示例应用程序上做了一些工作,您应该查看 sample view controller。