AVPlayerItemVideoOutput copyPixelBuffer始终返回1280x720 [英] AVPlayerItemVideoOutput copyPixelBuffer always returns 1280x720

查看:66
本文介绍了AVPlayerItemVideoOutput copyPixelBuffer始终返回1280x720的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我像这样实例化AVPlayerItemVideoOutput:

Im instanciating the AVPlayerItemVideoOutput like so:

let videoOutput = AVPlayerItemVideoOutput(pixelBufferAttributes: [String(kCVPixelBufferPixelFormatTypeKey): NSNumber(value: kCVPixelFormatType_32BGRA)])

并像这样检索pixelBuffers:

And retrieving the pixelBuffers like this:

@objc func displayLinkDidRefresh(link: CADisplayLink) {
        let itemTime = videoOutput.itemTime(forHostTime: CACurrentMediaTime())

        if videoOutput.hasNewPixelBuffer(forItemTime: itemTime) {
            if let pixelBuffer = videoOutput.copyPixelBuffer(forItemTime: itemTime, itemTimeForDisplay: nil) {

            }
        }
    }

但是由于某些原因 CVPixelBufferGetHeight(pixelBuffer)或Width.当iPhone的摄像头(横向或纵向)始终高度= 1280宽度= 720拍摄视频时,始终返回1280x720.即使是4k视频也是如此.如果加载来自instagram的方形视频或从互联网下载的任何其他视频(不是直接用相机应用程序直接创建),则在分辨率小于720p时会正确打印宽度和高度.但是不同的分辨率,例如.1008x1792将抛出CVPixelBufferGetHeight(pixelBuffer)= 1280

But for some reason CVPixelBufferGetHeight(pixelBuffer) or Width. always return 1280x720 when the video was taken when the iPhone's camera (landscape or portrait) always height=1280 width=720. EVEN if the video is 4k. If I load a square video from instagram or any other video downloaded from the internet (not created directly with the camera app) the width and height are printed correctly when the resolution is less than 720p. But a different resolution, for ex. a 1008x1792 will throw CVPixelBufferGetHeight(pixelBuffer) = 1280

用相机拍摄的视频...它总是会产生较低的分辨率.我尝试了4k和1080设置(您可以在iOS设置>相机中进行更改).仍然..即使在1080中,我也会获得1280x720像素的缓冲区.

Videos taken with the camera... it always throws a lower res. I tried 4k and 1080 settings (you can change that in iOS Settings > Camera). still.. even in 1080, I get 1280x720 pixel buffers.

推荐答案

我发现我正在使用的UIPickerController设置为默认将所选视频从库转码为中"设置.在这种情况下是1280x720

I figured out that th UIPickerController I was using was set to default transcode the selected video from library to a Medium setting. in this case it was 1280x720

我最终更改了选择器的此属性

I ended up changing this properties of the picker

picker.videoQuality = .typeHigh 
picker.videoExportPreset =  AVAssetExportPresetHighestQuality 

实际上进行更改的属性是 videoExportPreset ,另一个我不知道它的作用,即使文档指定它是用于录制视频 OR 您选择一个视频.

Altho the property that actually makes the change is the videoExportPreset the other one I dont know what it does, even tho the Documentation specifies it is for when you record a video OR you pick a video.

这篇关于AVPlayerItemVideoOutput copyPixelBuffer始终返回1280x720的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆