Disclaimer: I'm not on the spectrum. I'm about as average as one can be, and I don't know if any of the advice below is even feasible for you, if you're capable of doing what I'm going to say.
I've worked with several people on the autism spectrum over the years. These people did have meltdowns, although they were different from what you describe. Jane had the habit of locking herself in the toilet and pulling out her hair (trying to talk to her made it worse), Alice was prone to fits of shouting, swearing and throwing stuff (mainly buckets of dirty water) when things weren't going her way/she got overstimulated. Neither of them was very able to distinguish sarcasm, irony, or to recognize a joke, even when they were having a good day. A third co-worker at the same workplace sometimes just disappeared when there were too many people in the shop. I'm assuming they had some kind of meltdown too, just not in sight of others.
Joe is high-functioning and not as prone to meltdowns, but when he has them, it usually results in shouting a lot, being incapable of being reasoned with and being very, very literal. If you told him a sentence, he'd only pick up what met their way of thinking at that moment, he'd just not hear words/nuances and completely misinterpret what was said, in a way that it fit a stance of: 'I'm angry about this now, and you've just confirmed I should be'.
What I'm going to suggest here, is coming from how these co-workers explained their meltdowns to me, how they handled the fall-out of their meltdowns. I know no two people with autism are the same, their meltdowns might have been far milder or worse than yours, my personal preferences might not work for other people and there may even be a cultural difference because I was raised with a 'they can't help themselves, so you deal with it instead' attitude. Still, I hope this might help.
First off, friends. I don't know what your standards are for calling people friends, but to me, it usually implies that this is a person I can trust, that I would not be afraid of sharing information with, it implies already having a relationship in which self-disclosure is common. If you have any friends that don't know about your autism and meltdowns, I'd find a way to tell them sooner rather than later and let them know. Prepare them for what might happen, and offer a solution/tell them what they can do when a meltdown happens.
For example, I became friends with Jane before I knew she was on the spectrum and I saw her having a meltdown for the first time. After a while, Jane first just told me she had autism, later added that she sometimes had meltdowns where she locked herself in the toilet and told me to never try and talk to her while she was in there, she locked herself up mainly to have a quiet place where there were fewer stimuli (light, sounds). She couldn't really offer any solution, except for me to give it time and wait it out, and I could be quiet when walking past the toilet. I've 'seen' Jane have a few meltdowns, I've cleaned up the hairs after her a few times. In each case, it was sufficient for her to say something along the lines of 'I'm sorry, I'm okay now, let's get back to work/partying'.
Because I knew what might happen and was able to easily recognize the meltdown when she had it, there has never really been any fall-out or ruining of our friendship because of a meltdown. We're still friends, and because I know her and her meltdowns, I also know they will pass and that she'll be a nice person to interact with once she's back to normal.
Hopefully, by educating people beforehand of what might happen, you'll have a lot less explaining to do afterwards. If you're dealing with friends, explaining about your autism and meltdowns, especially before they have ever seen them happening, should lead to a lot less fall-out. I know the world isn't perfect, and depending on who you call your friends, you might lose them if you disclose about your autism and meltdowns, so please use your own judgment in this.
Disclosing your autism to your friends might also lead to you encountering what's called a social stigma and if you feel someone might be very prone to stigmatizing you, disclosing your autism might never be an option if you want to keep that friend. In my opinion, disclosing after a meltdown may then still be worse than before, because now they have seen the kind of behaviour that leads them to stigmatize you in full force instead of having just a description of it.
For acquaintances and strangers this is a lot harder. These are usually the people that you know by name and see when doing the groceries every Friday, or don't even know at all. Self-disclosure in such a relationship isn't going to work. I would first of all advice you to only invest your time and effort into strangers or acquaintances you'd like to interact with more often. It can take a lot of time and energy, and it's up to you to decide if this person is worth that. Once people see you have a melt-down, even when you try to explain it afterwards, you're likely to encounter the social stigma attached to autism or disbelief:
Sometimes parents attempted to defuse the situation by explaining the nature of their child's disability to the person who made the comment. Often this was successful and the other person was mollified, and, sometimes, even apologetic. Other times, however, an explanation made no difference. source
It's very strange, being on the other side of a meltdown if you have no idea the person is having one. One moment Alice seems perfectly fine, the next I'm standing there with wet and dirty hair/clothes because she threw the bucket of water and the cleaning rag at my head, because 'I talk too much'. Or you're discussing your code with Joe when all of a sudden he explodes in a fit of rage against another co-worker because of something completely unrelated but it has been bothering him and he wants it out of their system NOW and it started because you mentioned the word 'test'.
If you don't know people have autism, and they suddenly have meltdowns, prepare to be shocked. Especially when their meltdowns are so very different from the meltdowns you're 'used to' (in this case, quietly locking yourself up in a toilet, trying to avoid light/sounds) that you don't even initially recognize them as such.
If you decide you want to put in the time and effort to manage the fall-out and keep the social relationship intact, your best bet is to apologize, explain, and show you're not always like what they just experienced. My co-workers (both were what I would call acquaintances at the time) explained their autism and meltdowns to me after having had a meltdown in front of me, and despite everything, I'm still in contact with Alice and I still love working with Joe. Their explanations included more than just a 'Sorry, can't help myself, it's autism' though.
Keep the explaining and apologizing separate.
Here is an example of using excuses in an apology: "I'm sorry that I snapped at you when you came into my office yesterday. I had a lot on my plate, and my boss demanded my project report an hour earlier than planned." In this case, you excuse your behavior because of stress, and you imply that the other person was at fault because he bothered you on a busy day. This makes you look weak. A better approach is to say, "I'm sorry I snapped at you yesterday." This is short and heartfelt, and it offers no excuses for your behavior. source
In fact, neither co-worker 'explained' their autism in their apology. The first sentences they spoke to me, after having their meltdown, was more like the second example in that quote: "I'm sorry about yesterday".
As for the explaining, this is what is very likely to make people suspicious and what can do the most harm. I've personally found that I find it a lot easier to accept the explanation, when it's offered as a 'warning' that this might happen again, than as an 'excuse' for what has already happened. So, only explain after the apology (this doesn't even need to be during the same conversation), and explain in terms of what might happen, like I described Jane doing above in the section on dealing with friends. Phrase it as a 'warning' for the future, explain what people can expect and how they can recognize a meltdown, and if there's anything they can do that's helpful (even if that means not doing certain things) tell them that too.
Acts speak louder than words. Joe and Alice apologized, then left it at that for a while. A big part of apologizing is showing you have moved on. They didn't bring up their meltdown at every corner, instead, they apologized and we all went on with our lives. That's why I mentioned not doing the explaining in the same conversation as the apologizing above as well: An explanation to me works a lot better if I have already seen behaviour that confirms this is an incident, not regular behaviour. Of course, that doesn't work if you're having meltdowns often, but the people I met didn't have them that often, so they could risk not directly explaining and sounding like they're making excuses.
Another method that might work for you when dealing with strangers and acquaintances, is having another person that knows you well do the explaining. When I went to Paris on a school trip, I was put in a guest family with a girl from another class/year, that was basically a stranger to me. She had some kind of disability (I forgot which one), and was showing some pretty erratic (to me) behaviour: I had to do all the translating because she somehow had some mental block preventing her from speaking French to our hosts (which I at some point just started to refuse), and meticulously keeping a travel diary to the point where she'd wake up at night, turn on all the lights and had to write down that she'd also had a croissant for lunch because she forgot to mention it.
I later had a teacher explaining her disability to me (on her request) when I snapped and told her that turning on the lights at 3 a.m. was stupid, that writing down that you ate a croissant could wait till morning, she should go back to sleep, and I turned off the lights again.
Having a teacher, someone that knows you and the other person well, explain to you that someone has a serious reason for behaving the way they do works well, because then you have a (hopefully) impartial looking party doing the explaining, which will take away some of the 'that's just excuses for shitty behavior' attitude.
Make sure your chosen narrator knows what they're doing though: They should be able to explain in pretty impartial terms and not sound like they're making excuses for you or defending your behavior. Instead, they should be capable of conveying a sense of mutual respect and impartiality when explaining, recognizing the fallout and hurt of the other party as well as represent your difficulties and being capable of explaining them to the extent that the other person knows what they can do next.