Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

asset bundles for audio is way bigger for WebGL

Discussion in 'WebGL' started by andrew_pearce_, Aug 17, 2021.

  1. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    164
    Hello,

    I created asset bundles (using Asset Bundle Browser) for WebGL and 20mb audios became 70mb asset bundles. When I did the same for Android and iOS the assets were less, 13mb. Did I miss some important config in the project's settings? Can I at least have audio same size as original?

    Also, I am getting error when I am trying to play audio loaded from WebGL asset bundle in Editor but Android/iOS assets bundles were working fine. Is this a limitation for WebGL asset bundles and is there any workaround so I can keep testing app in editor? (since building WebGL project takes 7 min)

    Thank you
     
  2. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    164
    I found the answer: Unity WebGL does not support client side MP3 decoding, so they have to convert audio to wav, which causes the bundles to get bigger. At first I thought to use a native HTML5 via JS plugin but later membered that Chrome/Firefox does not support MP3 playback =(

    So the question about playing audio in Editor to debug app remains open.

    p.s. Why Unity is not allowing us to use OGG for some audios? That will be at least 3 times smaller asset bundles.
     
  3. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    386
    FYI, 2021.2 has
    > WebGL: Compressed audio support for WebGL.
     
  4. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    164
    Thanks for your reply. It took me some time to find time to install 2021. So here is the result:

    1) The bundle is the same as before for both MP3 and OGG files (so audio is still converted)

    2) I am still getting the same error in Editor: Cannot create FMOD::Sound instance for clip "ding" (FMOD error: Unsupported file or audio format.)

    However, what I noticed is that 2021 is working faster. There is no that lags when you open Asset Bundle Browser.

    Also, I noticed that compression does not make any sense, the bundle is the same size =)
     
  5. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    386
    Good to know as I haven't tried it per se but my advice is to report your findings in the 2021.2 beta forum + attach a bug report case. I am certain you'll get more answers from devs there.
     
  6. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    164
    @KamilDA I believe it will be a wasting of time (it's not high demanded feature). I personally found building WebGL build for 7 minutes pretty annoying. So, it should be easier to make PostProcessBuild script which will copy Android's bundles to StreamingAssets folder (which works in Editor) when I click Play button in Editor and WebGL budnles when I click build button. I know how to handle build but I am not sure how to play in Editor. Perhaps it's the same code which needs just a platfrom dependent compilation.
     
  7. vinodlobo

    vinodlobo

    Joined:
    Dec 3, 2019
    Posts:
    10
    Hi Andrew,
    We have found that at the same quality setting, WebGL asset bundles are about 60% bigger at the same quality setting as the iOS and Android asset bundles in terms of audio size, in 2020.3. So audio compressing much better for iOS and Android. We've had to lower quality to 1 for many audio files, which did not affect quality much but reduced files sizes significantly. The whole process of setting a vague quality rather than an exact bitrate seems strange, we've had to live with it.

    As you mentioned, Unity is expanding and recompressing audio, so we realized no benefit to compressing the source files: may as well use originals or lightly compressed. Easy for files to get BIGGER than source like you saw, if Quality 1 is higher bitrate than your source.
     
    andrew_pearce_ likes this.
  8. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    164
    That's interesting. Could you please tell us, where did you change that? We usually change the quality of the source audio but if there is an option to set audio quality within Unity, that should help a lot! Thank you in advance!