AVPlayerLayer 中显示的 AVAssetTrack 显示不正确
AVAssetTrack displayed in an AVPlayerLayer is displayed incorrectly
我的设置相当简单。我有一个包含视频和音频轨道的作品。视频以左横向或右横向拍摄。视频帧缓冲区使用 AVCaptureVideoDataOutput 对象捕获并使用 AVAssetWriter/AVAssetWriterInput 对象写入。然后这些视频显示在 AVPlayerLayer 中。
我正在根据设备方向设置写入器输入的转换。
if UIDevice.currentDevice.orientation == UIDeviceOrientation.LandscapeRight {
videoWriterVideoInput.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}
在 Quicktime 中查看输出视频如下所示:
接下来,此视频显示在 AVPlayerLayer 中:
使用 AVAssetExportSession 导出 AVMutableComposition 也会导致视频翻转 180 度。
我无法在合成的视频轨道上设置 preferredTransform,因为视频将以横向向左或向右方向录制。
我认为您需要设置连接的方向,以便您在 EXIF 数据上有一个正确的方向。如果它是 EXIF(元数据)的罪魁祸首,那就可以解释为什么它在 QuickTime 中正确显示而不是 iOS。
像这样:
self.captureConnection.setVideoOrientation(UIDevice.currentDevice.orientation)
您遗漏了一些细节,但我将引导您完成一个对我有用的基本过程:
就在我开始视频捕获之前,我调用了一个委托方法来设置 AVAssetWriter
和其他一些东西。在这个方法中我:
AVCaptureConnection *videoConnection = [_myCaptureVideoDataOutput connectionWithMediaType:AVMediaTypeVideo];
// you can use the devices orientation or force one here with a switch statement or something
[videoConnection setVideoOrientation:UIDevice.currentDevice.orientation];
此代码(显然包含所有设置)和简单地调用 _assetWriterVideoInput.transform = CGAffineTransformIdentity;
对我来说效果很好。有很多地方可能会出错,没有更多信息很难判断,但希望这会有所帮助。我担心您正在应用额外的转换,因为它可能会自动使用一组输出样本缓冲区的 AVVideoConnection
。
我的设置相当简单。我有一个包含视频和音频轨道的作品。视频以左横向或右横向拍摄。视频帧缓冲区使用 AVCaptureVideoDataOutput 对象捕获并使用 AVAssetWriter/AVAssetWriterInput 对象写入。然后这些视频显示在 AVPlayerLayer 中。
我正在根据设备方向设置写入器输入的转换。
if UIDevice.currentDevice.orientation == UIDeviceOrientation.LandscapeRight {
videoWriterVideoInput.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}
在 Quicktime 中查看输出视频如下所示:
接下来,此视频显示在 AVPlayerLayer 中:
使用 AVAssetExportSession 导出 AVMutableComposition 也会导致视频翻转 180 度。
我无法在合成的视频轨道上设置 preferredTransform,因为视频将以横向向左或向右方向录制。
我认为您需要设置连接的方向,以便您在 EXIF 数据上有一个正确的方向。如果它是 EXIF(元数据)的罪魁祸首,那就可以解释为什么它在 QuickTime 中正确显示而不是 iOS。
像这样:
self.captureConnection.setVideoOrientation(UIDevice.currentDevice.orientation)
您遗漏了一些细节,但我将引导您完成一个对我有用的基本过程:
就在我开始视频捕获之前,我调用了一个委托方法来设置 AVAssetWriter
和其他一些东西。在这个方法中我:
AVCaptureConnection *videoConnection = [_myCaptureVideoDataOutput connectionWithMediaType:AVMediaTypeVideo];
// you can use the devices orientation or force one here with a switch statement or something
[videoConnection setVideoOrientation:UIDevice.currentDevice.orientation];
此代码(显然包含所有设置)和简单地调用 _assetWriterVideoInput.transform = CGAffineTransformIdentity;
对我来说效果很好。有很多地方可能会出错,没有更多信息很难判断,但希望这会有所帮助。我担心您正在应用额外的转换,因为它可能会自动使用一组输出样本缓冲区的 AVVideoConnection
。