我一直在试图让我的头发试图让AVFoundation相机以正确的方向(即设备方向)拍摄图片,但我无法让它工作.
我看过教程,我看过WWDC演示文稿,我已经下载了WWDC示例程序,但即便如此也没有.
我的应用程序的代码是......
AVCaptureConnection *videoConnection = [CameraVC connectionWithMediaType:AVMediaTypeVideo fromConnections:[imageCaptureOutput connections]];
if ([videoConnection isVideoOrientationSupported])
{
[videoConnection setVideoOrientation:[UIApplication sharedApplication].statusBarOrientation];
}
[imageCaptureOutput captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
if (imageDataSampleBuffer != NULL)
{
//NSLog(@"%d", screenOrientation);
//CMSetAttachment(imageDataSampleBuffer, kCGImagePropertyOrientation, [NSString stringWithFormat:@"%d", screenOrientation], 0);
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self processImage:image];
}
}];
Run Code Online (Sandbox Code Playgroud)
(processImage使用与WWDC代码相同的writeImage ...方法)
并且WWDC应用程序的代码是......
AVCaptureConnection *videoConnection = [AVCamDemoCaptureManager connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([videoConnection isVideoOrientationSupported]) {
[videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
}
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if …Run Code Online (Sandbox Code Playgroud) 我试图在mac os x上镜像从网络摄像头收到的视频.我希望在收到视频缓冲区后避免进行手动翻转/转换.所以,我想设置AVCaptureSession这样的captureOutput方法接收的视频缓冲区AVCaptureVideoDataOutputSampleBufferDelegate由AVFoundation本身镜像.我不想使用预览图层.
在iMac(10.8.5)上,镜像视频,AVCaptureConnection isVideoMirroringSupported在设置videoMirrored属性之前已成功通过测试.但代理中收到的视频缓冲区captureOutput未镜像.
注意:当我按照这个 SO答案时,iOS上的视频镜像是成功的.但它对mac os x没有帮助.
使用的代码如下.此帖子遗漏了错误检查.
//create session
_session = [[AVCaptureSession alloc] init];
//get capture device
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//create sesion input
NSError * error;
_sessionInput = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error];
//create session output
_sessionOutput = [[AVCaptureVideoDataOutput alloc] init];
[_sessionOutput setAlwaysDiscardsLateVideoFrames:YES];
[[_sessionOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:YES];
NSDictionary *videoSettings = [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
[_sessionOutput setVideoSettings:videoSettings];
//serial queue to process video frames
dispatch_queue_t …Run Code Online (Sandbox Code Playgroud) 我正在使用AVAssetReader和AVAssetWriter将视频从一个文件转码到另一个文件.AVAssetReaderTrackOutput已添加到AVAssetReader.遗憾的是,单曲目的preferredTransform属性未从输入复制到输出,因此以纵向方向录制的视频以横向方式播放.
如何在输出文件中设置preferredTransform属性?