Hier ist das Problem. Ich benutze AVCaptureVideoDataOutput, um Videobilder von der Kamera zu erhalten und Videos von ihnen mit AVAssetWriter zu machen. Es funktioniert OK, aber das Video, das ich bekomme, steht auf dem Kopf, weil die Standardausrichtung des Geräts für meine App Landschaft links ist, nicht Landschaft rechts, wie es standardmäßig in AVCaptureVideoDataOutput angegeben ist. Ich versuche, die Ausrichtung in AVCaptureConnection-Klasse ändern, aber isVideoOrientationSupported ist immer falsch, ist es irgendwie möglich, es zu beheben? HierSo ändern Sie die Videoausrichtung für AVCaptureVideoDataOutput
ist ein Code:
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];
Upd: dachte, dass, wenn das Video zu exportieren, die AVAssetExportSession verliert preferredTransform Info.
Steve, hast du das funktioniert? Ich wollte wissen, wie du den AVAssetWriter damit benutzt hast. Ich möchte Videos vom iPhone streamen können. – nickfox
Hoffe es hilft. http://pastebin.com/RVEqWnyN – Steve
Wenn Sie die URL verwenden, erhalten Sie: Die "Pastebin" kann abgelaufen oder gelöscht worden sein! –