视频流中的方向如何工作 [Objective-C]
How orientation work in video streaming [Objective-C]
我在我的应用程序中使用 medialibdemos3x & 我的问题是当我以横向模式流式传输视频时,它显示如下图:
Image
& 这是我的代码:
@interface ViewControllerPublish () <MPIMediaStreamEvent>{
MemoryTicker *memoryTicker;
RTMPClient *socket;
BroadcastStreamClient *upstream;
MPVideoResolution resolution;
AVCaptureVideoOrientation orientation;
UIActivityIndicatorView *netActivity;
UIDeviceOrientation deviceOrientation;}
-(void)viewDidLoad {
//[DebLog setIsActive:YES];
[super viewDidLoad];
[self initNetActivity];
memoryTicker = [[MemoryTicker alloc] initWithResponder:self andMethod:@selector(sizeMemory:)];
memoryTicker.asNumber = YES;
socket = nil;
upstream = nil;}
-(void)doConnect {
resolution = RESOLUTION_CIF;
#if upstream = [[BroadcastStreamClient alloc] init:host resolution:resolution];
//upstream = [[BroadcastStreamClient alloc] initOnlyAudio:hostTextField.text];
//upstream = [[BroadcastStreamClient alloc] initOnlyVideo:hostTextField.text resolution:resolution];
#else
if (!socket) {
socket = [[RTMPClient alloc] init:hostTextField.text];
if (!socket) {
[self showAlert:@"Connection has not be created"];
return;}
[socket spawnSocketThread];}
upstream = [[BroadcastStreamClient alloc] initWithClient:socket resolution:resolution];
#endif
upstream.delegate = self;
upstream.videoCodecId = MP_VIDEO_CODEC_H264;
upstream.audioCodecId = MP_AUDIO_CODEC_AAC;
& 这是我的定位代码:
deviceOrientation =
[[UIDevice currentDevice] orientation];
if ( deviceOrientation == UIDeviceOrientationLandscapeLeft )
orientation = AVCaptureVideoOrientationLandscapeRight;
else if ( deviceOrientation == UIDeviceOrientationLandscapeRight )
orientation = AVCaptureVideoOrientationLandscapeLeft;
else orientation = AVCaptureVideoOrientationPortrait;
[upstream setVideoOrientation:orientation];
[upstream stream:stream publishType:PUBLISH_LIVE];
//[upstream stream:streamTextField.text orientation:orientation publishType:PUBLISH_RECORD];
//[upstream stream:streamTextField.text orientation:orientation publishType:PUBLISH_APPEND];
btnConnect.title = @"Disconnect";
[netActivity startAnimating];}
有没有办法解决这个问题?
谢谢
根据 Apple 指南,您不能在使用导航控制器时针对不同 viewController
强行更改应用程序的方向。您可以设置或允许特定 viewcontroller
的方向,但用户必须旋转设备。
参考此 link 以了解如何允许不同的方向。这有很好的问题和很多好的答案。 click here
希望这会有所帮助。 :)
我在我的应用程序中使用 medialibdemos3x & 我的问题是当我以横向模式流式传输视频时,它显示如下图:
Image
& 这是我的代码:
@interface ViewControllerPublish () <MPIMediaStreamEvent>{
MemoryTicker *memoryTicker;
RTMPClient *socket;
BroadcastStreamClient *upstream;
MPVideoResolution resolution;
AVCaptureVideoOrientation orientation;
UIActivityIndicatorView *netActivity;
UIDeviceOrientation deviceOrientation;}
-(void)viewDidLoad {
//[DebLog setIsActive:YES];
[super viewDidLoad];
[self initNetActivity];
memoryTicker = [[MemoryTicker alloc] initWithResponder:self andMethod:@selector(sizeMemory:)];
memoryTicker.asNumber = YES;
socket = nil;
upstream = nil;}
-(void)doConnect {
resolution = RESOLUTION_CIF;
#if upstream = [[BroadcastStreamClient alloc] init:host resolution:resolution];
//upstream = [[BroadcastStreamClient alloc] initOnlyAudio:hostTextField.text];
//upstream = [[BroadcastStreamClient alloc] initOnlyVideo:hostTextField.text resolution:resolution];
#else
if (!socket) {
socket = [[RTMPClient alloc] init:hostTextField.text];
if (!socket) {
[self showAlert:@"Connection has not be created"];
return;}
[socket spawnSocketThread];}
upstream = [[BroadcastStreamClient alloc] initWithClient:socket resolution:resolution];
#endif
upstream.delegate = self;
upstream.videoCodecId = MP_VIDEO_CODEC_H264;
upstream.audioCodecId = MP_AUDIO_CODEC_AAC;
& 这是我的定位代码:
deviceOrientation =
[[UIDevice currentDevice] orientation];
if ( deviceOrientation == UIDeviceOrientationLandscapeLeft )
orientation = AVCaptureVideoOrientationLandscapeRight;
else if ( deviceOrientation == UIDeviceOrientationLandscapeRight )
orientation = AVCaptureVideoOrientationLandscapeLeft;
else orientation = AVCaptureVideoOrientationPortrait;
[upstream setVideoOrientation:orientation];
[upstream stream:stream publishType:PUBLISH_LIVE];
//[upstream stream:streamTextField.text orientation:orientation publishType:PUBLISH_RECORD];
//[upstream stream:streamTextField.text orientation:orientation publishType:PUBLISH_APPEND];
btnConnect.title = @"Disconnect";
[netActivity startAnimating];}
有没有办法解决这个问题? 谢谢
根据 Apple 指南,您不能在使用导航控制器时针对不同 viewController
强行更改应用程序的方向。您可以设置或允许特定 viewcontroller
的方向,但用户必须旋转设备。
参考此 link 以了解如何允许不同的方向。这有很好的问题和很多好的答案。 click here
希望这会有所帮助。 :)