问题
I need to record a landscape video inside my portrait iPhone application.
Is it possible or is it blocked by any hardware limitation?
Using AVCaptureVideoPreviewLayer I was able to change the preview orientation, but the video is still recorded in Portrait.
Any idea is welcomed!
回答1:
You should be able to set the orientation to landscape for the video recording. And set the preview layer to portrait to achieve a landscape video that is previewed in portrait. If I understand your question correctly. Can you show any code you tried already?
if captureSession.canAddOutput(videoOutput) {
captureSession.addOutput(videoOutput)
let connection = videoOutput.connectionWithMediaType(AVMediaTypeVideo)
if connection.supportsVideoOrientation {
connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
}
print("adding output")
} else {
print("Could not add front video output")
return
}
...
func setupPreviewLayer() {
...etc...
previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.Portrait
...etc...
}
回答2:
I had a problem playing landscape video in portrait application. Solved it by writing the following code. Add the following code on configuring session:
captureSession.addOutput(videoFileOutput)
let videoDataOuputConnection = videoFileOutput.connection(with: .video)
videoFileOutput.setRecordsVideoOrientationAndMirroringChangesAsMetadataTrack(true, for: videoDataOuputConnection!)
In start recording video function, Add the following code before starting to record:
let videoDataOuputConnection = videoFileOutput.connection(with: .video)
let orientation = UIDevice.current.orientation
videoDataOuputConnection!.videoOrientation = AVCaptureVideoOrientation(rawValue: orientation.rawValue)!
Note: videoFileOutput is of type AVCaptureMovieFileOutput, captureSession is of type AVCaptureSession
来源:https://stackoverflow.com/questions/38072441/how-to-record-landscape-video-in-a-portrait-application-swift-2-iphone