NextLevel / NextLevelSessionExporter

🔄 Export and transcode media in Swift
http://nextlevel.engineering
MIT License
262 stars 49 forks source link

Preserve original orientation #16

Closed otymartin closed 5 years ago

otymartin commented 5 years ago

Hey @piemonte

Im curious if this library preserves the original orientation of the video the it was captured. Im experience a problem with my own export method were videos captured on the native iOS camera app in portrait mode are exported in landscape. Does this lib prevent that?

piemonte commented 5 years ago

hey @otymartin ✌️

you manually provide a specific output configuration, so there isn't any detection for automatic re-orientation. maybe if you could detect the dimensions and dynamically adjust?

otymartin commented 5 years ago

@piemonte I dug further and it was my own method messing me up. In either case, I do love this library so I implemented it. Nice abstraction over AVFoundation's NextLevel complexity 👍

rromanchuk commented 5 years ago

hey @piemonte this is a beautiful library. I have a somewhat similar question and you might be able to give me some guidance before i start mucking around.

I initially ended up here because my ABR vod solution didn't support the rotation flag, so my portrait videos (really landscape with rotation 90 in the exif) were being transcoded landscape. AVMutableComposition started getting nasty fast, especially with multiple tracks and just way too fragile.

Recently my solution provider started supporting autoration by honoring this metadata, so i was wondering if I might offload some cpu cycles from the client and back to the server with apple's native orientation. I remember how much faster it was from recording to uploading, and basically my question is, am I conflating what the expensive operation was? For all i know, i was sending insanely large files, where now i am indeed encoding AVCaptureSessionPresetHigh with both hevc/264 + specific encoding and bitrates that make a lot more sense.

Do you know if i would get any gains if I gave landscape dimensions, which would be a target size closer to naturalSize, i'm assuming you're feeding it CGAffineTransforms like i was before. Am i just being delusional? I just don't have any idea if it's the encoding that makes the operation expensive or the AVMutableVideoCompositionInstructions that put pressure on AVAssetWriter. Let me know if you have any obvious insights before I go down a dumb rabbit hole with instruments. 😆

TLDR: I'm trying to speed up my exports, and curious to know what instructions/operations are the most expensive.

piemonte commented 5 years ago

hey @rromanchuk ironically i'm not using this library in a current project but will within the next month or so. i did make a couple updates such that it adopts the swift 5 result type.

in terms of the problem your addressing, i recommend avoiding CPU operations and using function calls on the gpu (instead of the uploading option you have). now do these AVFoundation calls use accelerate or the GPU instead of the CPU, would have to check, i don't know offhand. so essentially, i'm no help. 😝