RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
232 stars 28 forks source link

IOS build file size increase #1392

Closed KeeleyYu closed 1 year ago

KeeleyYu commented 1 year ago

Describe the issue Hi, Recently we bought the Ultra edition and integrated this plugin in our app. But the issue is that we are seeing an increase of round 10 MB in our IOS build size, without the sample videos and demos.

How can we reduce the build size as this much increase in size is not feasible for us, which is the ios version of the similar issue #618 .

Your Setup (please complete the following information):

MorrisRH commented 1 year ago

The iOS framework is ~10MiB in size so would definitely account for the increase in build size.

You can try the following but we provide no guarantee that this will work and is entirely at your own risk:

Delete the Headers and Modules folders from inside AVProVideo.framework, this should get you about 3MiB back.

The rest requires using the terminal and is destructive to the plugin binary so I suggest that you make sure you keep a back up copy. It removes the armv7 (32bit) and bitcode components. You should also note that these actions are performed by the asset store as part of its app building process so wouldn't contribute to your final build size in the AppStore.

Using the terminal, change directory to the folder containing AVProVideo.framework, this should be something like Path-to-your-unity-project/Assets/AVProVideo/Runtime/Plugins/iOS and run the following commands:

mv AVProVideo.framework/AVProVideo ./
lipo -extract arm64 -output AVProVideo2 AVProVideo
xcrun bitcode_strip -r AVProVideo2 -o AVProVideo3
mv AVProVideo3 AVProVideo.framework/AVProVideo 
rm AVProVideo AVProVideo2

This will get the plugin size down to about 0.5MiB.

Chris-RH commented 1 year ago

Have you had any luck with this @KeeleyYu ?

KeeleyYu commented 1 year ago

Thanks for the quick response! We will have a try as soon as possible since after dealing with some other bugs in our app :)

KeeleyYu commented 1 year ago

The iOS framework is ~10MiB in size so would definitely account for the increase in build size.

You can try the following but we provide no guarantee that this will work and is entirely at your own risk:

Delete the Headers and Modules folders from inside AVProVideo.framework, this should get you about 3MiB back.

The rest requires using the terminal and is destructive to the plugin binary so I suggest that you make sure you keep a back up copy. It removes the armv7 (32bit) and bitcode components. You should also note that these actions are performed by the asset store as part of its app building process so wouldn't contribute to your final build size in the AppStore.

Using the terminal, change directory to the folder containing AVProVideo.framework, this should be something like Path-to-your-unity-project/Assets/AVProVideo/Runtime/Plugins/iOS and run the following commands:

mv AVProVideo.framework/AVProVideo ./
lipo -extract arm64 -output AVProVideo2 AVProVideo
xcrun bitcode_strip -r AVProVideo2 -o AVProVideo3
mv AVProVideo3 AVProVideo.framework/AVProVideo 
rm AVProVideo AVProVideo2

This will get the plugin size down to about 0.5MiB.

After I followed these steps, the total size of the actual IOS library file was reduced from 9.3MB to about 500KB+, but the total size of the app generated by compiling was only reduced by about 0.4M, which is a bit different from the expected 3.5MB. Is it possible? What is the reason?

KeeleyYu commented 1 year ago

Besides, is there a possibility that this optimization will cause the video to be incompatible on some low-end equipments? Such as Iphone 4, 4s and so on.

MorrisRH commented 1 year ago

Are you taking the size of the built ipa file? ima files are compressed so would not show a linear relationship with the size of the app source.

We've never supported low-end devices with AVPro Video 2 as we require a 64bit cpu and a gpu that supports Metal, this makes the iPhone 5s the lowest iPhone capable of running AVPro Video 2.

KeeleyYu commented 1 year ago

Yes, we are mainly concerned with the size of the ipa file and want it to be as small as possible. The reason we use avpro is that we encountered a lot of inexplicable problems when using videoplayer, so we wanted to find a lightweight replacement component. Moreover, we don't need some extra functions so far even though they are useful, such as live broadcast support, VR, 360, and even Image resources such as progress bars, volume keys, etc. All we want is the basic video playback functionality indeed. Thus, we are eager to see if there are still such resources that can be discarded in our app :)

KeeleyYu commented 1 year ago

It's okay to support iphone5s though for now :)

MorrisRH commented 1 year ago

Yes, we are mainly concerned with the size of the ipa file and want it to be as small as possible. The reason we use avpro is that we encountered a lot of inexplicable problems when using videoplayer, so we wanted to find a lightweight replacement component. Moreover, we don't need some extra functions so far even though they are useful, such as live broadcast support, VR, 360, and even Image resources such as progress bars, volume keys, etc. All we want is the basic video playback functionality indeed. Thus, we are eager to see if there are still such resources that can be discarded in our app :)

If you're targeting iOS versions before 12.2 then there is not much more that can be done as you already strip out the demo scenes and the streaming assets. iOS versions from 12.2 onwards do not require the swift runtime to be embedded in the built app, if you set Target minimum iOS version to 12.2 in the iOS player settings that should reduce your build size.

KeeleyYu commented 1 year ago

Ok. Thanks for your reply.