【发布时间】:2010-09-29 16:02:08
【问题描述】:
这就是问题所在。我正在使用 AVCaptureVideoDataOutput 从相机获取视频帧并使用 AVAssetWriter 从它们制作视频。它工作正常,但我得到的视频是颠倒的,因为我的应用程序的默认设备方向是横向左侧,而不是 AVCaptureVideoDataOutput 中默认说明的横向右侧。我试图在 AVCaptureConnection 类中更改方向,但 isVideoOrientationSupported 总是错误的,是否有可能修复它?
这是一些代码:
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput
deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]
error:nil];
/*We setupt the output*/
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
captureOutput.alwaysDiscardsLateVideoFrames = YES;
captureOutput.minFrameDuration = CMTimeMake(1.0, 24.0); //Uncomment it to specify a minimum duration for each video frame
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
// Set the video output to store frame in BGRA (It is supposed to be faster)
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[captureOutput setVideoSettings:videoSettings];
/*And we create a capture session*/
self.captureSession = [[AVCaptureSession alloc] init];
self.captureSession.sessionPreset = AVCaptureSessionPresetLow;
/*We add input and output*/
if ([self.captureSession canAddInput:captureInput])
{
[self.captureSession addInput:captureInput];
}
if ([self.captureSession canAddOutput:captureOutput])
{
[self.captureSession addOutput:captureOutput];
}
/*We add the preview layer*/
self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];
if ([self.prevLayer isOrientationSupported])
{
[self.prevLayer setOrientation:AVCaptureVideoOrientationLandscapeLeft];
}
self.prevLayer.frame = self.view.bounds;
self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer addSublayer: self.prevLayer];
AVCaptureConnection *videoConnection = NULL;
[self.captureSession beginConfiguration];
for ( AVCaptureConnection *connection in [captureOutput connections] )
{
for ( AVCaptureInputPort *port in [connection inputPorts] )
{
if ( [[port mediaType] isEqual:AVMediaTypeVideo] )
{
videoConnection = connection;
}
}
}
if([videoConnection isVideoOrientationSupported]) // **Here it is, its always false**
{
[videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
}
[self.captureSession commitConfiguration];
[self.captureSession startRunning];
更新:发现在导出视频时,AVAssetExportSession 丢失了preferredTransform 信息。
【问题讨论】:
-
史蒂夫,你搞定了吗?我想知道你是如何使用 AVAssetWriter 的。我希望能够从 iphone 流式传输视频。
-
希望对您有所帮助。 pastebin.com/RVEqWnyN
-
当你使用你得到的URL时:“Pastebin”可能已经过期或被删除了!
-
@Steve:hi,现在我也有同样的问题。你有什么解决办法吗???如何使 AVCaptureConnection 支持视频方向????请帮助我
-
请在 Swift 中查看我的Answer。它非常适合我。
标签: iphone objective-c