AVAssetTrack preferredTransform始终返回格局

 _Cokoice 发布于 2023-02-12 10:51

我有应用程序记录视频.

要处理电话轮换,我有以下代码:

    // called on phone rotation
    AVCaptureConnection *previewLayerConnection = [[self previewLayer] connection];
    if ([previewLayerConnection isVideoOrientationSupported]) {
        [previewLayerConnection setVideoOrientation:[self getVideoOrientation]];
    }

和getVideoOrientation函数:

- (AVCaptureVideoOrientation) getVideoOrientation {
    UIInterfaceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    AVCaptureVideoOrientation newOrientation = AVCaptureVideoOrientationPortrait;
    switch (deviceOrientation) {
        case UIInterfaceOrientationPortrait:
            NSLog(@"UIInterfaceOrientationPortrait");
            newOrientation = AVCaptureVideoOrientationPortrait;
            break;
        case UIInterfaceOrientationLandscapeLeft:
            NSLog(@"UIInterfaceOrientationLandscapeRight");
            newOrientation = AVCaptureVideoOrientationLandscapeLeft;
            break;
        case UIInterfaceOrientationLandscapeRight:
            NSLog(@"UIInterfaceOrientationLandscapeLeft");
            newOrientation = AVCaptureVideoOrientationLandscapeRight;
            break;
        default:
            NSLog(@"default");
            newOrientation = AVCaptureVideoOrientationPortrait;
            break;
    }

    return newOrientation;
}

应用程序的这一部分正常工作(我在任何设备方向上都可以看到视频).但是当我尝试制作缩略图(或播放视频)时,我遇到了问题.

正如我在其他问题中所读到的,我为每首曲目做了以下事情:

        AVAssetTrack* videoTrack    = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
        CGAffineTransform txf       = [videoTrack preferredTransform];
        CGFloat videoAngleInDegree  = RadiansToDegrees(atan2(txf.b, txf.a));

        if (txf.a == 0 && txf.b == 1.0 && txf.c == -1.0 && txf.d == 0) {
            thumbOrientation = UIImageOrientationLeft;
        }
        if (txf.a == 0 && txf.b == -1.0 && txf.c == 1.0 && txf.d == 0) {
            thumbOrientation =  UIImageOrientationRight;
        }
        if (txf.a == 1.0 && txf.b == 0 && txf.c == 0 && txf.d == 1.0) {
            thumbOrientation =  UIImageOrientationUp;
        }
        if (txf.a == -1.0 && txf.b == 0 && txf.c == 0 && txf.d == -1.0) {
            thumbOrientation = UIImageOrientationDown;
        }

        UIImage *image = [UIImage imageWithCGImage:im scale:1.0 orientation:thumbOrientation];

我有2个示例文件:1 - 右侧景观,2 - 左侧景观.我希望它们在上面的代码中有不同的方向,但出乎意料的是它们具有相同的(并且videoAngleInDegree对于它们都是相同的).

有没有解决方法?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有