Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory consumption too high while applying asset transform on sourceImage #370

Open
VarinderSH opened this issue Aug 27, 2023 · 0 comments

Comments

@VarinderSH
Copy link

VarinderSH commented Aug 27, 2023

First of all Thanks to the MetalPetal team, I have build an application using this awesome library.
but while testing the application I have found one memory crash which related to asset transform.

I am using MTIVideoComposition to get every frame of the video to process
in this block I am applying multiple filters on the video.
the composition I am using has max 20 video tracks
While testing I found that whenever I am applying transform on the source image as per the video the memory is getting too hight and at the end memory crash is occurring.

I have found this method to apply transform on the source image

extension MTIImage { public func applyingAssetTrackTransform(_ transform: CGAffineTransform) -> MTIImage { let transformFilter = MTITransformFilter() transformFilter.inputImage = self var transform = transform transform.tx = 0 transform.ty = 0 transformFilter.transform = CATransform3DMakeAffineTransform(transform.inverted()) transformFilter.viewport = transformFilter.minimumEnclosingViewport return transformFilter.outputImage! } }

this is the code I am using to render every frame of the video and applying transform
let videoComposition = MTIVideoComposition(asset: composition,
context: renderContext,
queue: DispatchQueue.main, filter: { [weak self] request in
guard let self else { return MTIImage.black }

         var sourceImage = request.anySourceImage.applyingAssetTrackTransform(transform) ?? .black
        return sourceImage

})

Kindly help me to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant