简体   繁体   中英

Rotate MTLTexture

I'm using Metal to display camera frames. I convert the outputted sample buffers into id<MTLTexture> s using CVMetalTextureCacheCreateTextureFromImage , and that works great... except that the frames come rotated 90 degrees clockwise.

How can I rotate the id<MTLTexture> 90 degrees counter clockwise?

I considered doing this when I display the texture (in the MTKView ), but then it will still be rotated the wrong way when I record the video.

You have at least a couple of different options here.

The easiest is probably requesting "physically" rotated frames from AVFoundation. Assuming you're using an AVCaptureConnection , you can use the setVideoOrientation API (when available) to specify that you want frames to be rotated before they're delivered. Then, displaying and recording can be handled in a uniform way with no further work on your part.

Alternatively, you could apply a rotation transform both when drawing the frame into the Metal view and when recording a movie. It sounds like you already know how to do the former. The latter just amounts to setting the transform property on your AVAssetWriterInput , assuming that's what you're using. Similar APIs exist on lower-level AVFoundation classes such as AVMutableComposition .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM