Data Persistence of AVAssets

Hey,

I am fairly new to working with AVFoundation etc. As far as I could research on my own, if I want to get metadata from let's say a .m4a audio file, I have to get the data and then create an AVAsset. My files are all on local servers and therefore I would not be able to just pass in the URL. The extraction of the metadata works fine - however those AVAssets create a huge overhead in storage consumption. To my knowledge the data instances of each audio file and AVAsset should only live inside the function I call to extract the metadata, however those data/AVAsset instances still live on on storage as I can clearly see that the app's file size increases by multiple Gigabytes (equal to the library size I test with). However, the only data that I purposefully save with SwiftData is the album artwork. Is this normal behavior for AVAssets or am I missing some detail?

PS. If I forgot to mention something important, please ask. This is my first ever post, so I'm not too sure what is worth mentioning.

Thank you in advance! Denis

Hi @denisdawid , well AVFoundation is a great framework used for audio modeling, but as all Apple frameworks, is not so simple. AVAsset generally are container for single AVAssetTrack, each of this could be a different media type, for example audio, video, video/audio subtitles, and so on.

But, if I remember correctly, this objects abstraction are not correlated to media data they represent (that is, load in memory) until you execute an asynchronous data load. Note that from iOS 16 syntax callbacks are more younger, look at this link https://developer.apple.com/documentation/avfoundation/media_assets/loading_media_data_asynchronously Then, what you should try to manage, is this asynchronous loading of media that could optimise the media operations. Use the correct keys should avoid data not necessarily used for your app.

Bye Rob

Data Persistence of AVAssets
 
 
Q